From d0a29196dd4eb00d66a9b23f47a6b8860037b1e1 Mon Sep 17 00:00:00 2001 From: Froidefond Julien Date: Fri, 6 Mar 2026 21:04:40 +0100 Subject: [PATCH] perf: add sccache to Docker builds for faster compilation - Install sccache in builder stage of both api and indexer Dockerfiles - Configure RUSTC_WRAPPER to use sccache - Use Docker cache mount (--mount=type=cache,target=/sccache) to persist cache - Reduces build time significantly on subsequent builds by caching compiled artifacts - Requires Docker BuildKit (enabled by default in Docker 23.0+) Note: First build will still be slow (installs sccache + populates cache) Subsequent builds will be much faster as dependencies are cached --- apps/api/Dockerfile | 9 ++++++++- apps/indexer/Dockerfile | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index 7da8ab8..a3dfcbf 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -1,6 +1,11 @@ FROM rust:1-bookworm AS builder WORKDIR /app +# Install sccache for faster builds +RUN cargo install sccache --locked +ENV RUSTC_WRAPPER=sccache +ENV SCCACHE_DIR=/sccache + COPY Cargo.toml ./ COPY apps/api/Cargo.toml apps/api/Cargo.toml COPY apps/indexer/Cargo.toml apps/indexer/Cargo.toml @@ -11,7 +16,9 @@ COPY apps/indexer/src apps/indexer/src COPY crates/core/src crates/core/src COPY crates/parsers/src crates/parsers/src -RUN cargo build --release -p api +# Build with sccache (cache persisted between builds via Docker cache mount) +RUN --mount=type=cache,target=/sccache \ + cargo build --release -p api FROM debian:bookworm-slim RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget unrar-free poppler-utils && rm -rf /var/lib/apt/lists/* diff --git a/apps/indexer/Dockerfile b/apps/indexer/Dockerfile index 185acf0..4be7f35 100644 --- a/apps/indexer/Dockerfile +++ b/apps/indexer/Dockerfile @@ -1,6 +1,11 @@ FROM rust:1-bookworm AS builder WORKDIR /app +# Install sccache for faster builds +RUN cargo install sccache --locked +ENV RUSTC_WRAPPER=sccache +ENV SCCACHE_DIR=/sccache + COPY Cargo.toml ./ COPY apps/api/Cargo.toml apps/api/Cargo.toml COPY apps/indexer/Cargo.toml apps/indexer/Cargo.toml @@ -11,7 +16,9 @@ COPY apps/indexer/src apps/indexer/src COPY crates/core/src crates/core/src COPY crates/parsers/src crates/parsers/src -RUN cargo build --release -p indexer +# Build with sccache (cache persisted between builds via Docker cache mount) +RUN --mount=type=cache,target=/sccache \ + cargo build --release -p indexer FROM debian:bookworm-slim RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget unrar-free && rm -rf /var/lib/apt/lists/*