Skip to content

Commit

Permalink
refactor: Ensure caching in a separate layer
Browse files Browse the repository at this point in the history
Signed-off-by: Eden Reich <[email protected]>
  • Loading branch information
edenreich committed Feb 23, 2025
1 parent c180c2a commit 04f3efb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ predicates = "3.1.3"
serial_test = "3.2.0"
tempfile = "3.17.1"

[build]
jobs = 3

[profile.release]
lto = true
opt-level = "z"
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
FROM chef AS cacher
ARG TARGET_ARCH
ENV CC=clang \
AR=llvm-ar \
RUSTFLAGS="-C target-feature=+crt-static -C linker=clang" \
RUSTFLAGS="-C target-feature=+crt-static -C linker=clang -C target-cpu=native" \
CARGO_HOME=/root/.cargo \
PATH="/root/.cargo/bin:${PATH}" \
PKG_CONFIG_ALLOW_CROSS=1
PATH="/root/.cargo/bin:${PATH}"

RUN apk add --no-cache \
make \
Expand All @@ -35,13 +34,14 @@ RUN apk add --no-cache \
/tmp/* \
/var/tmp/*

# First build dependencies
COPY --from=planner /app/recipe.json recipe.json
RUN rustup target add ${TARGET_ARCH}
RUN cargo chef cook --release --target ${TARGET_ARCH} --recipe-path recipe.json

# Then build application
FROM cacher AS builder
ARG TARGET_ARCH
COPY . .
COPY --from=cacher /app/target /app/target
RUN cargo build --release --target ${TARGET_ARCH}

FROM gcr.io/distroless/static:nonroot AS minimal
Expand Down

0 comments on commit 04f3efb

Please sign in to comment.