feat: add Docker volume cache mounting for reproducible builds#385
feat: add Docker volume cache mounting for reproducible builds#385
Conversation
…ache Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds optional Docker volume cache mounting to speed up sequential reproducible builds in workspaces and CI/CD environments by reusing compiled dependencies and downloaded crates across container invocations.
Changes:
- Added
--mount-target-cacheand--mount-cargo-cacheCLI flags with defaultfalsefor backward compatibility - Extended Docker volume mounting logic to map local
./targetand~/.cargodirectories into containers - Added README documentation explaining cache flags and reproducibility trade-offs
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cargo-near/src/commands/build/actions/reproducible_wasm/mod.rs | Added mount_target_cache and mount_cargo_cache boolean fields to BuildOpts and propagated them through conversion functions |
| cargo-near-build/src/types/near/docker_build/mod.rs | Added mount_target_cache and mount_cargo_cache fields to DockerBuildOpts struct |
| cargo-near-build/src/near/docker_build/mod.rs | Implemented additional_docker_args function to construct volume mounts and environment variables when cache flags are enabled |
| README.md | Added "Caching for faster builds" section documenting the new flags and reproducibility caveats |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let cargo_home = std::env::var("CARGO_HOME") | ||
| .or_else(|_| { | ||
| std::env::var("HOME") | ||
| .or_else(|_| std::env::var("USERPROFILE")) | ||
| .map(|home| format!("{}/.cargo", home)) | ||
| }) | ||
| .map_err(|_| eyre::eyre!("Failed to determine CARGO_HOME or ~/.cargo directory"))?; | ||
|
|
||
| let cargo_home_str = dunce::canonicalize(&cargo_home) | ||
| .map_err(|e| eyre::eyre!("Failed to canonicalize cargo home {:?}: {}", cargo_home, e))? | ||
| .to_string_lossy() | ||
| .to_string(); |
There was a problem hiding this comment.
The cargo home directory is not created before calling dunce::canonicalize, unlike the target directory (lines 141-143). If the directory doesn't exist (e.g., on a fresh system), canonicalize will fail. Add std::fs::create_dir_all(&cargo_home) before the canonicalize call, similar to the target directory handling.
Adds opt-in cache mounting to speed up sequential reproducible builds in workspaces and CI/CD by reusing compiled dependencies and downloaded crates across Docker container invocations.
Changes
CLI flags: Added
--mount-target-cacheand--mount-cargo-cachetocargo near build reproducible-wasmfalsefor backward compatibilitycargo near deploy reproducible-wasmvia flag flatteningVolume mounting: Extended
additional_docker_args()to construct volume mounts when flags are enabled./target→/target_cachewithCARGO_TARGET_DIR=/target_cache~/.cargo→/usr/local/cargo(standard CARGO_HOME in Rust images)Documentation: Added README section explaining cache flags and reproducibility trade-offs
Usage
Cache reuse pattern:
EC → 1EC, EC → 2EC, EC → 3ECwhere EC is external cache, enabling significant build time reduction when building multiple contracts or rebuilding the same contract.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
docs.rs/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)s3-us-west-1.amazonaws.com/home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build /home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build -static -I 64-REDACTED-linux-gnu/bin/rust-lld -I ./vendor/dbus/ -Wall -Wextra -UDBUS_DISABLE_CHECKS -UWORDS_BIGENDIAN -UHAVE_GETPEERUCRED -UHAVE_CMSGCRED --64�� /rust/working/target/debug/build--gdwarf-4 22-dbus-file-unix.o(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
build reproducible-wasmwith cargo-near #308💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.