forked from flashbots/rbuilder
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Keszey Dániel
authored and
Keszey Dániel
committed
Oct 25, 2024
1 parent
45a5043
commit 3afe8f0
Showing
1 changed file
with
13 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,19 @@ | ||
# | ||
# 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.81 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 | ||
|
||
COPY ./Cargo.lock ./Cargo.lock | ||
COPY ./Cargo.toml ./Cargo.toml | ||
COPY ./.git ./.git | ||
COPY ./crates/ ./crates/ | ||
|
||
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 | ||
|
||
# | ||
# Builder container (running "cargo chef cook" and "cargo build --release") | ||
# | ||
FROM base as builder | ||
# Dockerfile for building rbuilder executable | ||
FROM lukemathwalker/cargo-chef:latest-rust-1 AS builder | ||
WORKDIR /app | ||
|
||
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 ./Cargo.lock ./Cargo.lock | ||
COPY ./Cargo.toml ./Cargo.toml | ||
COPY ./.git ./.git | ||
COPY ./crates/ ./crates/ | ||
# Install system dependencies | ||
RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config git | ||
|
||
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" | ||
|
||
# | ||
# Runtime container | ||
# | ||
FROM gcr.io/distroless/cc-debian12 | ||
|
||
WORKDIR /app | ||
# Copy the entire rbuilder repository | ||
COPY . . | ||
|
||
# RUN apk add libssl3 ca-certificates | ||
# RUN apt-get update \ | ||
# && apt-get install -y libssl3 ca-certificates \ | ||
# && rm -rf /var/lib/apt/lists/* | ||
# Build the executable | ||
RUN cargo build --release | ||
|
||
COPY --from=builder /app/target/release/rbuilder /app/rbuilder | ||
# Stage for the executable | ||
FROM scratch | ||
COPY --from=builder /app/target/release/rbuilder /usr/local/bin/rbuilder | ||
|
||
ENTRYPOINT ["/app/rbuilder"] | ||
# Mark the executable as the entrypoint | ||
ENTRYPOINT ["/usr/local/bin/rbuilder"] |