Dockerfile with cargo artifacts caching (#8455)

When developing locally with kurtosis a typical dev workflow is:

loop:
- Build local lighthouse docker image
- Run kurtosis
- Observe bug
- Fix code

The docker build step would download and build all crates. Docker docs suggests an optimization to cache build artifacts, see https://docs.docker.com/build/cache/optimize/#use-cache-mounts

I have tested and it's like building Lighthouse outside of a docker environment 🤤  The docker build time after changing one line in the top beacon_node crate is 50 seconds on my local machine ❤️

The release path is un-affected. Do you have worries this can affect the output of the release binaries? This is too good of an improvement to keep it in a separate Dockerfile.


  


Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
Lion - dapplion
2025-11-25 00:45:25 -03:00
committed by GitHub
parent bdfade8e3d
commit d6cec0ba50
2 changed files with 8 additions and 27 deletions

View File

@@ -1,13 +1,19 @@
FROM rust:1.88.0-bullseye AS builder FROM rust:1.88.0-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
COPY . lighthouse
ARG FEATURES ARG FEATURES
ARG PROFILE=release ARG PROFILE=release
ARG CARGO_USE_GIT_CLI=true ARG CARGO_USE_GIT_CLI=true
ENV FEATURES=$FEATURES ENV FEATURES=$FEATURES
ENV PROFILE=$PROFILE ENV PROFILE=$PROFILE
ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI
RUN cd lighthouse && make ENV CARGO_INCREMENTAL=1
WORKDIR /lighthouse
COPY . .
# Persist the registry and target file across builds. See: https://docs.docker.com/build/cache/optimize/#use-cache-mounts
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/lighthouse/target \
make
FROM ubuntu:22.04 FROM ubuntu:22.04
RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \

View File

@@ -1,25 +0,0 @@
FROM rust:1.88.0-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
WORKDIR /lighthouse
ARG FEATURES
ARG PROFILE=release
ARG CARGO_USE_GIT_CLI=true
ENV FEATURES=$FEATURES
ENV PROFILE=$PROFILE
ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI
ENV CARGO_INCREMENTAL=1
COPY . .
# Persist the registry and target file across builds. See: https://docs.docker.com/build/cache/optimize/#use-cache-mounts
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/lighthouse/target \
make
FROM ubuntu:22.04
RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \
libssl-dev \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/lighthouse /usr/local/bin/lighthouse