# syntax=docker/dockerfile:1 # Unified Dockerfile for reth and op-reth, optimized for Depot builds # Usage: # reth: --build-arg BINARY=reth # op-reth: --build-arg BINARY=op-reth --build-arg MANIFEST_PATH=crates/optimism/bin FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef 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 # Builds a cargo-chef plan FROM chef AS planner COPY --exclude=.git . . RUN cargo chef prepare --recipe-path recipe.json FROM chef AS builder COPY --from=planner /app/recipe.json recipe.json # Binary to build (reth or op-reth) 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 ARG RUSTFLAGS="" ENV RUSTFLAGS="$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 # Build dependencies 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 \ cargo chef cook --profile $BUILD_PROFILE --features "$FEATURES" --locked --recipe-path recipe.json --manifest-path $MANIFEST_PATH/Cargo.toml # Build application 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 \ cargo build --profile $BUILD_PROFILE --features "$FEATURES" --locked --bin $BINARY --manifest-path $MANIFEST_PATH/Cargo.toml RUN sccache --show-stats || true # Copy binary to a known location (ARG not resolved in COPY) # Note: Custom profiles like maxperf/profiling output to target//, 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"]