Skip to content

Unable to import local library dependency #283

@rsb-tbg

Description

@rsb-tbg

Hey all,

I have a project that looks like this:

project/
---app-backend/ **rust binary
---file-processor/ **rust binary
---gcp-sdk/ **rust library
---project-config/
------...
------docker-compose.yaml

Both app-backend and file-processor depend on gcp-sdk and each of their cargo.toml's use a relative path of "../gcp-sdk". They both compile just fine.

In my docker-compose, I'm setting the context at the project/ level. I've provided my Dockerfile for file-processor below but I continue to get the further-below error.

I've removed cargo chef from my Dockerfile and it builds correctly without issue. Does anybody have any idea what I'm doing wrong with cargo chef (because I would like to continue using it)?

# Base image for building the Rust application
FROM lukemathwalker/cargo-chef:latest-rust-latest AS chef
WORKDIR /app
RUN apt update && apt install -y lld clang

# Planner stage
FROM chef AS planner
COPY ./gcp-sdk /app/gcp-sdk
COPY ./file-processor /app/file-processor

WORKDIR /app/file-processor

# Compute a lock-like file for the project dependencies
RUN cargo chef prepare --recipe-path /app/recipe.json

# Builder stage
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

# Build dependencies using the prepared recipe.json
RUN cargo chef cook --release --recipe-path recipe.json

# Copy the source code after the dependencies are cached
COPY --from=planner /app/gcp-sdk /app/gcp-sdk
COPY --from=planner /app/file-processor /app/file-processor

# Build the Rust binary
RUN cargo build --release --bin file-processor

# Runtime stage
FROM debian:bookworm-slim AS runtime
RUN apt-get update -y \
    && apt-get install -y --no-install-recommends openssl ca-certificates \
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

# Copy the compiled binary from the build stage
COPY --from=builder /app/target/release/file-processor /app/file-processor

COPY ./project-config/configuration /app/configuration
COPY ./project-config/wait-for-it.sh /app/wait-for-it.sh
RUN chmod +x /app/wait-for-it.sh

# Entry point for the backend binary
ENTRYPOINT ["/app/file-processor"]

And here's the build error:

rsb-tbg@MacBook-Pro project-config % docker compose up --build
[+] Building 9.7s (16/23)                                                                                                            docker:desktop-linux
 => [file-processor internal] load build definition from Containerfile                                                                               0.0s
 => => transferring dockerfile: 1.47kB                                                                                                               0.0s
 => [file-processor internal] load metadata for docker.io/library/debian:bookworm-slim                                                               0.3s
 => [file-processor internal] load metadata for docker.io/lukemathwalker/cargo-chef:latest-rust-latest                                               0.3s
 => [file-processor internal] load .dockerignore                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                      0.0s
 => [file-processor chef 1/3] FROM docker.io/lukemathwalker/cargo-chef:latest-rust-latest@sha256:e279910c5108e3acf843cb910e7ce1726e0ab37bd3eb394fb8  0.0s
 => [file-processor internal] load build context                                                                                                     0.9s
 => => transferring context: 2.98MB                                                                                                                  0.9s
 => [file-processor runtime 1/6] FROM docker.io/library/debian:bookworm-slim@sha256:36e591f228bb9b99348f584e83f16e012c33ba5cad44ef5981a1d7c0a93eca2  0.0s
 => CACHED [file-processor runtime 2/6] RUN apt-get update -y     && apt-get install -y --no-install-recommends openssl ca-certificates     && apt-  0.0s
 => CACHED [file-processor chef 2/3] WORKDIR /app                                                                                                    0.0s
 => CACHED [file-processor chef 3/3] RUN apt update && apt install -y lld clang                                                                      0.0s
 => CACHED [file-processor planner 1/4] COPY ./gcp-sdk /app/gcp-sdk                                                                                  0.0s
 => [file-processor planner 2/4] COPY ./file-processor /app/file-processor                                                                           4.4s
 => [file-processor planner 3/4] WORKDIR /app/file-processor                                                                                         0.0s
 => [file-processor planner 4/4] RUN cargo chef prepare --recipe-path /app/recipe.json                                                               0.1s
 => CACHED [file-processor builder 1/5] COPY --from=planner /app/recipe.json recipe.json                                                             0.0s
 => ERROR [file-processor builder 2/5] RUN cargo chef cook --release --recipe-path recipe.json                                                       0.3s
------                                                                                                                                                    
 > [file-processor builder 2/5] RUN cargo chef cook --release --recipe-path recipe.json:                                                                  
0.123 warning: unused manifest key: bin.0.plugin                                                                                                          
0.123 warning: unused manifest key: lib.plugin                                                                                                            
0.148     Updating crates.io index                                                                                                                        
0.248 error: failed to get `gcp-sdk` as a dependency of package `file-processor v0.0.1 (/app)`
0.248 
0.248 Caused by:
0.248   failed to load source for dependency `gcp-sdk`
0.248 
0.248 Caused by:
0.248   Unable to update /gcp-sdk
0.248 
0.248 Caused by:
0.248   failed to read `/gcp-sdk/Cargo.toml`
0.248 
0.248 Caused by:
0.248   No such file or directory (os error 2)
0.249 thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-chef-0.1.68/src/recipe.rs:218:27:
0.249 Exited with status code: 101
0.249 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
failed to solve: process "/bin/sh -c cargo chef cook --release --recipe-path recipe.json" did not complete successfully: exit code: 101

Thanks for any help!!!

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