Skip to content

Instantly share code, notes, and snippets.

@mfirhas
Created October 9, 2023 09:41
Show Gist options
  • Save mfirhas/81d5d1aab6b4dcec3813d82b73cfb940 to your computer and use it in GitHub Desktop.
Save mfirhas/81d5d1aab6b4dcec3813d82b73cfb940 to your computer and use it in GitHub Desktop.
rust_cargo_chef.Dockerfile
### STAGE 1: install cargo chef
FROM rust AS chef
RUN cargo install cargo-chef
WORKDIR /app
### STAGE 2: create cargo chef recipe.json
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
### STAGE 3: build dependencies from recipe.json and build the app
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --bin app
### STAGE 4: run the app
# We do not need the Rust toolchain to run the binary!
FROM gcr.io/distroless/cc-debian12
COPY --from=builder /app/target/release/app app
# RUN chmod +x ./app
ENTRYPOINT [ "./app" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment