Containerfile: add cargo-chef for dependency-layer caching in podman build #3

Open
opened 2026-08-19 06:38:50 +00:00 by gal-bot · 2 comments
Owner

The two-stage Containerfile copies Cargo.toml + src/ together then runs cargo build --release — every source change invalidates the build layer → full dependency recompile every deploy.

Fix: adopt the cargo-chef planner/cache/cooker pattern:

  1. planner stage: cargo chef prepare --recipe-path recipe.json from Cargo.toml/Cargo.lock
  2. cache stage: cargo chef cook --release --recipe-path recipe.json — dep compilation, cached as a layer
  3. builder stage: copy recipe + sources, cargo build --release — only recompiles app code unless deps change

Effect: dep changes only recompile when Cargo.toml/Cargo.lock actually change; day-to-day source-only pushes reuse the cached dep layer (seconds vs minutes).

This is app-level (this Containerfile) but the archetype comes from the ditc scaffold — the template should adopt cargo-chef too so new apps inherit it (cross-reference: dit-client template ticket).

The two-stage Containerfile copies `Cargo.toml` + `src/` together then runs `cargo build --release` — every source change invalidates the build layer → full dependency recompile every deploy. Fix: adopt the [cargo-chef](https://github.com/lukemartinwalker/cargo-chef) planner/cache/cooker pattern: 1. `planner` stage: `cargo chef prepare --recipe-path recipe.json` from Cargo.toml/Cargo.lock 2. `cache` stage: `cargo chef cook --release --recipe-path recipe.json` — dep compilation, cached as a layer 3. `builder` stage: copy recipe + sources, `cargo build --release` — only recompiles app code unless deps change Effect: dep changes only recompile when Cargo.toml/Cargo.lock actually change; day-to-day source-only pushes reuse the cached dep layer (seconds vs minutes). This is app-level (this Containerfile) but the archetype comes from the ditc scaffold — the template should adopt cargo-chef too so new apps inherit it (cross-reference: dit-client template ticket).
Owner

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.
Owner

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gal/constructionbot#3
No description provided.