Skip to content

Commit

Permalink
refactor(docker): improve cargo-chef caching in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Oct 6, 2022
1 parent 0c7769b commit 0f38960
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# syntax=docker/dockerfile:1.4.3-labs
FROM lukemathwalker/cargo-chef:0.1.39-rust-1.63.0-slim-buster as planner
FROM lukemathwalker/cargo-chef:0.1.39-rust-1.63.0-slim-buster as chef
WORKDIR app

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

FROM lukemathwalker/cargo-chef:0.1.39-rust-1.63.0-slim-buster as cacher
WORKDIR app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
--allow-unauthenticated git
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
RUN cargo chef cook --release --recipe-path recipe.json

FROM rust:1.63.0-slim-buster as builder
WORKDIR app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
--allow-unauthenticated zlib1g-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
COPY . .
COPY --from=cacher /app/target target
COPY --from=cacher $CARGO_HOME $CARGO_HOME
RUN cargo build --release --locked --no-default-features
RUN rm -f target/release/deps/git_cliff*

Expand Down

0 comments on commit 0f38960

Please sign in to comment.