ARG RUST_CHEF_IMAGE=docker.io/lukemathwalker/cargo-chef:latest-rust-latest
ARG RUNTIME_FROM=gcr.io/distroless/cc-debian13
FROM $RUST_CHEF_IMAGE AS chef
WORKDIR /app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG LIBGCC_VERSION=14
ARG CARGO_BUILD_JOBS=""
RUN apt-get update && apt-get install -y ca-certificates libz-dev libgcc-${LIBGCC_VERSION}-dev libssl-dev
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --features cli --recipe-path recipe.json \
${CARGO_BUILD_JOBS:+--jobs "$CARGO_BUILD_JOBS"}
COPY . .
RUN cargo build --release --features cli --bin adnv \
${CARGO_BUILD_JOBS:+--jobs "$CARGO_BUILD_JOBS"}
FROM $RUNTIME_FROM
# libz, libssl, libcrypto, libgcc_s and libstdc++ ship in both runtime bases
# already, so copying them from the builder only pinned this image to one
# architecture through `/usr/lib/${LIB_ARCH}-${TARGETOS}-gnu/`.
# `/etc/ssl/certs` does have to come across: debian-slim has no certificates.
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /app/target/release/adnv /usr/local/bin/
CMD ["/usr/local/bin/adnv"]