Image builds compile every dependency again on any Cargo.lock change #438
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Dockerfile builds the dependencies in one layer, which any change to Cargo.toml or Cargo.lock invalidates, so all 509 crates compile again in release, holding the builder's 6 GB cap for minutes (adding crates/tui did it on 2026-11-09). Dockerfile.directory has no dependency layer at all and compiles everything on every build. BuildKit cache mounts for cargo's registry and target/ would keep compiled crates between builds, so only what changed compiles.
Fixed in
3a3900e: cargo's registry and target/ are BuildKit cache mounts in Dockerfile and Dockerfile.directory. Measured: a Cargo.toml change now compiles 3 crates in 52 s, where it compiled 405 in 170 s; the lowest MemAvailable was about the same (8.1 GB against 7.9), since the ipx crate itself is most of the peak. Both images built, pushed and checked with --version.