mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
114 lines
4.0 KiB
Docker
114 lines
4.0 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# Dockerfile for reth, optimized for Depot builds
|
|
# Supports PGO+BOLT optimization for maximum performance
|
|
# Usage:
|
|
# reth: --build-arg BINARY=reth
|
|
# PGO+BOLT: --build-arg USE_PGO_BOLT=true (Linux x86_64/aarch64 only)
|
|
|
|
FROM rust:1.93 AS builder
|
|
WORKDIR /app
|
|
|
|
LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth
|
|
LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"
|
|
|
|
RUN apt-get update && apt-get install -y libclang-dev pkg-config
|
|
|
|
# Install sccache for compilation caching
|
|
RUN cargo install sccache --locked
|
|
ENV RUSTC_WRAPPER=sccache
|
|
ENV SCCACHE_DIR=/sccache
|
|
ENV SCCACHE_WEBDAV_ENDPOINT=https://cache.depot.dev
|
|
|
|
# Binary to build
|
|
ARG BINARY=reth
|
|
|
|
# Manifest path for the binary
|
|
ARG MANIFEST_PATH=bin/reth
|
|
|
|
# Build profile, release by default
|
|
ARG BUILD_PROFILE=release
|
|
ENV BUILD_PROFILE=$BUILD_PROFILE
|
|
|
|
# Extra Cargo flags (can be overridden, otherwise set per-platform below)
|
|
ARG RUSTFLAGS=""
|
|
|
|
# Extra Cargo features
|
|
ARG FEATURES=""
|
|
ENV FEATURES=$FEATURES
|
|
|
|
# Git info for vergen (since .git is excluded from Docker context)
|
|
ARG VERGEN_GIT_SHA=""
|
|
ARG VERGEN_GIT_DESCRIBE=""
|
|
ARG VERGEN_GIT_DIRTY="false"
|
|
ENV VERGEN_GIT_SHA=$VERGEN_GIT_SHA
|
|
ENV VERGEN_GIT_DESCRIBE=$VERGEN_GIT_DESCRIBE
|
|
ENV VERGEN_GIT_DIRTY=$VERGEN_GIT_DIRTY
|
|
|
|
# Enable PGO+BOLT optimization (Linux only)
|
|
ARG USE_PGO_BOLT=false
|
|
ENV USE_PGO_BOLT=$USE_PGO_BOLT
|
|
|
|
# Optional path to a pre-collected merged.profdata file in build context.
|
|
ARG PGO_PROFDATA=""
|
|
ENV PGO_PROFDATA=$PGO_PROFDATA
|
|
|
|
# Whether to strip debug symbols from PGO-built binaries.
|
|
ARG STRIP_SYMBOLS=true
|
|
ENV STRIP_SYMBOLS=$STRIP_SYMBOLS
|
|
|
|
# Build application
|
|
# Platform-specific RUSTFLAGS: amd64 uses x86-64-v3 (Haswell+) with pclmulqdq for rocksdb
|
|
ARG TARGETPLATFORM
|
|
COPY --exclude=.git . .
|
|
RUN --mount=type=secret,id=DEPOT_TOKEN,env=SCCACHE_WEBDAV_TOKEN \
|
|
--mount=type=cache,target=/usr/local/cargo/registry,sharing=shared \
|
|
--mount=type=cache,target=/usr/local/cargo/git,sharing=shared \
|
|
--mount=type=cache,target=$SCCACHE_DIR,sharing=shared \
|
|
export RUSTC_WRAPPER=sccache SCCACHE_WEBDAV_ENDPOINT=https://cache.depot.dev SCCACHE_DIR=/sccache && \
|
|
sccache --start-server && \
|
|
if [ "$USE_PGO_BOLT" = "true" ] && [ "$TARGETPLATFORM" = "linux/amd64" ] && [ -n "$PGO_PROFDATA" ] && [ -f "$PGO_PROFDATA" ]; then \
|
|
apt-get update && apt-get install -y -qq lsb-release wget sudo && \
|
|
BINARY="$BINARY" PROFILE="$BUILD_PROFILE" FEATURES="$FEATURES" SKIP_BOLT=true STRIP_SYMBOLS="$STRIP_SYMBOLS" PGO_PROFDATA="$PGO_PROFDATA" \
|
|
./.github/scripts/build_pgo_bolt.sh; \
|
|
else \
|
|
if [ "$USE_PGO_BOLT" = "true" ]; then \
|
|
echo "PGO requested but pre-collected profile missing at '${PGO_PROFDATA:-<unset>}' - falling back to non-PGO build"; \
|
|
fi; \
|
|
if [ -n "$RUSTFLAGS" ]; then \
|
|
export RUSTFLAGS="$RUSTFLAGS"; \
|
|
elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
|
export RUSTFLAGS="-C target-cpu=x86-64-v3 -C target-feature=+pclmulqdq"; \
|
|
fi && \
|
|
cargo build --profile $BUILD_PROFILE --features "$FEATURES" --locked --bin $BINARY --manifest-path $MANIFEST_PATH/Cargo.toml; \
|
|
fi && \
|
|
sccache --show-stats
|
|
|
|
# Copy binary to a known location (ARG not resolved in COPY)
|
|
# Note: Custom profiles like maxperf/profiling output to target/<profile>/, not target/release/
|
|
RUN cp /app/target/$BUILD_PROFILE/$BINARY /app/binary || \
|
|
cp /app/target/release/$BINARY /app/binary
|
|
|
|
FROM ubuntu:24.04 AS runtime
|
|
WORKDIR /app
|
|
|
|
# Binary name for entrypoint
|
|
ARG BINARY=reth
|
|
|
|
# Install runtime dependencies
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends ca-certificates && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy binary from build stage and create canonical symlink for entrypoint
|
|
COPY --from=builder /app/binary /usr/local/bin/
|
|
RUN mv /usr/local/bin/binary /usr/local/bin/$BINARY && \
|
|
ln -s /usr/local/bin/$BINARY /usr/local/bin/reth-binary && \
|
|
chmod +x /usr/local/bin/$BINARY
|
|
|
|
# Copy licenses
|
|
COPY LICENSE-* ./
|
|
|
|
EXPOSE 30303 30303/udp 9001 8545 8546
|
|
ENTRYPOINT ["/usr/local/bin/reth-binary"]
|