Skip to content

cargo chef appears to ignore Cargo.lock #252

@thomaseizinger

Description

@thomaseizinger

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 the source code above for the v0.52 tag and try to build the Dockerfile using:

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 [email protected] --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):

# 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions