Is this a docs issue?
Type of issue
Information is incorrect
Description
Rust language-specific guide and Optimize cache usage in builds say to cache mount /usr/local/cargo/git/db and /usr/local/cargo/registry when building Rust projects. Eg.
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo build
However, I believe this breaks multi-platform builds (Eg. docker buildx build --platform linux/amd64,linux/arm64 .) because while the package cache is shared between builds, the package cache lock is not. The lock can currently be found at $CARGO_HOME/.package-cache, which is /usr/local/cargo/.package-cache inside the container.
Location
https://docs.docker.com/guides/rust/
Suggestion
Potential solutions, worst-to-best in my opinion:
- Make the cache exclusive, eg.
--mount=type=cache,sharing=locked,target=/usr/local/cargo/registry.
- Why use Docker to do something that Cargo can do by itself?
- Share the package cache lock file, eg.
--mount=type=cache,target=/usr/local/cargo/.package-cache.
- Cache the entire Cargo home directory, eg.
--mount=type=cache,target=/usr/local/cargo,from=rust:1.92,source=/usr/local/cargo.
- Doing this means we don't care about the internals of Cargo home, but we do have to specify
from=rust:1.92 (assuming you are in a FROM rust:1.92 section) so that everything already in Cargo home isn't clobbered.
See https://hackmd.io/@kobzol/S17NS71bh for a good summary of Docker caching with cargo builds.
Is this a docs issue?
Type of issue
Information is incorrect
Description
Rust language-specific guide and Optimize cache usage in builds say to cache mount
/usr/local/cargo/git/dband/usr/local/cargo/registrywhen building Rust projects. Eg.RUN --mount=type=cache,target=/usr/local/cargo/git/db \ --mount=type=cache,target=/usr/local/cargo/registry \ cargo buildHowever, I believe this breaks multi-platform builds (Eg.
docker buildx build --platform linux/amd64,linux/arm64 .) because while the package cache is shared between builds, the package cache lock is not. The lock can currently be found at$CARGO_HOME/.package-cache, which is/usr/local/cargo/.package-cacheinside the container.Location
https://docs.docker.com/guides/rust/
Suggestion
Potential solutions, worst-to-best in my opinion:
--mount=type=cache,sharing=locked,target=/usr/local/cargo/registry.--mount=type=cache,target=/usr/local/cargo/.package-cache..package-cache-mutate.--mount=type=cache,target=/usr/local/cargo,from=rust:1.92,source=/usr/local/cargo.from=rust:1.92(assuming you are in aFROM rust:1.92section) so that everything already in Cargo home isn't clobbered.See https://hackmd.io/@kobzol/S17NS71bh for a good summary of Docker caching with cargo builds.