Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Crate index caching
This PR adds documentation on how to cache a local crate index when working with
workspaces that have large
git
dependencies. I devised this method after Inoticed that the
cargo chef cook
step was cloning a non-targetgit
dependency (namely,
aptos-core
)during a
cargo-chef
build, since compilation requires a complete local crateindex.
The documentation in the PR goes into detail about the mechanisms at play, and
below I'm including an example for additional illustrative purposes.
Related:
--download-only
option for multi-crate workspaces #250Example
Layout
Consider the following workspace:
The top-level
Cargo.toml
file defines two packages:The
Dockerfile
is identical to the template proposed in this PR:The
Cargo.toml
formy_package
has no special dependencies:And
my_bin.rs
declares a simple "Hello, world!" statement:However, the
Cargo.toml
foranother_package
has agit
dependency onaptos-core
(note that peraptos-core
#8984there is no plan to support package management on
crates.io
):Note that
another_bin.rs
has a modified "Hello, world!" statement, whichrelies on a random account address generated via the
move-core-types
dependency:
Cache hit dynamics
To follow along, replicate the above workspace. Then generate a lockfile:
To build and run
my-bin
viacargo-chef
:Hello, world!
Note that this downloads the entire
aptos-core
repository during the--dry-run
step, since a local crate index is required for the eventualcargo chef cook
operation:=> [indexer 2/2] RUN cargo update --dry-run
However, if
my_bin.rs
is modified to instead printHello, chef!
, since theaptos-core
git
dependencycrate index is already cached, the repository does not need to be downloaded
again when re-building the image.
To run
another-bin
:Hello, 0xa53c237d4f6fd71c6355254a36ecaa8fed0269430669131d21a27c732d66b18e!
Here, the local image cache preserves the output for the
--dry-run
crate indexgeneration step, since the
Cargo.toml
manifest skeleton is common across bothbuilds in the workspace.
Moreover, updating
another_bin.rs
to printGoodbye, ...
results in anothercache hit since there are no new dependencies.
Cache miss dynamics
The local crate index cache step can be undone by simply commenting out the
following line in the Dockerfile:
In this case, the
cargo chef cook
command has no access to a local crate indexcache, and it will need to regenerate it whenever a recipe changes. Notably,
this involves re-downloading
aptos-core
even for changes to
my_package
that have nothing to do with the dependency.