chore: Use cargo-chef to build the hivetests docker image (#14884)

Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
This commit is contained in:
Ján Jakub Naništa
2025-03-11 07:52:36 -07:00
committed by GitHub
parent cdc6136999
commit 4920ad6dbe
4 changed files with 66 additions and 18 deletions

View File

@@ -1,7 +1,60 @@
FROM ubuntu
# syntax=docker.io/docker/dockerfile:1.7-labs
COPY dist/reth /usr/local/bin
#
# We'll use cargo-chef to speed up the build
#
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config
#
# We prepare the build plan
#
FROM chef AS planner
ARG CARGO_BIN
COPY --exclude=.git --exclude=dist . .
RUN cargo chef prepare --recipe-path recipe.json --bin ${CARGO_BIN}
#
# And build the app
#
FROM chef AS builder
WORKDIR /app
ARG CARGO_BIN
ARG BUILD_PROFILE=hivetests
ARG FEATURES=""
ARG MANIFEST_PATH=""
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook \
--profile $BUILD_PROFILE \
--bin $CARGO_BIN \
${FEATURES:+--features "$FEATURES"} \
${MANIFEST_PATH:+--manifest-path $MANIFEST_PATH} \
--recipe-path recipe.json
COPY --exclude=.git --exclude=dist . .
RUN cargo build \
--profile $BUILD_PROFILE \
--bin $CARGO_BIN \
${FEATURES:+--features "$FEATURES"} \
${MANIFEST_PATH:+--manifest-path $MANIFEST_PATH} \
--locked
#
# The runtime will then just use the build artifact without building anything
#
FROM ubuntu AS runtime
ARG CARGO_BIN
COPY --from=builder /app/target/hivetests/$CARGO_BIN /usr/local/bin/reth
COPY LICENSE-* ./
EXPOSE 30303 30303/udp 9001 8545 8546

View File

@@ -31,20 +31,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: mkdir artifacts
- uses: rui314/setup-mold@v1
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Build reth
run: |
CARGO_CMD="cargo build --features ${{ inputs.cargo_features }} --profile hivetests --bin ${{ inputs.binary_name }} --locked"
if [ -n "${{ inputs.cargo_package }}" ]; then
CARGO_CMD="$CARGO_CMD --manifest-path ${{ inputs.cargo_package }}"
fi
$CARGO_CMD
mkdir dist && cp ./target/hivetests/${{ inputs.binary_name }} ./dist/reth
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
@@ -56,6 +42,10 @@ jobs:
file: .github/assets/hive/Dockerfile
tags: ${{ inputs.image_tag }}
outputs: type=docker,dest=./artifacts/reth_image.tar
build-args: |
CARGO_BIN=${{ inputs.binary_name }}
MANIFEST_PATH=${{ inputs.cargo_package }}
FEATURES=${{ inputs.cargo_features }}
cache-from: type=gha
cache-to: type=gha,mode=max

3
.gitignore vendored
View File

@@ -53,3 +53,6 @@ rustc-ice-*
# Book sources should be able to build with the latest version
book/sources/Cargo.lock
# Cargo chef recipe file
recipe.json

View File

@@ -1,3 +1,5 @@
# syntax=docker.io/docker/dockerfile:1.7-labs
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
@@ -9,7 +11,7 @@ RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-
# Builds a cargo-chef plan
FROM chef AS planner
COPY . .
COPY --exclude=.git --exclude=dist . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
@@ -31,7 +33,7 @@ ENV FEATURES=$FEATURES
RUN cargo chef cook --profile $BUILD_PROFILE --features "$FEATURES" --recipe-path recipe.json
# Build application
COPY . .
COPY --exclude=.git --exclude=dist . .
RUN cargo build --profile $BUILD_PROFILE --features "$FEATURES" --locked --bin reth
# ARG is not resolved in COPY so we have to hack around it by copying the