Skip to content

Commit

Permalink
chore(docker): cache packages to speed up builds
Browse files Browse the repository at this point in the history
  • Loading branch information
malpercio-dev committed Dec 1, 2024
1 parent 6736ba1 commit 369640c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
FROM rust:1.82.0-bullseye as builder
ENV APP atBB
WORKDIR /usr/src/$APP
FROM rust:1.82.0-bullseye as base
RUN cargo install sccache --version ^0.7
RUN cargo install cargo-chef --version ^0.1
ENV RUSTC_WRAPPER=sccache SCCACHE_DIR=/sccache

FROM base AS planner
WORKDIR /app
COPY . .
RUN cargo install --path .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
cargo chef prepare --recipe-path recipe.json

FROM base AS builder
WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
cargo install --path .

FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/$APP /usr/local/bin/$APP
COPY --from=builder /usr/local/cargo/bin/atBB /usr/local/bin/atBB
ENTRYPOINT [ "/usr/local/bin/atBB" ]

0 comments on commit 369640c

Please sign in to comment.