# Build the application from source.
FROM rust:1.77.0-slim@sha256:e785e4aa81f87bc1ee02fa2026ffbc491e0410bdaf6652cea74884373f452664 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:6dcc833df2a475be1a3d7fc951de90ac91a2cb0be237c7578b88722e48f2e56f AS runtime
LABEL maintainer "DeadNews <aurczpbgr@mozmail.com>"
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"]