Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo chef prepare fails Dockerfile build #107

Closed
z4f1r0v opened this issue Jan 11, 2022 · 6 comments
Closed

cargo chef prepare fails Dockerfile build #107

z4f1r0v opened this issue Jan 11, 2022 · 6 comments

Comments

@z4f1r0v
Copy link

z4f1r0v commented Jan 11, 2022

Hello,

I'm following the familiar Zero To Production book and am facing a problem building a docker image from one of the versions of the Dockerfile. Here it is:

FROM lukemathwalker/cargo-chef:latest-rust-1.56.0 as chef
WORKDIR /app

FROM chef as planner
COPY . .
# Compute a lock-like file for our project
RUN cargo chef prepare  --recipe-path recipe.json

FROM chef as builder
COPY --from=planner /app/recipe.json recipe.json
# Build our project dependencies, not our application!
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
ENV SQLX_OFFLINE true
# Build our project
RUN cargo build --release --bin zero2prod

FROM debian:bullseye-slim AS runtime
WORKDIR /app
RUN apt-get update -y \
    && apt-get install -y --no-install-recommends openssl \
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/zero2prod zero2prod
COPY configuration configuration
ENV APP_ENVIRONMENT production
ENTRYPOINT ["./zero2prod"]

Building the image gives me:

$ docker build --tag zero2prod --file Dockerfile .
[+] Building 1.4s (14/20)                                                                                                
 => [internal] load build definition from Dockerfile                                                                0.0s
 => => transferring dockerfile: 906B                                                                                0.0s
 => [internal] load .dockerignore                                                                                   0.0s
 => => transferring context: 34B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/debian:bullseye-slim                                             1.1s
 => [internal] load metadata for docker.io/lukemathwalker/cargo-chef:latest-rust-1.56.0                             1.2s
 => [auth] library/debian:pull token for registry-1.docker.io                                                       0.0s
 => [auth] lukemathwalker/cargo-chef:pull token for registry-1.docker.io                                            0.0s
 => [internal] load build context                                                                                   0.0s
 => => transferring context: 23.08kB                                                                                0.0s
 => [chef 1/2] FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.56.0@sha256:94c1c11d7afcf4c26fbeec11bbcdc420  0.0s
 => [runtime 1/5] FROM docker.io/library/debian:bullseye-slim@sha256:b0d53c872fd640c2af2608ba1e693cfc7dedea30abcd8  0.0s
 => CACHED [chef 2/2] WORKDIR /app                                                                                  0.0s
 => CACHED [runtime 2/5] WORKDIR /app                                                                               0.0s
 => CACHED [runtime 3/5] RUN apt-get update -y     && apt-get install -y --no-install-recommends openssl     && ap  0.0s
 => [planner 1/2] COPY . .                                                                                          0.0s
 => ERROR [planner 2/2] RUN cargo chef prepare  --recipe-path recipe.json                                           0.1s
------
 > [planner 2/2] RUN cargo chef prepare  --recipe-path recipe.json:
#14 0.134 standard_init_linux.go:228: exec user process caused: exec format error
------
executor failed running [/bin/sh -c cargo chef prepare  --recipe-path recipe.json]: exit code: 1

I'm running this on a M1 Mac. From searching about the topic it seems like this problem is related to my machine. Still decided to ask since I'm not too familiar with the workings of cargo-chef. I would appreciate any hints!

@z4f1r0v z4f1r0v changed the title cargo chef prepare fails dockerfile build cargo chef prepare fails Dockerfile build Jan 11, 2022
@z4f1r0v z4f1r0v changed the title cargo chef prepare fails Dockerfile build cargo chef prepare fails Dockerfile build Jan 11, 2022
@LukeMathWalker
Copy link
Owner

Are you using the cargo-chef version compiled for your OS architecture?
I think this was the issue previously.

@z4f1r0v
Copy link
Author

z4f1r0v commented Jan 12, 2022

I realized that it was a problem with M1. That is solved (thanks to the latest Colima update that gives the ability to pass --arch aarch64 as a parameter).

Unfortunately, I'm getting a new error. If you don't mind @LukeMathWalker I will continue this thread and split accordingly in the end once we (hopefully) get to the bottom of things. This time I get:

docker build --tag zero2prod --file Dockerfile .
[+] Building 23.4s (16/19)                                                                                               
 => [internal] load build definition from Dockerfile                                                                0.0s
 => => transferring dockerfile: 37B                                                                                 0.0s
 => [internal] load .dockerignore                                                                                   0.0s
 => => transferring context: 34B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/debian:bullseye-slim                                             1.2s
 => [internal] load metadata for docker.io/lukemathwalker/cargo-chef:latest-rust-1.53.0                             1.2s
 => [auth] library/debian:pull token for registry-1.docker.io                                                       0.0s
 => [auth] lukemathwalker/cargo-chef:pull token for registry-1.docker.io                                            0.0s
 => [runtime 1/4] FROM docker.io/library/debian:bullseye-slim@sha256:b0d53c872fd640c2af2608ba1e693cfc7dedea30abcd8  0.0s
 => [internal] load build context                                                                                   0.0s
 => => transferring context: 14.63kB                                                                                0.0s
 => [chef 1/2] FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.53.0@sha256:112f5524c4fb257ce9190ed8e747d6c7  0.0s
 => CACHED [runtime 2/4] WORKDIR /app                                                                               0.0s
 => CACHED [runtime 3/4] RUN apt-get update -y     && apt-get install -y --no-install-recommends openssl     && ap  0.0s
 => CACHED [chef 2/2] WORKDIR /app                                                                                  0.0s
 => CACHED [planner 1/2] COPY . .                                                                                   0.0s
 => CACHED [planner 2/2] RUN cargo chef prepare --recipe-path recipe.json                                           0.0s
 => CACHED [builder 1/4] COPY --from=planner /app/recipe.json recipe.json                                           0.0s
 => ERROR [builder 2/4] RUN cargo chef cook --release --recipe-path recipe.json                                    22.1s
------
 > [builder 2/4] RUN cargo chef cook --release --recipe-path recipe.json:
#16 2.658     Updating crates.io index
#16 22.09 thread 'main' panicked at 'Process terminated by signal', /usr/local/cargo/registry/src/git.luolix.top-1ecc6299db9ec823/cargo-chef-0.1.21/src/recipe.rs:137:21
#16 22.09 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
executor failed running [/bin/sh -c cargo chef cook --release --recipe-path recipe.json]: exit code: 101

It seems like the Updating crates.io index process times out. All is well on the host machine. Have you had problems like this?

@LukeMathWalker
Copy link
Owner

Never seen this I am afraid, not sure it's related to cargo-chef.

@orhun
Copy link

orhun commented Jun 8, 2022

I'm having the same problem as above.

 #37 [linux/arm64 cacher 4/4] RUN cargo chef cook --release --recipe-path recipe.json
#37 434.4 thread 'main' panicked at 'Process terminated by signal', /usr/local/cargo/registry/src/git.luolix.top-1ecc6299db9ec823/cargo-chef-0.1.35/src/recipe.rs:146:21
#37 434.4 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#37 ERROR: process "/bin/sh -c cargo chef cook --release --recipe-path recipe.json" did not complete successfully: exit code: 101
#34 [linux/amd64 cacher 4/4] RUN cargo chef cook --release --recipe-path recipe.json
#34 CANCELED
------
 > [linux/arm64 cacher 4/4] RUN cargo chef cook --release --recipe-path recipe.json:
#37 7.119     Updating crates.io index
#37 434.4 thread 'main' panicked at 'Process terminated by signal', /usr/local/cargo/registry/src/git.luolix.top-1ecc6299db9ec823/cargo-chef-0.1.35/src/recipe.rs:146:21
#37 434.4 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
Dockerfile:9
--------------------
   7 |     WORKDIR app
   8 |     COPY --from=planner /app/recipe.json recipe.json
   9 | >>> RUN cargo chef cook --release --recipe-path recipe.json
  10 |     
  11 |     FROM rust:1.60.0-slim-buster as builder

See https://github.com/orhun/git-cliff/runs/6783936127

@lukehsiao
Copy link

We, too, are seeing the same error.

#30 [linux/arm64 builder 2/4] RUN cargo chef cook --release --recipe-path recipe.json
#30 544.9 thread 'main' panicked at 'Process terminated by signal', /usr/local/cargo/registry/src/git.luolix.top-1ecc6299db9ec823/cargo-chef-0.1.35/src/recipe.rs:146:21
#30 545.0 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#30 ERROR: process "/bin/sh -c cargo chef cook --release --recipe-path recipe.json" did not complete successfully: exit code: 101
#26 [linux/amd64 builder 2/4] RUN cargo chef cook --release --recipe-path recipe.json
#26 651.2    Compiling pest_meta v2.1.3
#26 CANCELED
------
 > [linux/arm64 builder 2/4] RUN cargo chef cook --release --recipe-path recipe.json:
#0 8.750     Updating crates.io index
#30 544.9 thread 'main' panicked at 'Process terminated by signal', /usr/local/cargo/registry/src/git.luolix.top-1ecc6299db9ec823/cargo-chef-0.1.35/src/recipe.rs:146:21
#30 545.0 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
Dockerfile:13
--------------------
  11 |     COPY --from=planner /app/recipe.json recipe.json
  12 |     # Build our project dependencies, not our application!
  13 | >>> RUN cargo chef cook --release --recipe-path recipe.json
  14 |     COPY . .
  15 |     ENV SQLX_OFFLINE true
--------------------
error: failed to solve: process "/bin/sh -c cargo chef cook --release --recipe-path recipe.json" did not complete successfully: exit code: 101
Error: buildx failed with: error: failed to solve: process "/bin/sh -c cargo chef cook --release --recipe-path recipe.json" did not complete successfully: exit code: 101

orhun added a commit to orhun/git-cliff that referenced this issue Jun 23, 2022
@LukeMathWalker
Copy link
Owner

This was reported in #136 as well.
It is not an issue with cargo-chef, but rather an issue with cargo itself.

You have two workarounds:

  • Use nightly: cargo +nightly chef -Z sparse-registry cook --release --recipe-path recipe.json;
  • Use CARGO_NET_GIT_FETCH_WITH_CLI=true cargo chef cook --release --recipe-path recipe.json to use an alternative method to fetch the registry, which should be faster.

The sparse-registry should solve this problem for good, but it's not stable yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants