Skip to content

perf(ci): cache Rust deps in release builds (cargo-chef + rust-cache)#166

Merged
kitplummer merged 1 commit into
mainfrom
perf/ci-rust-cache
Jun 18, 2026
Merged

perf(ci): cache Rust deps in release builds (cargo-chef + rust-cache)#166
kitplummer merged 1 commit into
mainfrom
perf/ci-rust-cache

Conversation

@kitplummer

Copy link
Copy Markdown
Collaborator

Speeds up builds/releases by caching Rust dependency compilation, per architecture.

The bottleneck

The multi-arch image build recompiled the entire dependency tree from scratch every release: the Dockerfile built everything in one cargo build --release --workspace layer, so any source change cache-missed it. The per-arch buildx GHA cache (already configured) only kept the apt/toolchain layers — useless for the cargo compile.

Changes

  • Dockerfile → cargo-chef. cook compiles only dependencies into a layer keyed on Cargo.lock; the existing per-architecture buildx GHA cache (scope=peat-node-<arch>) now actually reuses it across releases. A wrinkle: cargo-chef stubs workspace build scripts during cook, which broke our build.rs proto codegen (include!(OUT_DIR/_connectrpc.rs) not found). Fixed by re-copying build.rs + proto/ and cargo clean -p peat-node after cook so the codegen re-runs — deps stay cooked.
  • release.yml — added Swatinem/rust-cache to the 4 peat-cli binary jobs (they were uncached), keyed per matrix target.

Verified locally

  • Full build succeeds; image works (peat-node derive-id returns the correct id).
  • Real source change → ~14s rebuild, cook (deps) layer CACHED, only peat-node + peat-cli recompiled — no deps (tokio/iroh/peat-mesh) rebuilt.

CI host jobs (Test/Clippy/Build/Cross-platform) already use rust-cache; this closes the two remaining gaps (Docker dep layer + peat-cli release binaries). No product/behavior change — build tooling only.

The slow part of a release was the multi-arch image build recompiling the full
dependency tree from scratch every time: the Dockerfile built everything in one
`cargo build --release --workspace` layer, so any source change cache-missed it,
and the per-arch buildx GHA cache only kept the apt/toolchain layers.

- Dockerfile: adopt cargo-chef. `cook` compiles only dependencies into a layer
  keyed on Cargo.lock, which the existing per-architecture buildx GHA cache now
  actually reuses across releases. Re-copy build.rs + proto and `cargo clean -p
  peat-node` after cook so our proto-codegen build script regenerates
  OUT_DIR/_connectrpc.rs (cargo-chef stubs workspace build scripts during cook).
  Verified locally: a real source change rebuilds in ~14s recompiling only
  peat-node + peat-cli — deps stay cooked/cached (vs a full from-scratch build).
- release.yml: add Swatinem/rust-cache to the peat-cli binary jobs (4 host
  targets were uncached), keyed per matrix target.

CI host jobs already use rust-cache; the multi-arch Docker build already had the
per-arch buildx GHA cache — it just wasn't effective without cargo-chef.

@peat-bot peat-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peat QA Review (SHA: 63683ad)

No findings.

Scope: build tooling only — Dockerfile adopts the cargo-chef planner/cook/build pattern keyed on Cargo.lock, and .github/workflows/release.yml adds Swatinem/rust-cache to the 4 peat-cli release binary jobs keyed per matrix target. No changes to proto/sidecar.proto, the Connect RPC surface, src/crypto.rs, src/watcher.rs, Cargo.toml dependency pins, chart/peat-node/, or zarf.yaml. The cargo clean -p peat-node --release step after cook is the documented workaround to force build.rs proto codegen to re-run while leaving cooked dependency artifacts intact, and the ADR-001 in-container peat --help smoke test is preserved.

@kitplummer kitplummer merged commit 250314e into main Jun 18, 2026
13 checks passed
@kitplummer kitplummer deleted the perf/ci-rust-cache branch June 20, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants