2026-04-07 22:12:37 +02:00
|
|
|
# Build stage
|
2026-04-09 11:51:57 +02:00
|
|
|
FROM rust:alpine AS builder
|
2026-04-07 22:12:37 +02:00
|
|
|
|
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
|
2026-04-09 11:51:57 +02:00
|
|
|
# Install build dependencies and musl target
|
|
|
|
|
RUN apk add --no-cache musl-dev pkgconfig openssl-dev && \
|
|
|
|
|
rustup target add x86_64-unknown-linux-musl
|
2026-04-07 22:12:37 +02:00
|
|
|
|
|
|
|
|
# Copy manifests
|
2026-04-09 11:51:57 +02:00
|
|
|
COPY Cargo.toml Cargo.lock ./
|
2026-04-07 22:12:37 +02:00
|
|
|
COPY crates ./crates
|
|
|
|
|
COPY apps ./apps
|
|
|
|
|
|
2026-04-09 11:51:57 +02:00
|
|
|
# Build static binary with musl target
|
|
|
|
|
ENV RUSTFLAGS='-C target-feature=+crt-static'
|
|
|
|
|
RUN cargo build --release --bin ${BIN_NAME} --target x86_64-unknown-linux-musl
|
2026-04-07 22:12:37 +02:00
|
|
|
|
2026-04-09 11:51:57 +02:00
|
|
|
# Runtime stage - minimal Alpine
|
|
|
|
|
FROM alpine:latest AS runtime
|
2026-04-07 22:12:37 +02:00
|
|
|
|
2026-04-09 11:51:57 +02:00
|
|
|
# Install CA certificates only
|
|
|
|
|
RUN apk add --no-cache ca-certificates
|
2026-04-07 22:12:37 +02:00
|
|
|
|
|
|
|
|
# Create app user
|
2026-04-09 11:51:57 +02:00
|
|
|
RUN adduser -D -u 1000 appuser
|
2026-04-07 22:12:37 +02:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
2026-04-09 11:51:57 +02:00
|
|
|
# Copy static binary from builder
|
|
|
|
|
COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/${BIN_NAME} ./${BIN_NAME}
|
2026-04-07 22:12:37 +02:00
|
|
|
|
|
|
|
|
# Switch to non-root user
|
|
|
|
|
USER appuser
|
|
|
|
|
|
|
|
|
|
# Run the binary
|
|
|
|
|
CMD ["./${BIN_NAME}"]
|