# Build the application from source. FROM rust:1.80.1-slim@sha256:e8e40c50bfb54c0a76218f480cc69783b908430de87b59619c1dca847fdbd753 AS rust-builder ENV CARGO_HOME="/cache/cargo" WORKDIR /app COPY Cargo.toml Cargo.lock ./ COPY src/ ./src/ # Install musl-tools to cross-compile the application for a lean image. RUN --mount=type=cache,target="/var/cache/" \ --mount=type=cache,target="/var/lib/apt/lists/" \ apt-get update && apt-get install -y --no-install-recommends musl-tools # Build the application for the musl target. RUN --mount=type=cache,target=${CARGO_HOME} \ rustup target add x86_64-unknown-linux-musl && \ cargo build --release --locked --target x86_64-unknown-linux-musl # Deploy the application binary into a lean image. FROM gcr.io/distroless/static-debian12:latest@sha256:ce46866b3a5170db3b49364900fb3168dc0833dfb46c26da5c77f22abb01d8c3 AS runtime LABEL maintainer="DeadNews " COPY --from=rust-builder /app/target/x86_64-unknown-linux-musl/release/deadnews-template-rust /usr/local/bin/deadnews-template-rust USER nonroot:nonroot EXPOSE 8080 HEALTHCHECK NONE CMD ["deadnews-template-rust"]