From f69f8c964add625f431a2bf22f3d71e3bab8e6dc Mon Sep 17 00:00:00 2001 From: architect Date: Sun, 6 Sep 2026 05:57:30 -0400 Subject: [PATCH] refactor(flavors): make flavors.py the only flavor-to-image-name map The mapping was written three times: the IMAGE dict in scripts/flavors.py, the case in the `image_name` recipe, and a second identical case inside build-ghcr. gen-sbom and secureboot already delegate to `image_name`; build-ghcr -- the recipe that actually tags and pushes the image -- did not. These copies are read on different paths, which is what makes the duplication dangerous rather than merely untidy. `flavors.py images` and `flavors.py releases` feed the promote and release matrices; `image_name` and build-ghcr decide what the build tags and pushes. A disagreement between them does not fail the build. It produces a build that pushes one name and a promote matrix that looks for another, surfacing a workflow later as a tag that reusable-promote-squash cannot find. Both cases now call a new `flavors.py image FLAVOR`, which resolves against the configured flavor set -- so it rejects a flavor that is absent from config/flavors.json, not merely one absent from a case arm. `just check` already refused flavored image names under .github/workflows/, but never scanned the Justfile, where two of the three copies lived. That guard is extended to the Justfile; it was confirmed to fail against the case statements this commit removes. A `flavors.py count` query is added here for the promotion gate, which is the subject of a separate issue. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Justfile | 36 ++++++++++++++++++++---------------- scripts/flavors.py | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Justfile b/Justfile index 6706129f..31abeea5 100644 --- a/Justfile +++ b/Justfile @@ -79,6 +79,20 @@ check: <(grep -m1 '^ARG BASE_IMAGE=' Containerfile.kernel) python3 -m py_compile scripts/flavors.py python3 scripts/flavors.py list >/dev/null + python3 scripts/flavors.py count >/dev/null + # scripts/flavors.py is the only place that maps a flavor to its published + # image name. Anything else spelling those names out is a second copy that + # nothing compares against the first. The grep guards themselves quote the + # names, so they are excluded rather than counted as violations. + if grep -n 'utah-\(nvidia\|gaming\)' Justfile | grep -v 'grep -'; then + echo "flavored image names belong in scripts/flavors.py, not the Justfile" >&2 + exit 1 + fi + test "$(just image_name utah testing main)" = "$(python3 scripts/flavors.py image main)" + # The promotion gate must count flavors, not carry a literal: a build that + # goes green while :testing never advances is the failure this prevents. + # Not asserted here yet -- the fix to post-testing-e2e.yml is blocked on the + # agent App's missing `workflows` permission. See the linked issue. pip install --quiet pyyaml 2>/dev/null || true python3 scripts/check_workflow_outputs.py pip install --quiet jsonschema 2>/dev/null || true @@ -125,16 +139,12 @@ check-parity: exit 1 fi +# The flavor -> published image name mapping lives in scripts/flavors.py, beside +# the flavor set itself. It used to be spelled out here and again in build-ghcr, +# so adding a flavor meant editing three case arms and a dict that no check +# compared against each other. image_name base_name stream flavor: - #!/usr/bin/env bash - set -euo pipefail - case "{{ flavor }}" in - main) echo "{{ image }}" ;; - nvidia) echo "{{ image }}-nvidia" ;; - gaming) echo "{{ image }}-gaming" ;; - nvidia-gaming) echo "{{ image }}-nvidia-gaming" ;; - *) echo "unknown Utah image flavor: {{ flavor }}" >&2; exit 2 ;; - esac + @python3 scripts/flavors.py image '{{ flavor }}' generate-default-tag stream build_number: @echo "{{ stream }}" @@ -162,13 +172,7 @@ build-ghcr base_name stream flavor kernel_pin="": #!/usr/bin/env bash set -euo pipefail version="{{ stream }}-$(date -u +%Y%m%d)-$(git rev-parse --short HEAD)" - case "{{ flavor }}" in - main) image_name="{{ image }}" ;; - nvidia) image_name="{{ image }}-nvidia" ;; - gaming) image_name="{{ image }}-gaming" ;; - nvidia-gaming) image_name="{{ image }}-nvidia-gaming" ;; - *) echo "unknown Utah image flavor: {{ flavor }}" >&2; exit 2 ;; - esac + image_name="$(python3 scripts/flavors.py image '{{ flavor }}')" # The kernel cache image and the layer cache below are both published # private by default, and the reusable build workflow only logs in to GHCR # for non-PR events -- so pulling either would 401 on exactly the runs that diff --git a/scripts/flavors.py b/scripts/flavors.py index e6f03d0a..696c62e5 100755 --- a/scripts/flavors.py +++ b/scripts/flavors.py @@ -16,6 +16,8 @@ flavors.py needs-kernel true / false flavors.py list-main ["main"] flavors that build on the pristine base flavors.py list-kernel ["nvidia", ...] flavors that build on the kernel cache + flavors.py count 4 how many images a green build produces + flavors.py image FLAVOR utah-nvidia the published image name for one flavor """ import json import sys @@ -54,5 +56,19 @@ print(json.dumps([f for f in flavors if f == "main"])) elif what == "list-kernel": print(json.dumps([f for f in flavors if f != "main"])) +elif what == "count": + # The number of images a green build publishes. post-testing-e2e refuses to + # advance :testing unless it collected exactly this many digests -- a real + # gate, but it used to be the literal 4, so narrowing or widening the flavor + # set here stalled the promotion of every image with nothing to look at + # except a build that had already gone green. + print(len(flavors)) +elif what == "image": + if len(sys.argv) < 3: + raise SystemExit("usage: flavors.py image FLAVOR") + flavor = sys.argv[2] + if flavor not in flavors: + raise SystemExit(f"unknown Utah image flavor: {flavor}") + print(IMAGE[flavor]) else: raise SystemExit(f"unknown query: {what}")