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

Build Error: Syntax error: ";" unexpected #266

Closed dennohpeter closed 5 months ago

dennohpeter commented 5 months ago

I'm getting this error when building a docker image. Seems the recent docker image broke things

=> ERROR [planner 2/2] RUN cargo chef prepare --recipe-path recipe.json                                                                                                                0.2s
------
 > [planner 2/2] RUN cargo chef prepare --recipe-path recipe.json:
0.162 /root/.cargo/bin/cargo-chef: 1: Syntax error: ";" unexpected
------
Dockerfile:11
--------------------
   9 |     COPY . .
  10 |     
  11 | >>> RUN cargo chef prepare --recipe-path recipe.json
  12 |     
  13 |     # Builder stage
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo chef prepare --recipe-path recipe.json" did not complete successfully: exit code: 2
LukeMathWalker commented 5 months ago

I just tried reproducing the issue, but it worked without hiccups.

Can you provide a minimal repository to reproduce the failure?

dennohpeter commented 5 months ago

Sure is a sample repo to reproduce: https://github.com/dennohpeter/workspace

dennohpeter commented 5 months ago

Now the error is failed to find a workspace root for virtual workspaces

0.391 Error: Failed to compute recipe
0.391 
0.391 Caused by:
0.392     0: Cannot extract Cargo metadata
0.392     1: `cargo metadata` exited with an error: error: failed to parse manifest at `/sub/Cargo.toml`
0.392        
0.392        Caused by:
0.392          error inheriting `anyhow` from workspace root manifest's `workspace.dependencies.anyhow`
0.392        
0.392        Caused by:
0.392          failed to find a workspace root
0.392        
------
failed to solve: process "/bin/sh -c cargo chef prepare --recipe-path recipe.json" did not complete successfully: exit code: 1
LukeMathWalker commented 5 months ago

Those Docker builds are failing because the Docker context is limited to each subdirectory while it should include the parent directory, where the workspace root is defined.

cargo-chef is irrelevant here.

dennohpeter commented 5 months ago

Noted, any suggestion on how to solve the issue?

LukeMathWalker commented 5 months ago

Move the Dockerfiles to the root of the repository.

I'll close this in the meantime.