-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
32 lines (28 loc) · 1.28 KB
/
Dockerfile
File metadata and controls
32 lines (28 loc) · 1.28 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
ARG APP_NAME=status-list-server
# Use buildx's automatic platform detection
FROM --platform=$BUILDPLATFORM blackdex/rust-musl:x86_64-musl AS builder-amd64
FROM --platform=$BUILDPLATFORM blackdex/rust-musl:aarch64-musl AS builder-arm64
# Select the appropriate builder based on target platform
FROM builder-${TARGETARCH} AS builder
ARG APP_NAME
ARG TARGETPLATFORM
ARG TARGETARCH
WORKDIR /app
# Set the Rust target and build the application
RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target,id=target-cache-${TARGETPLATFORM} \
--mount=type=cache,target=/root/.cargo/registry,id=registry-cache-${TARGETPLATFORM} \
case "$TARGETARCH" in \
amd64) RUST_TARGET="x86_64-unknown-linux-musl" ;; \
arm64) RUST_TARGET="aarch64-unknown-linux-musl" ;; \
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
esac; \
cargo build --locked --release --target=${RUST_TARGET}; \
mv target/${RUST_TARGET}/release/${APP_NAME} .
FROM gcr.io/distroless/static-debian12 AS runtime
ARG APP_NAME
COPY --from=builder --chown=nonroot:nonroot /app/${APP_NAME} /app/${APP_NAME}
EXPOSE 8000
ENTRYPOINT ["/app/status-list-server"]