Skip to content

Commit

Permalink
fix(earthly): copy cargo-chef to image layer
Browse files Browse the repository at this point in the history
A `CACHE` serves as a persistent cache mount which remains popullated
in between layer changes. This is very helpful for speeding up CI when
there are genuine layer updates, since we can, e.g. maintain already
fetched dependencies in `CARGO_HOME`, while adding whichever new ones.

However, there has been a persistent issue with `cargo-chef`, which was
installed into our `CARGO_HOME` shared `CACHE`. Rarely, the `CACHE`
would be cleared by a command like `earthly prune`, but the layer that
installed it was still assumed to be cached (and therefore skipped),
leading to a very confusing error where the installation of `cargo-chef`
was incorrectly skipped, and calls to it would fail.

Copying it immediately after installation outside the persistent `CACHE`
into the layer itself, means that if this step is considered cached by
earthly, and therefore skipped, that a copy of the cargo-chef binary
will be guaranteed to exist in a location already defined in the system
`PATH`, avoiding the confusing and unpredictable error.
  • Loading branch information
nrdxp committed Aug 27, 2024
1 parent be7518a commit 6997b1b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setup:

COPY Cargo.* .rustfmt.toml rust-toolchain.toml .
RUN rustup show
RUN cargo install --locked cargo-chef
RUN cargo install --locked cargo-chef && cp "$CARGO_HOME/bin/cargo-chef" /usr/local/bin

source:
FROM +setup
Expand Down

0 comments on commit 6997b1b

Please sign in to comment.