-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,64 @@ | ||
FROM lukemathwalker/cargo-chef:latest AS chef | ||
# | ||
# Base container (with sccache and cargo-chef) | ||
# | ||
# - https://github.com/mozilla/sccache | ||
# - https://github.com/LukeMathWalker/cargo-chef | ||
# | ||
# Based on https://depot.dev/blog/rust-dockerfile-best-practices | ||
# | ||
FROM rust:1.82 as base | ||
|
||
ARG FEATURES | ||
|
||
RUN cargo install sccache --version ^0.8 | ||
RUN cargo install cargo-chef --version ^0.1 | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y clang libclang-dev | ||
|
||
ENV CARGO_HOME=/usr/local/cargo | ||
ENV RUSTC_WRAPPER=sccache | ||
ENV SCCACHE_DIR=/sccache | ||
|
||
# | ||
# Planner container (running "cargo chef prepare") | ||
# | ||
FROM base AS planner | ||
WORKDIR /app | ||
|
||
# Prepare build plan | ||
FROM chef AS planner | ||
COPY ./Cargo.toml ./Cargo.lock ./ | ||
COPY ./src ./src | ||
RUN cargo chef prepare | ||
COPY . . | ||
|
||
# Build application | ||
FROM chef AS builder | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/usr/local/cargo/git \ | ||
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \ | ||
cargo chef prepare --recipe-path recipe.json | ||
|
||
# Install system dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y openssl libclang-dev libssl3 && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
# | ||
# Builder container (running "cargo chef cook" and "cargo build --release") | ||
# | ||
FROM base as builder | ||
WORKDIR /app | ||
# Default binary filename | ||
ARG ROLLUP_BOOST_BIN="rollup-boost" | ||
COPY --from=planner /app/recipe.json recipe.json | ||
|
||
RUN --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \ | ||
cargo chef cook --release --recipe-path recipe.json | ||
|
||
COPY --from=planner /app/recipe.json . | ||
RUN cargo chef cook --release | ||
COPY . . | ||
RUN cargo build --release | ||
|
||
FROM debian:bullseye-slim AS final | ||
COPY --from=builder /app/target/release/rollup-boost /usr/local/bin/ | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/usr/local/cargo/git \ | ||
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \ | ||
cargo build --release --features="$FEATURES" --package=${ROLLUP_BOOST_BIN} | ||
|
||
# | ||
# Runtime container | ||
# | ||
FROM gcr.io/distroless/cc-debian12 | ||
WORKDIR /app | ||
|
||
ARG ROLLUP_BOOST_BIN="rollup-boost" | ||
COPY --from=builder /app/target/release/${ROLLUP_BOOST_BIN} /usr/local/bin/ | ||
|
||
ENTRYPOINT ["/usr/local/bin/rollup-boost"] |