Refactor Docker build pipeline: matrix-driven selection + reusable workflow#95
Merged
Conversation
Previously every push to main rebuilt and pushed all 7 images to Docker Hub (build ran via workflow_run after CI), so even a docs-only change triggered a full 7-image rebuild. Make the pipeline modular/granular. - Add .github/build-matrix.json: canonical component registry (service, dockerfile, tag_prefix, paths) — single source of truth for the workflows and the publish-matrix test. - Add scripts/select_build_matrix.py: map changed files to affected images using plain `git diff` + the registry (no third-party changed-files action, avoiding the tj-actions CVE-2025-30066 risk class). - Add .github/workflows/_build-images.yml: reusable workflow that builds and pushes one image; callers drive it with a per-component matrix. - ci.yml: detect changes in the push context (reliable github.event.before) and build only the affected images via the reusable workflow, still gated on the test + security jobs. - build-and-push.yml: drop workflow_run; now handles v* tags (full image set) and manual workflow_dispatch (all, or a single chosen image). - Update tests (registry coverage, node24 pins now on the reusable workflow, full selection-logic coverage) and docs. Docs-only, core, and test changes now build no image; a change under a single component rebuilds only that image. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B2rvA2p3F2H9HRuiE74F3j
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restructure the Docker image build pipeline to decouple image selection from build execution. Introduces a canonical component registry (
.github/build-matrix.json), a selection script that maps changed files to affected images, and a reusable build workflow. This enables:ci.yml): only rebuild images whose source files changedbuild-and-push.yml): rebuild all images for a tag, or pick one via workflow dispatchKey Changes
.github/build-matrix.json(new): Canonical registry of all publishable Docker images with metadata (service name, Dockerfile path, tag prefix, change-detection globs)scripts/select_build_matrix.py(new): Selection script that reads the registry and outputs a compact JSON matrix for GitHub Actions. Supports three modes:--all: select every component (release tags, manual "build all")--service NAME: select one component by name (manual dispatch)--changed FILE: read changed paths from stdin/file and select components whose globs match.github/workflows/_build-images.yml(new): Reusable workflow that builds and pushes a single Docker image. Extracted from the originalbuild-and-push.ymlto avoid duplication betweenci.ymlandbuild-and-push.yml..github/workflows/build-and-push.yml(refactored): Simplified to a two-job workflow:select: resolves the build matrix from the registry (all images for a tag, or one via dispatch)call-build: calls the reusable workflow once per selected imageworkflow_runtrigger (per-component builds now happen inci.yml).github/workflows/ci.yml(enhanced): Added two new jobs:detect-changes: maps changed files to affected images using the selection scriptcall-build: builds only the affected images after tests pass on main/master (push-only guard)tests/test_docker_publish_matrix.py(expanded): Added comprehensive tests for the new selection logic:--all,--service,--changed)CLAUDE.md&README.md: Updated to document the new workflow structure and registry-driven approachImplementation Details
prefix/**recursive) to map changed files to components. A component rebuilds if any of itspathsglobs match a changed file.any_changedisfalseand the build job is skipped._build-images.ymlworkflow accepts service name, Dockerfile path, tag prefix, and scout flag as inputs, allowing bothci.ymlandbuild-and-push.ymlto call it with the same interface.https://claude.ai/code/session_01B2rvA2p3F2H9HRuiE74F3j