talira

cargo-chef

Cache the dependencies of your Rust project and speed up your Docker builds.

open sourceApache-2.0self-hostablefree

cargo-chef is a Cargo subcommand that makes Docker layer caching work for Rust. cargo chef prepare computes a recipe of the project's dependency skeleton, and cargo chef cook builds only the dependencies in an earlier Docker layer, so source changes don't invalidate the dependency build. It was written for the deployment chapter of Zero to Production in Rust and is not meant to be run on a local checkout.

Ways to install

Package managers

Problems it solves

  • every code change makes my Rust Dockerfile rebuild all dependencies
  • docker build for a Rust service takes 15 minutes even for a one-line change
  • cache Rust crates in a Docker layer the way npm install gets cached
  • COPY . . invalidates the cargo build layer every time
  • speed up building Rust container images in CI
  • multi-stage Dockerfile for Rust that doesn't recompile the world
  • separate dependency compilation from application compilation in a container build
  • my deploy pipeline spends most of its time compiling crates that never change

Features

  • prepare: dependency recipe
  • cook: build dependencies only
  • works with multi-stage Dockerfiles

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what cargo-chef does.

  1. sccache Shared compilation cache for C, C++, Rust and CUDA, stored locally or in the cloud
  2. BuildKit concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
  3. Depot Software delivery built for machine scale
  4. WarpBuild High-performance GitHub Actions runners: 2x faster, 50% cheaper

Compare cargo-chef with the top 3