LukeMathWalker / cargo-chef

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

toolchain in recipe.json is ignored in `cargo chef cook` #271

Open kobkaz opened 2 months ago

kobkaz commented 2 months ago

cargo chef cook generates rust-toolchain.toml file, but it's not used in the subsequent build of dependencies. rust-toolchain.toml takes effect when cargo is invoked next time. Therefore, executing cargo chef cook twice results in building with the wrong toolchain for the first time and the correct building for the second time.

The following Dockerfile reproduces the problem.

FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app

FROM chef AS planner
RUN echo '[workspace]\nresolver = "2"\nmembers = ["hello"]' > Cargo.toml
RUN cargo new hello
RUN echo '[toolchain]\nchannel = "1.75.0"' > rust-toolchain.toml
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json # does not install 1.75.0
RUN cargo chef cook --release --recipe-path recipe.json # does install 1.75.0