From d6cec0ba50e60fbf5ff0f7fbde0352b07fbde399 Mon Sep 17 00:00:00 2001 From: Lion - dapplion <35266934+dapplion@users.noreply.github.com> Date: Tue, 25 Nov 2025 00:45:25 -0300 Subject: [PATCH] Dockerfile with cargo artifacts caching (#8455) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- Dockerfile | 10 ++++++++-- Dockerfile.dev | 25 ------------------------- 2 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 Dockerfile.dev diff --git a/Dockerfile b/Dockerfile index f925836e48..8cc20ab000 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,19 @@ FROM rust:1.88.0-bullseye AS builder RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev -COPY . 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 -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 RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \ diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 50bf1e5898..0000000000 --- a/Dockerfile.dev +++ /dev/null @@ -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 \ No newline at end of file