Skip to content

I can't make it work for target x86_64-unknown-linux-musl #172

@josecelano

Description

@josecelano

I have a Dokerfile similar to what is described in this repo README file.

The cache is not working.

Expected behaviour

I suppose the build should use the cached layer if I do not change any file in src directory or the Cargo.toml or Cargo.lock files.

In other words, this line:

RUN cargo build --release --target x86_64-unknown-linux-musl --bin rust-cargo-chef-test

should be cached if you do not change those files.

Actual behavior

The cargo build compiles all the files even if you only change the README file.

How to reproduce

I've created a repo with the minimum code to reproduce the problem. You can reproduce it running:

cd /tmp
git clone [email protected]:josecelano/rust-cargo-chef-test.git
cd rust-cargo-chef-test

If you run the build script twice, the second time, you will use the cache for all the layers:

$ ./build.sh 
./build.sh: line 3: UID: readonly variable
Building docker image ...
UID: 1000
[+] Building 2.0s (24/24) FINISHED                                                                                                     
 => [internal] load build definition from Dockerfile                                                                              0.1s
 => => transferring dockerfile: 1.31kB                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                 0.0s
 => => transferring context: 61B                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                  1.3s
 => [internal] load metadata for docker.io/clux/muslrust:stable                                                                   1.6s
 => [stage-3 1/7] FROM docker.io/library/alpine:latest@sha256:8914eb54f968791faf6a8638949e480fef81e697984fba772b3976835194c6d4    0.0s
 => [chef 1/3] FROM docker.io/clux/muslrust:stable@sha256:368156460a4f9a4498cb7bf842096f2e13bcfac982a4b16c660733fad452c3b9        0.0s
 => CACHED [chef 2/3] WORKDIR /app                                                                                                0.0s
 => CACHED [chef 3/3] RUN cargo install cargo-chef                                                                                0.0s
 => CACHED [planner 1/3] WORKDIR /app                                                                                             0.0s
 => [internal] load build context                                                                                                 0.1s
 => => transferring context: 82.91kB                                                                                              0.1s
 => CACHED [stage-3 2/7] WORKDIR /app                                                                                             0.0s
 => CACHED [stage-3 3/7] RUN apk --no-cache add ca-certificates                                                                   0.0s
 => CACHED [builder 2/6] RUN adduser   --disabled-password   --gecos ""   --home "/nonexistent"   --shell "/sbin/nologin"   --no  0.0s
 => CACHED [planner 2/3] COPY . .                                                                                                 0.0s
 => CACHED [planner 3/3] RUN cargo chef prepare --recipe-path recipe.json                                                         0.0s
 => CACHED [builder 3/6] COPY --from=planner /app/recipe.json recipe.json                                                         0.0s
 => CACHED [builder 4/6] RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json               0.0s
 => CACHED [builder 5/6] COPY . .                                                                                                 0.0s
 => CACHED [builder 6/6] RUN cargo build --release --target x86_64-unknown-linux-musl --bin rust-cargo-chef-test                  0.0s
 => CACHED [stage-3 4/7] COPY --from=builder /etc/passwd /etc/passwd                                                              0.0s
 => CACHED [stage-3 5/7] COPY --from=builder /etc/group /etc/group                                                                0.0s
 => CACHED [stage-3 6/7] COPY --from=builder --chown=appuser   /app/target/x86_64-unknown-linux-musl/release/rust-cargo-chef-tes  0.0s
 => CACHED [stage-3 7/7] RUN chown -R appuser:appuser /app                                                                        0.0s
 => exporting to image                                                                                                            0.0s
 => => exporting layers                                                                                                           0.0s
 => => writing image sha256:0794352934801e6658229724f9036f21b38831c01c261e97371f5f27dc496fef                                      0.0s
 => => naming to docker.io/library/rust-cargo-chef-test                                                                           0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

but if you change something in the README file and you rerun the build script it will compile the dependencies again:

...
 [builder 6/6] RUN cargo build --release --target x86_64-unknown-linux-musl --bin rust-cargo-chef-test   
...

Notes

I tried to fix it COPYING only the src dir and the Cargo.toml and Cargo.lock files:

COPY ./src/* Cargo.toml Cargo.lock ./
RUN cargo build --release --target x86_64-unknown-linux-musl --bin rust-cargo-chef-test

but it does not work. The layer is cached, but the binary does not work.

The actual project where I have this problem is this one: torrust/torrust-tracker#123

Am I missing something?

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