-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.dev
More file actions
110 lines (89 loc) · 4.18 KB
/
Dockerfile.dev
File metadata and controls
110 lines (89 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Development Dockerfile for Multiway Gateway (Control Plane + Data Plane)
#
# This Dockerfile uses a lower optimization profile for faster builds.
# Use this for development and testing; use the main Dockerfile for production.
#
# Build from workspace root:
# docker build -f Dockerfile.dev --target controlplane -t multiway:dev .
# docker build -f Dockerfile.dev --target dataplane -t multiway-dataplane:dev .
ARG RUST_VERSION=1.92
# =============================================================================
# Builder Stage - Compiles BOTH binaries with shared dependencies
# =============================================================================
FROM rust:${RUST_VERSION}-alpine AS builder
ARG TARGETARCH
# Install ALL build dependencies (union of controlplane + dataplane needs)
# - musl-dev, pkgconfig: basic Rust/C compilation
# - cmake, perl, make: aws-lc-rs (controlplane TLS)
# - clang, clang-dev, linux-headers, g++: Pingora (dataplane proxy)
RUN apk add --no-cache \
musl-dev \
pkgconfig \
cmake \
perl \
make \
clang \
clang-dev \
linux-headers \
g++
# Add appropriate musl target based on architecture
RUN case "${TARGETARCH}" in \
"amd64") echo "x86_64-unknown-linux-musl" > /rust-target.txt ;; \
"arm64") echo "aarch64-unknown-linux-musl" > /rust-target.txt ;; \
*) echo "x86_64-unknown-linux-musl" > /rust-target.txt ;; \
esac && rustup target add $(cat /rust-target.txt)
WORKDIR /build
# Copy workspace Cargo files for dependency caching
COPY Cargo.toml Cargo.lock ./
COPY crates/controlplane/Cargo.toml ./crates/controlplane/
COPY crates/dataplane/Cargo.toml ./crates/dataplane/
COPY crates/gateway-crds/Cargo.toml ./crates/gateway-crds/
# Create dummy source files to cache dependencies
# Build BOTH packages in one command to share dependency compilation
# Using default dev profile (opt-level 0) for fastest builds with debug symbols
RUN mkdir -p crates/controlplane/src/bin crates/dataplane/src crates/gateway-crds/src && \
echo "fn main() {}" > crates/controlplane/src/bin/main.rs && \
echo "" > crates/controlplane/src/lib.rs && \
echo "fn main() {}" > crates/dataplane/src/main.rs && \
echo "" > crates/gateway-crds/src/lib.rs && \
cargo build --target $(cat /rust-target.txt) \
-p multiway \
-p multiway-dataplane && \
rm -rf crates
# Copy actual source code
COPY . .
# Build BOTH real binaries in one command
# Touch all source files to invalidate cache
RUN touch crates/controlplane/src/lib.rs \
crates/controlplane/src/bin/main.rs \
crates/dataplane/src/main.rs \
crates/gateway-crds/src/lib.rs && \
cargo build --target $(cat /rust-target.txt) \
-p multiway --bin multiway \
-p multiway-dataplane --bin multiway-dataplane
# Copy binaries to predictable locations
RUN cp /build/target/$(cat /rust-target.txt)/debug/multiway /multiway && \
cp /build/target/$(cat /rust-target.txt)/debug/multiway-dataplane /multiway-dataplane
# Create config directory structure for dataplane (distroless can't mkdir)
RUN mkdir -p /etc/multiway
# =============================================================================
# Control Plane Runtime Stage
# =============================================================================
FROM gcr.io/distroless/static:nonroot AS controlplane
COPY --from=builder /multiway /usr/local/bin/multiway
ENTRYPOINT ["/usr/local/bin/multiway"]
CMD ["controller", "--help"]
# =============================================================================
# Data Plane Runtime Stage
# =============================================================================
FROM gcr.io/distroless/static:nonroot AS dataplane
# Copy the binary
COPY --from=builder /multiway-dataplane /usr/local/bin/multiway-dataplane
# Copy config directory (owned by nonroot user in distroless)
COPY --from=builder --chown=nonroot:nonroot /etc/multiway /etc/multiway
# Default config path (matches binary default and control plane mount point)
ENV CONFIG_PATH=/config/config.json
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/multiway-dataplane"]
# Config path is set via CONFIG_PATH env var by the control plane
# Default in binary is /config/config.json which matches control plane mount