# syntax=docker/dockerfile:1
# Template, reviewed November 2026; image build pending
# Replace each <digest> with the digest you pin for that tag.
FROM rust:1.100.0-slim-bookworm@sha256:<digest> AS chef
RUN cargo install cargo-chef --locked --version 0.1.78
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Dependencies only: cached until Cargo.toml or Cargo.lock change.
RUN cargo chef cook --release --locked --recipe-path recipe.json
COPY . .
RUN cargo build --release --locked --bin refservice

# glibc build, so the runtime is distroless cc. For a static musl build
# (--target x86_64-unknown-linux-musl), use gcr.io/distroless/static-debian12:nonroot
# and copy from target/x86_64-unknown-linux-musl/release/.
FROM gcr.io/distroless/cc-debian12:nonroot@sha256:<digest> AS runtime
COPY --from=builder /app/target/release/refservice /usr/local/bin/refservice
USER 65532:65532
EXPOSE 8080
ENV PORT=8080 RUST_LOG=info
ENTRYPOINT ["/usr/local/bin/refservice"]
