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
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"]