Skip to content

ci(gitlab): use a per-pipeline BuildKit builder instead of a persistent one - #482

Merged
wdconinc merged 2 commits into
masterfrom
ccr-616d5ca1-vga0gi-per-pipeline-builder
Nov 8, 2026
Merged

wdconinc merged 2 commits into
masterfrom
ccr-616d5ca1-vga0gi-per-pipeline-builder

Conversation

@wdconinc

@wdconinc wdconinc commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Problem

All GitLab build jobs on eic-n0 share one persistent docker-container builder named builder, across pipelines. Concurrent builds from different pipelines on that instance are linked to two recurring failures:

  • no active session for …: context deadline exceeded: a lazily imported cache layer was bound to another build's session.
  • unknown blob sha256:… in history: blobs were garbage-collected while another build still referenced them.

Change

  • BUILDER_NAME: new global variable, default builder-${CI_PIPELINE_ID}. All build jobs of one pipeline share an instance. Jobs of different pipelines no longer do.
  • Rollback switch: run a pipeline with BUILDER_NAME=builder to get the old persistent instance back, with no revert needed.
  • Bootstrap: create no longer bootstraps. A separate buildx inspect --bootstrap step retries up to 3 times, because the three base jobs start together and race to create the same container.
  • clean_builder:docker-new: new finalize job, when: always. It runs after spack-cache-cleanup and removes this pipeline's builder container and state volume. It also sweeps builders of other finished pipelines (success, failed, canceled, skipped), because canceled pipelines never reach finalize. It never removes the persistent builder. It uses the same unauthenticated pipeline-status API call as clean_pipeline.
  • AGENTS.md: documents the above.

Independence from #480 and #481

This PR branches from master and does not touch any registry layer cache settings. All images, CUDA included, keep --cache-from and --cache-to, so this change can be judged on its own. The three branches merge into master together without conflicts, and the merged YAML parses.

If this PR and #481 are both merged, CUDA images get no layer reuse across pipelines at all. They keep reuse within a job, between the default and nightly builds, plus the Spack buildcache.

Known trade-offs

  • Cache mounts start empty in every pipeline. This covers /ccache, /var/cache/spack and the concretization cache. Nightly EICrecon and epic compiles run without ccache, and sources are downloaded again.
  • Layer reuse across pipelines depends on registry cache hits. Previous ephemeral-builder attempts saw consistent misses. Here is one hypothesis, not yet verified. The base images are rebuilt in every pipeline, so any change in their digest invalidates every eic stage in an imported cache. A persistent builder masks that through local state.
  • What to check after merge: whether the builder_concretization_default and builder_installation_default steps show CACHED in an eic_ci or eic_xl job on a master pipeline.
  • spack-cache-cleanup becomes nearly a no-op with per-pipeline builders. It is kept for the BUILDER_NAME=builder mode.
  • The old buildx_buildkit_builder0 container and volume stay on eic-n0 until someone removes or prunes them.

Validation


Generated by Claude Code

Copilot AI balanced review requested due to automatic review settings November 1, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Move GitLab CI builds from a shared persistent BuildKit builder to a per-pipeline builder to prevent cross-pipeline session/cache interference and reduce flakiness on concurrent builds.

Changes:

  • Introduces BUILDER_NAME (default builder-${CI_PIPELINE_ID}) and updates build setup to use it.
  • Splits BuildKit bootstrapping into a retryable buildx inspect --bootstrap loop.
  • Adds a clean_builder:docker-new finalize job to remove per-pipeline builders and sweep builders from finished pipelines; documents behavior in AGENTS.md.
File Description
AGENTS.md Documents per-pipeline BuildKit builder behavior and cleanup job.
.gitlab-ci.yml Adds BUILDER_NAME, changes buildx initialization/bootstrapping, and introduces finalize cleanup job.

Review effort: Lite

Comment thread .gitlab-ci.yml Resolved
Comment thread .gitlab-ci.yml Resolved
Comment thread .gitlab-ci.yml Resolved
Comment thread .gitlab-ci.yml Resolved
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Capybara summary for PR 482

@wdconinc
wdconinc force-pushed the ccr-616d5ca1-vga0gi-per-pipeline-builder branch from 5413217 to abb6639 Compare November 2, 2026 22:38
@wdconinc
wdconinc force-pushed the ccr-616d5ca1-vga0gi-per-pipeline-builder branch from abb6639 to 916d678 Compare November 3, 2026 20:18
wdconinc pushed a commit that referenced this pull request Nov 4, 2026
GitLab builds imported four Docker layer caches per build: the branch and
master tags on both eicweb and ghcr.io/eic/buildcache.  The ghcr.io caches
are written by GitHub Actions builds, never by GitLab, and give BuildKit a
second set of records that can match the same cache keys as eicweb's.  In
#482's pipelines, base builds with identical inputs matched some steps and
then missed the following ones, and mixing records from several cache
sources is one suspected cause.

scripts/build-base.sh and scripts/build-eic.sh now import only the CI
system's own registry in CI mode (GitLab: eicweb, as before also the only
cache destination; GitHub: ghcr.io, unchanged), and the public ghcr.io
caches only for local builds (unchanged).  docs/build-pipeline.md
describes the GitLab and local cache sources.

The Spack binary buildcache mirrors (mirrors.yaml.in, including the ghcr
mirror that GitLab reads and pushes to) are not changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019qEz4vCZUkz3xKJYKfcaaf
wdconinc added a commit that referenced this pull request Nov 5, 2026
GitLab builds imported four Docker layer caches per build: the branch and
master tags on both eicweb and ghcr.io/eic/buildcache.  The ghcr.io caches
are written by GitHub Actions builds, never by GitLab, and give BuildKit a
second set of records that can match the same cache keys as eicweb's.  In
#482's pipelines, base builds with identical inputs matched some steps and
then missed the following ones, and mixing records from several cache
sources is one suspected cause.

scripts/build-base.sh and scripts/build-eic.sh now import only the CI
system's own registry in CI mode (GitLab: eicweb, as before also the only
cache destination; GitHub: ghcr.io, unchanged), and the public ghcr.io
caches only for local builds (unchanged).  docs/build-pipeline.md
describes the GitLab and local cache sources.

The Spack binary buildcache mirrors (mirrors.yaml.in, including the ghcr
mirror that GitLab reads and pushes to) are not changed.


Claude-Session: https://claude.ai/code/session_019qEz4vCZUkz3xKJYKfcaaf

Co-authored-by: Claude <noreply@anthropic.com>
@wdconinc
wdconinc force-pushed the ccr-616d5ca1-vga0gi-per-pipeline-builder branch from 916d678 to 3ec3a53 Compare November 5, 2026 16:09
…nt one

All GitLab build jobs on eic-n0 shared one persistent docker-container
builder ("builder") across pipelines.  Concurrent builds from different
pipelines on that instance hit "no active session" errors for lazily
imported cache layers and "unknown blob ... in history" when blobs were
garbage-collected under them.

- BUILDER_NAME (default builder-${CI_PIPELINE_ID}) names the builder; all
  build jobs of a pipeline share it, jobs of different pipelines do not.
  Setting BUILDER_NAME=builder restores the persistent instance.
- Bootstrap is retried, since concurrent jobs of a pipeline race to
  create the builder container.
- clean_builder:docker-new removes this pipeline's builder after
  spack-cache-cleanup, and the builders of other finished pipelines,
  since canceled pipelines never reach the finalize stage.

Registry layer caching (--cache-from/--cache-to) is unchanged: a fresh
builder relies on it for layer reuse.  Cache mounts (ccache, spack
sources, concretization cache) now start empty in every pipeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019qEz4vCZUkz3xKJYKfcaaf
@wdconinc
wdconinc force-pushed the ccr-616d5ca1-vga0gi-per-pipeline-builder branch from 3ec3a53 to 40c6dcd Compare November 5, 2026 22:48
- Remove the builder in its own builder-cleanup stage after finalize,
  instead of a finalize job with needs on spack-cache-cleanup: without
  needs, clean_builder only starts once every job of all earlier stages
  (including spack-cache-cleanup) has finished.
- Make builder creation idempotent: fall back to `docker buildx use`
  if `docker buildx create` reports an existing builder.  (Each job
  container starts with an empty buildx config, so this is a safeguard;
  concurrent jobs race only at bootstrap, which is retried.)
- Document that a job retried after clean_builder ran re-creates the
  builder (empty, layers from the registry cache), and that the sweep
  in later pipelines removes it once its pipeline has finished again.
- apk add --no-cache in clean_builder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019qEz4vCZUkz3xKJYKfcaaf
@wdconinc
wdconinc enabled auto-merge (squash) November 6, 2026 23:40
@wdconinc
wdconinc requested review from a team and veprbl November 6, 2026 23:41
@wdconinc
wdconinc merged commit 0bd77e4 into master Nov 8, 2026
93 checks passed
@wdconinc
wdconinc deleted the ccr-616d5ca1-vga0gi-per-pipeline-builder branch November 8, 2026 14:36

This branch was previously deployed

1 inactive deployment
github-pages — a8efd510 Deployed Nov 7, 2026 by wdconinc via deploy-artifacts-page #4570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants