Deploying Rust Actix within a workspace

Hi there!

I’m trying to deploy a Rust Actix app that is within a workspace using a lib crate I created. I followed this guide but got this error during the build:

------                                                                                                   
 > [builder 2/4] RUN cargo chef cook --release --recipe-path recipe.json:
0.239     Updating crates.io index
0.253 error: failed to get `common_lib` as a dependency of package `server_app v0.0.1 (/app)`
0.253 
0.253 Caused by:
0.253   failed to load source for dependency `common_lib`
0.253 
0.253 Caused by:
0.253   Unable to update /lib
0.253 
0.253 Caused by:
0.253   failed to read `/lib/Cargo.toml`
0.253 
0.253 Caused by:
0.253   No such file or directory (os error 2)
0.254 thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-chef-0.1.67/src/recipe.rs:218:27:
0.254 Exited with status code: 101
0.254 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------

My folder structure is:

/rust
----/lib
--------Cargo.toml
----/server
--------/src/main.rs
--------Cargo.toml
--------Dockerfile
--------fly.toml

And the Cargo.toml in /rust/server contains:

[dependencies]
common_lib = { path = "../lib" }

The generated Dockerfile is:

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

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --bin server_app

# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/server_app /usr/local/bin
ENTRYPOINT ["/usr/local/bin/server_app"]

Have you some hints on this? :slight_smile:

Hey @hugodz,
Looks like the error is caused due to your dependency.Does your dependency name common_lib match with the package name specified under the [package] section of lib/Cargo.toml?

Yes it does. I do think the cargo chef thing mess up the Docker build context at some point :thinking:

What’s the status of your deployment?

I solved the issue placing the fly.toml in the parent folder and copying the /lib folder by hand in the Dockerfile…

But this is not usable state of things for Rust deployment in Fly (with workspace and local libs crates), I guess cargo chef messed up the JSON recipe or something, but there is something going on here. I saw some folks posting similar issues in the cargo chef repo, all quircking around with copying files by hand in the Docker build context.

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

FROM chef AS planner
COPY . .
COPY ../lib ../lib
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
COPY ../lib ../lib
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json -p server_app
# Build application
COPY . .
RUN cargo build --release --bin server_app -p server_app

# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/server_app /usr/local/bin
ENTRYPOINT ["/usr/local/bin/server_app"]
1 Like

Yeah it most likely seems to be an issue with cargo chef Dockerfile. Need to test this one out!

Actually cargo chef do it’s job well until you’re working with Rust workspaces. Which is the case for most of complex project.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.