-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.gateway-agent
More file actions
64 lines (54 loc) · 3.26 KB
/
Dockerfile.gateway-agent
File metadata and controls
64 lines (54 loc) · 3.26 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
# syntax=docker/dockerfile:1
# ─────────────────────────────────────────────────────────────────────────────
# Dockerfile.gateway-agent — multi-arch build (linux/amd64 + linux/arm64)
#
# Build a single arch:
# docker build --platform linux/amd64 -f Dockerfile.gateway-agent -t pamtunnel/gateway-agent:latest .
# docker build --platform linux/arm64 -f Dockerfile.gateway-agent -t pamtunnel/gateway-agent:latest .
#
# Build + push multi-arch manifest (requires `docker buildx`):
# docker buildx build --platform linux/amd64,linux/arm64 \
# -f Dockerfile.gateway-agent -t pamtunnel/gateway-agent:latest --push .
# ─────────────────────────────────────────────────────────────────────────────
FROM --platform=$BUILDPLATFORM rust:1-slim-bookworm AS builder
ARG TARGETARCH
RUN apt-get update && apt-get install -y --no-install-recommends \
python3-pip xz-utils \
&& pip3 install ziglang --break-system-packages \
&& cargo install cargo-zigbuild \
&& rustup target add \
x86_64-unknown-linux-musl \
aarch64-unknown-linux-musl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
# ── Dependency-caching layer ──────────────────────────────────────────────────
COPY Cargo.toml Cargo.lock ./
COPY shared/Cargo.toml shared/Cargo.toml
COPY vps-agent/Cargo.toml vps-agent/Cargo.toml
COPY gateway-agent/Cargo.toml gateway-agent/Cargo.toml
RUN mkdir -p shared/src vps-agent/src gateway-agent/src \
&& echo 'pub struct _Stub;' > shared/src/lib.rs \
&& echo 'fn main() {}' > vps-agent/src/main.rs \
&& echo 'fn main() {}' > gateway-agent/src/main.rs
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target \
case "$TARGETARCH" in \
amd64) TARGET=x86_64-unknown-linux-musl ;; \
arm64) TARGET=aarch64-unknown-linux-musl ;; \
*) echo "Unsupported TARGETARCH: $TARGETARCH" >&2 && exit 1 ;; \
esac \
&& cargo zigbuild --release --target "$TARGET" -p gateway-agent
# ── Real build ────────────────────────────────────────────────────────────────
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target \
case "$TARGETARCH" in \
amd64) TARGET=x86_64-unknown-linux-musl ;; \
arm64) TARGET=aarch64-unknown-linux-musl ;; \
esac \
&& cargo zigbuild --release --target "$TARGET" -p gateway-agent \
&& cp "target/$TARGET/release/gateway-agent" /gateway-agent
# ── Minimal runtime image ─────────────────────────────────────────────────────
FROM scratch
COPY --from=builder /gateway-agent /gateway-agent
ENTRYPOINT ["/gateway-agent"]