LukeMathWalker / LukeMathWalker/cargo-chef
`cargo chef` appears to ignore `Cargo.lock`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.7k
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Description
I have the following `Dockerfile`: https://github.com/libp2p/rust-libp2p/blob/v0.52/interop-tests/Dockerfile.native.
Recently, we released a new version of `libp2p-identity`, version `0.2.8`. That one raises the MSRV in a patch-version. Not necessarily best practice but that is not the point.
If you [download](https://codeload.github.com/libp2p/rust-libp2p/zip/refs/heads/v0.52) the source code above for the `v0.52` tag and try to build the Dockerfile using:
```shell
sudo docker build -f interop-tests/Dockerfile.native .
```
It will fail with:
```
124.1 error: package `libp2p-identity v0.2.8` cannot be built because it requires rustc 1.73.0 or newer, while the currently active rustc version is 1.67.0
124.1 Either upgrade to rustc 1.73.0 or newer, or use
124.1 cargo update -p libp2p-identity@0.2.8 --precise ver
124.1 where `ver` is the latest version of `libp2p-identity` supporting rustc 1.67.0
124.1 thread 'main' panicked at 'Exited with status code: 101', src/recipe.rs:204:27
124.1 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
Dockerfile.native:13
--------------------
11 | COPY --from=planner /app/recipe.json recipe.json
12 | # Build dependencies - this is the caching Docker layer!
13 | >>> RUN cargo chef cook --release --package interop-tests --bin native_ping --recipe-path recipe.json
14 | # Build application
15 | COPY . .
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo chef cook --release --package interop-tests --bin native_ping --recipe-path recipe.json" did not complete successfully: exit code: 101
```
If you change the Dockerfile to the following (i.e. comment out `cargo chef`):
```dockerfile
# syntax=docker/dockerfile:1.5-labs
FROM rust:1.67.0 as chef
RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin
WORKDIR /app
# FROM chef AS planner
# COPY . .
# RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
# COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
# RUN cargo chef cook --release --package interop-tests --bin native_ping --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --package interop-tests --bin native_ping
FROM gcr.io/distroless/cc
COPY --from=builder /app/target/release/native_ping /usr/local/bin/testplan
ENV RUST_BACKTRACE=1
ENTRYPOINT ["testplan"]
```
it suddenly works.
The `Cargo.lock` for the `v0.52` tag points to `libp2p-identity 0.2.7` which has an MSRV of 1.63 and therefore compiles with the old Dockerfile. It appears that `cargo chef` ignores `Cargo.lock`. Is that intended?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with interop-tests/Dockerfile.native and compare cargo chef cook with the direct cargo build that uses Cargo.lock. Inspect src/recipe.rs around line 204 and the cargo chef prepare/cook entry points to determine how dependency metadata is handled. Done means the Cargo.lock behavior is explained and cargo chef cook is consistent with the demonstrated build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100