LukeMathWalker / LukeMathWalker/cargo-chef
Using cargo-chef increased my build time from 5 minutes to 25 mintues
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.7k
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Description
Hi
I have a monorepo with a workspace at the root and each micro-service as a cargo project.
when I copy all the files from the root to docker e..g `COPY . . ` and then run the cargo-chef commands as shown in the README - in the chef cook --release it compiles and builds my entire workspace including all the binaries which takes a long time.
Then it does the build release for the binary I actually want:
```RUN cargo build --release --bin image-categorisation-service```
Is there a way cargo-chef can avoid building the entire workspace when I just want to release the image-categorisation-service binary in a docker image
using cargo-chef has increased the build time for releasing just the image-categorisation-service from 5 minutes to 25 minutes because it's building the entire workspace
```dockerfile
ARG RUST_VERSION=1.78.0
ARG APP_NAME=image-categorisation-service
# Install cargo-chef
FROM rust:${RUST_VERSION} AS chef
# We only pay the installation cost once,
# it will be cached from the second build onwards
RUN cargo install cargo-chef
WORKDIR /app
# Prepare the recipe
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Build the project
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 image-categorisation-service
# Setup the Runtime
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/image-categorisation-service /usr/local/bin
CMD ["/usr/local/bin/image-categorisation-service"]
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the README workflow and the provided Dockerfile, starting with cargo chef prepare and cargo chef cook --release for the workspace recipe. Determine how the selected image-categorisation-service binary can avoid rebuilding unrelated workspace binaries, and consider the relevant workspace and recipe behavior. Done means the dependency-cache stage supports this targeted release build without compiling the entire workspace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, rust
- Domain
- build-system, devops, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100