Cargo Chef not working with docker compose
Closed this issue · 2 comments
ajosecueto commented
This is my Dockerfile
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
RUN apt update && apt install -y cmake capnproto libsasl2-dev
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
COPY . .
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release
# We do not need the Rust toolchain to run the binary!
FROM debian:bullseye-slim AS runtime
RUN apt update && apt install -y cmake capnproto libsasl2-dev
WORKDIR app
COPY . .
COPY --from=builder /app/target/release/posts /usr/local/bin/app
RUN ls -l /usr/local/bin
ENTRYPOINT ["/usr/local/bin/app"]
When i build with the following command: docker compose -f docker-compose.yml up -d --build, cargo chef is not caching... and take the same time building always.
LukeMathWalker commented
This has nothing to do with docker-compose.
This:
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
COPY . .
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release
should be converted into this:
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
The extra COPY
statement was busting your cache on every build.
ajosecueto commented
Thanks @LukeMathWalker