A cargo subcommand that speeds up Rust Docker builds by caching dependencies using Docker layer caching.
cargo-chef is a cargo subcommand that optimizes Rust Docker builds by leveraging Docker's layer caching. It analyzes a Rust project to create a recipe of minimal required files, allowing dependencies to be built and cached separately from application code, which significantly reduces build times.
Rust developers building containerized applications with Docker, particularly those working on backend services or projects where fast, incremental Docker builds are critical.
Developers choose cargo-chef over manual Dockerfile tweaks because it automatically handles workspace changes, adapts to project reorganizations, and provides robust dependency caching without fragile workarounds, ensuring maintainable and fast builds as projects evolve.
A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically detects and manages all crates in a Cargo workspace, adapting seamlessly when new crates are added or files are moved without requiring Dockerfile edits.
Builds dependencies into a separate Docker layer using a recipe.json file, preventing rebuilds when only app code changes and speeding up builds by up to 5x in some cases.
Works with different Rust toolchains and targets, including x86_64-unknown-linux-musl for creating static binaries compatible with Alpine Linux distributions.
Offers ready-to-use Docker images with integrated Rust and cargo-chef, simplifying setup and ensuring version compatibility across build stages.
cargo chef cook and cargo build must run from the same directory; otherwise, dependency caching fails because cargo's *.d files contain absolute paths, breaking portability.
The README acknowledges that testing hasn't covered all cargo build customizations, so complex project setups might encounter unforeseen issues or rough edges.
Local dependencies outside the project are always rebuilt from scratch due to cargo's timestamp-based fingerprinting, as noted in a long-standing cargo issue, reducing cache benefits for such cases.