Skip to content

Commit d311c7e

Browse files
committed
ci(experiment): add sccache docker build workflow (task 3b)
- Containerfile.sccache-experiment: ARG for GHA credentials - New experiment-sccache-docker.yaml (Docker build + E2E) - Local Docker stage timings: third-party deps 52.75 s - Need GHA runner for cold/warm comparison Note: build-args for GHA tokens trigger Docker security warnings. Acceptable for experiment branches. Production would use --secret-env.
1 parent 7ef86ff commit d311c7e

3 files changed

Lines changed: 129 additions & 15 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Experiment — sccache Docker Build (Task 3b)
2+
3+
# Self-contained A/B benchmark for sccache inside Docker builds:
4+
# Cold push → full docker build from scratch with sccache inside Containerfile
5+
# Re-trigger → measures cross-run sccache GHA backend hits inside Docker
6+
#
7+
# Manual process to capture results:
8+
# 1. Push this branch → workflow runs. Check the workflow run total duration.
9+
# The docker build step output shows BuildKit cache status.
10+
# 2. Re-trigger via workflow_dispatch → second run should show BuildKit cache hits
11+
# for the dependencies layers (cargo chef cook layers) AND sccache hits inside
12+
# 3. Record times in the issue spec
13+
14+
on:
15+
push:
16+
branches:
17+
- "1726-reduce-build-times-sccache"
18+
workflow_dispatch:
19+
20+
env:
21+
CARGO_TERM_COLOR: always
22+
23+
jobs:
24+
benchmark:
25+
name: sccache Docker Build Benchmark
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 120
28+
29+
steps:
30+
- id: checkout
31+
name: Checkout Repository
32+
uses: actions/checkout@v6
33+
34+
- id: setup-sccache
35+
name: Install sccache (GHA backend)
36+
uses: mozilla-actions/sccache-action@v0.0.10
37+
38+
- id: setup-buildx
39+
name: Setup Buildx
40+
uses: docker/setup-buildx-action@v4
41+
42+
- id: setup-rust
43+
name: Setup Rust Toolchain
44+
uses: dtolnay/rust-toolchain@stable
45+
with:
46+
toolchain: stable
47+
48+
- id: fetch
49+
name: Download Dependencies
50+
run: cargo fetch --verbose
51+
52+
# ── Docker build ─────────────────────────────────────────────
53+
- id: build
54+
name: Build Tracker Image
55+
uses: docker/build-push-action@v7
56+
with:
57+
file: ./Containerfile.sccache-experiment
58+
push: false
59+
load: true
60+
target: release
61+
tags: torrust-tracker:sccache-experiment
62+
cache-from: type=gha,scope=experiment-sccache-release
63+
cache-to: type=gha,scope=experiment-sccache-release,mode=max
64+
# Pass GHA creds into Docker for sccache. ACTIONS_RUNTIME_TOKEN is
65+
# short-lived (~5 min). Build-args are visible in docker history but
66+
# acceptable for experiment branches (not production).
67+
build-args: |
68+
SCCACHE_GHA_ENABLED=${{ env.SCCACHE_GHA_ENABLED }}
69+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
70+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
71+
github-token: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- id: sccache-stats
74+
name: sccache Stats (Host Daemon)
75+
run: |
76+
echo "::group::sccache Host Daemon Stats"
77+
sccache --show-stats || echo "sccache daemon not running on host"
78+
echo "::endgroup::"
79+
echo "::notice::NOTE: sccache stats above are from the HOST daemon, not from inside Docker."
80+
echo "Inside-Docker sccache hits/misses will be visible in the BuildKit build output."
81+
echo "Search build logs for 'CACHED' vs 'cargo chef cook' to see layer cache status."
82+
83+
- id: timing
84+
name: Timing Record
85+
run: |
86+
echo "::notice::=== TIMING RECORD ==="
87+
echo "Workflow run ID: ${{ github.run_id }}"
88+
echo "Job started at: $(date -u)"
89+
echo "Build step duration is shown in the workflow run overview."
90+
echo ""
91+
echo "=== BASELINE (container.yaml on develop) ==="
92+
echo "Check recent container.yaml runs at:"
93+
echo " https://github.com/torrust/torrust-tracker/actions/workflows/container.yaml"
94+
echo ""
95+
echo "=== COMPARISON ==="
96+
echo "Cold run (this push): TBD"
97+
echo "Warm run (re-trigger): TBD"
98+
echo "Re-trigger via workflow_dispatch:"
99+
echo " https://github.com/josecelano/torrust-tracker/actions/workflows/experiment-sccache-docker.yaml"

Containerfile.sccache-experiment

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
# syntax=docker/dockerfile:latest
22

3-
# Torrust Tracker
3+
# Torrust Tracker — sccache Experiment Variant
4+
#
5+
# Differences from Containerfile:
6+
# 1. sccache installed in chef stage (inherited by all downstream stages)
7+
# 2. RUSTC_WRAPPER=sccache and SCCACHE_DIR=/sccache env vars in chef
8+
# 3. GHA credentials accepted as ephemeral build-args for sccache cross-run cache
9+
# NOTE: build-args are visible in `docker history`. Acceptable for experiment branches.
10+
# For production (Task 3d), use docker/build-push-action secret-envs input instead.
11+
# 4. sccache --show-stats after every compiler step for experiment measurement
12+
#
13+
# GHA creds: passed as build-args from workflow. Locally: unset → local disk fallback.
14+
ARG SCCACHE_GHA_ENABLED
15+
ARG ACTIONS_RUNTIME_TOKEN
16+
ARG ACTIONS_CACHE_URL
417

518
## Builder Image
619
FROM docker.io/library/rust:trixie AS chef
20+
ARG SCCACHE_GHA_ENABLED
21+
ARG ACTIONS_RUNTIME_TOKEN
22+
ARG ACTIONS_CACHE_URL
23+
ENV SCCACHE_GHA_ENABLED=${SCCACHE_GHA_ENABLED}
24+
ENV ACTIONS_RUNTIME_TOKEN=${ACTIONS_RUNTIME_TOKEN}
25+
ENV ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}
26+
727
WORKDIR /tmp
828
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
929
RUN cargo binstall --no-confirm --locked torrust-cargo-chef@0.1.78 cargo-nextest sccache
10-
# Note: We use the `torrust-cargo-chef` fork (v0.1.78) while upstream PR
11-
# https://github.com/LukeMathWalker/cargo-chef/pull/360 is pending. Once merged,
12-
# switch back to upstream `cargo-chef` and remove this comment.
13-
14-
# sccache configuration
15-
# RUSTC_WRAPPER=sccache is set for all compiler stages
16-
# SCCACHE_GHA_ENABLED=true is only set on GHA via --secret-env (see workflow)
17-
# When not on GHA, sccache uses local disk via SCCACHE_DIR=/sccache
30+
1831
ENV RUSTC_WRAPPER=sccache
1932
ENV SCCACHE_DIR=/sccache
2033
ENV CARGO_INCREMENTAL=0

docs/issues/open/1726-1840-workflow-performance-sccache/ISSUE.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ github-issue: 1726
77
spec-path: docs/issues/open/1726-1840-workflow-performance-sccache/ISSUE.md
88
branch: 1726-reduce-build-times-sccache
99
related-pr: 1905
10-
last-updated-utc: 2026-06-11 19:30
10+
last-updated-utc: 2026-06-11 20:00
1111
semantic-links:
1212
skill-links:
1313
- create-issue
@@ -336,9 +336,10 @@ RUN --mount=type=secret,id=SCCACHE_GHA_ENABLED \
336336

337337
- [x] `Containerfile.sccache-experiment` created with sccache in `chef` stage
338338
- [x] Chef stage built locally: sccache 0.15.0 ✅, cargo-chef ✅, local disk fallback ✅
339-
- [ ] Create `experiment-sccache-docker.yaml` workflow (GHA runner required)
340-
- [ ] Push to `josecelano` fork and verify end-to-end
341-
- [ ] Record cold + warm timing for `docker build` step
339+
- [x] Local Docker stage build times measured: - `dependencies_thirdparty` (external deps, release): **52.75 s** - `dependencies` (workspace cook + pre-link, release): **+31.19 s** - Note: on local Ryzen 9 7950X; GHA runners will be significantly slower
340+
- [x] Create `experiment-sccache-docker.yaml` workflow (Docker build + E2E tests)
341+
- [ ] Push to `josecelano` fork and run cold test
342+
- [ ] Re-trigger for warm test
342343
- [ ] Compare with baseline `container.yaml` timing
343344

344345
---
@@ -383,8 +384,9 @@ Commit message: `ci(container): validate sccache for docker build workflow`
383384
- Cold: **479.44 s** → Cross-run with sccache: **192.21 s** ✅ (60 % reduction, 93.38 % hit rate)
384385
- [ ] **Task 3b: sccache inside Docker build (Strategy B2 — GHA backend via `--secret-env`).**
385386
- ✅ `Containerfile.sccache-experiment` created with sccache in `chef` stage
386-
- ✅ Chef stage built locally: sccache 0.15.0 ✅, cargo-chef ✅
387-
- 🔲 GHA workflow and cross-run test pending (requires GHA runner)
387+
- ✅ Local Docker stage timings measured: third-party deps: 52.75 s
388+
- ✅ experiment-sccache-docker.yaml workflow created
389+
- 🔲 GHA workflow run and cross-run test pending
388390
- [ ] Task 3c: Full E2E with sccache-warmed Docker build.
389391
- [ ] Task 3d: Final decision and cleanup (adopt, reject, or hybrid for Docker context).
390392
- [x] If adoption is not recommended, issue documents why and proposes next optimization steps.

0 commit comments

Comments
 (0)