···11+FROM rust:1 AS chef
22+# We only pay the installation cost once,
33+# it will be cached from the second build onwards
44+RUN cargo install cargo-chef
55+WORKDIR /workspace
66+77+88+FROM chef AS planner
99+COPY crates .
1010+RUN cargo chef prepare --recipe-path recipe.json
1111+1212+FROM chef AS builder
1313+ARG CRATE_NAME
1414+COPY --from=planner /workspace/recipe.json recipe.json
1515+# Build dependencies - this is the caching Docker layer!
1616+RUN cargo chef cook --release --recipe-path recipe.json
1717+# Build application
1818+COPY crates .
1919+RUN cargo build --release --bin ${CRATE_NAME}
2020+2121+# We do not need the Rust toolchain to run the binary!
2222+FROM debian:bookworm-slim AS runtime
2323+ARG CRATE_NAME
2424+WORKDIR /workspace
2525+COPY --from=builder /workspace/target/release/${CRATE_NAME} /usr/local/bin/app
2626+ENTRYPOINT ["/usr/local/bin/app"]