LukeMathWalker / cargo-chef

A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Apache License 2.0
1.81k stars 117 forks source link

We should keep all manifests, even if they are not mentioned in the list of workspace members #207

Closed LukeMathWalker closed 1 year ago

LukeMathWalker commented 1 year ago

…since the binary target might depend on them via a path dependency.

We could be more surgical and keep exclusively the ones that are in the binary's transitive dependency closure, but we'll leave that for a future PR.

Zizico2 commented 1 year ago

The problem I mentioned here https://github.com/LukeMathWalker/cargo-chef/issues/205#issuecomment-1514068403 happens with a crate that is mentioned in the workspace members tho

LukeMathWalker commented 1 year ago

I'm aware—the expected behaviour is removing it from the list of workspace members but keeping the actual manifest of that crate around, so that it's picked up as a path dependency.

Can you test again on 0.1.57? @Zizico2

oddgrd commented 1 year ago

Hey @LukeMathWalker! We are also experiencing this issue, and it persists on 0.1.57. Like @Zizico2 it also works for us if we use 0.1.54. Dockerfile: https://github.com/shuttle-hq/shuttle/blob/main/Containerfile Workspace manifest: https://github.com/shuttle-hq/shuttle/blob/main/Cargo.toml

Error:

 > [builder 2/4] RUN cargo chef cook $(if [ "debug" = "release" ]; then echo --debug; fi) --recipe-path recipe.json:
#0 0.456 error: failed to get `shuttle-secrets` as a dependency of package `cargo-shuttle v0.0.1 (/build/cargo-shuttle)`
#0 0.456
#0 0.456 Caused by:
#0 0.456   failed to load source for dependency `shuttle-secrets`
#0 0.456
#0 0.456 Caused by:
#0 0.456   Unable to update /build/resources/secrets
#0 0.456
#0 0.456 Caused by:
#0 0.456   failed to read `/build/resources/secrets/Cargo.toml`
#0 0.456
#0 0.456 Caused by:
#0 0.456   No such file or directory (os error 2)
#0 0.459 thread 'main' panicked at 'Exited with status code: 101', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cargo-chef-0.1.57/src/recipe.rs:189:27
#0 0.459 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
Containerfile:32
--------------------
  30 |     COPY --from=planner /build/recipe.json recipe.json
  31 |     ARG CARGO_PROFILE
  32 | >>> RUN cargo chef cook $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi) --recipe-path recipe.json
  33 |     COPY --from=cache /build .
  34 |     ARG folder
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo chef cook $(if [ \"$CARGO_PROFILE\" = \"release\" ]; then echo --${CARGO_PROFILE}; fi) --recipe-path recipe.json" did not complete successfully: exit code: 101
make: *** [Makefile:162: shuttle-provisioner] Error 1
Zizico2 commented 1 year ago

I'm aware—the expected behaviour is removing it from the list of workspace members but keeping the actual manifest of that crate around, so that it's picked up as a path dependency.

Can you test again on 0.1.57? @Zizico2

It worked @LukeMathWalker

LukeMathWalker commented 1 year ago

Your setup is quite a bit more intricate @oddgrd, but I think the root cause is the fact that you are excluding that crate (shuttle-secrets) from the workspace here.

It should be enough to either: