Skip to content

Commit

Permalink
update dockerfile
Browse files Browse the repository at this point in the history
  • 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.
81 changes: 13 additions & 68 deletions Dockerfile
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"]

0 comments on commit 3afe8f0

Please sign in to comment.