fix(contributor-scan): the release builds the scan image from the pinned base (3.2, part 2)

The `images` job of `.github/workflows/release.yml` built `Dockerfile` with no build
arguments, so the file's own defaults applied: `TASK_BASE_TAG=base-unpublished` and an
empty digest. The first `FROM` could not be resolved. The log of the `v2.1.0-alpha.1` tag's
run (42229293910, job `images (openultrasast, Dockerfile)`, 2026-11-06T13:54:46Z) reads
`ERROR: failed to build: failed to solve: failed to parse stage name
"ghcr.io/norandom/ousast-task-base:base-unpublished@": invalid reference format`. Compose
had the same defect, closed in 89d08e0.

The job now reads `plane/task-base.digest` in a `pins` step before its build, the way the
`pins` job of `engine-image.yml` does: the same pattern, fail closed on an unpublished or
malformed pin, the tag and digest written to the step's outputs. The build step passes them
as `TASK_BASE_TAG` and `TASK_BASE_DIGEST`. The other leg of the matrix, the runner, declares
no such arguments and ignores them. The `image` job of `engine-image.yml` already passes
both arguments to its search-task leg, which does not declare them either: run 42229294086
of the same tag succeeded, and its log holds no line about unused arguments.

Tests: the new `tests/test_task_images.py::test_release_pins_the_base_of_its_scan_image`
fails on the workflow at 9d53c32 (3 failed: the job reads no pin) and passes after, in five
cases. A valid pin writes exactly the two output lines. An unpublished pin, a bare tag, a
short digest and another repository each stop the script with its own message and write
nothing. The test also asserts that the pin is read before the build and that the build
carries both arguments from that step. With `tests/test_search_image.py`, 23 passed. On
this machine the script, run from the tree, wrote `base_tag=base-b696c08` and the digest
`docker-compose.yml` defaults to. ruff format, ruff check, mypy, the three gates and
compileall pass, and the gates print what they printed before the change. An independent
reviewer approved the change in one round; its three notes on the test are applied here
(the step order, the exit status and message, two more malformed pins).

Not run: the release workflow itself, on GitHub.
This commit is contained in:
Marius Ciepluch
2026-11-26 13:50:17 +01:00
parent 9d53c320a5
commit 88ea171dbe
2 changed files with 52 additions and 0 deletions
+18
View File
@@ -64,6 +64,21 @@ jobs:
dockerfile: plane/Dockerfile.runner dockerfile: plane/Dockerfile.runner
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
# The scan image builds FROM the pinned base, and Dockerfile's own default names none (`base-unpublished`), so
# a build without these arguments cannot succeed. The runner takes no base: the arguments are unused there.
- id: pins
run: |
python3 - <<'PYTHON'
import json, os, re
from pathlib import Path
pins = json.loads(Path("plane/task-base.digest").read_text())
pattern = r"ghcr.io/norandom/ousast-task-base:(base-[a-z0-9-]+)@(sha256:[0-9a-f]{64})"
match = re.fullmatch(pattern, pins.get("base") or "")
if not match:
raise SystemExit("base: unpublished/invalid pin; run task-base-image and update plane/task-base.digest")
with open(os.environ["GITHUB_OUTPUT"], "a") as out:
out.write(f"base_tag={match[1]}\nbase_digest={match[2]}\n")
PYTHON
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3 - uses: docker/login-action@v3
with: with:
@@ -86,5 +101,8 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: |
TASK_BASE_TAG=${{ steps.pins.outputs.base_tag }}
TASK_BASE_DIGEST=${{ steps.pins.outputs.base_digest }}
- run: | - run: |
echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.name }}@${{ steps.build.outputs.digest }}" >> "$GITHUB_STEP_SUMMARY" echo "ghcr.io/${{ github.repository_owner }}/${{ matrix.name }}@${{ steps.build.outputs.digest }}" >> "$GITHUB_STEP_SUMMARY"
+34
View File
@@ -169,6 +169,40 @@ def test_ci_pin_gate_offline(case, tmp_path, monkeypatch):
assert not calls assert not calls
@pytest.mark.parametrize("case", ["unpublished", "bare-tag", "short-digest", "wrong-repo", "valid"])
def test_release_pins_the_base_of_its_scan_image(case, tmp_path, monkeypatch):
"""`Dockerfile`'s own default base is `base-unpublished`: built without the pin, the release image cannot exist."""
steps = workflow("release")["jobs"]["images"]["steps"]
pin_steps = [s for s in steps if s.get("id") == "pins"]
assert pin_steps, "the images job reads no pin, so its build takes Dockerfile's default base"
build = next(s for s in steps if s.get("uses") == "docker/build-push-action@v6")
assert steps.index(pin_steps[0]) < steps.index(build), "the pin is read after the build that needs it"
assert "TASK_BASE_TAG=${{ steps.pins.outputs.base_tag }}" in build["with"]["build-args"]
assert "TASK_BASE_DIGEST=${{ steps.pins.outputs.base_digest }}" in build["with"]["build-args"]
script = pin_steps[0]["run"].split("<<'PYTHON'\n", 1)[1].rsplit("PYTHON", 1)[0]
pinned = "ghcr.io/norandom/ousast-task-base:base-1234567@sha256:" + "a" * 64
ref = {
"unpublished": None,
"bare-tag": pinned.split("@")[0],
"short-digest": pinned[:-40],
"wrong-repo": pinned.replace("norandom/ousast-task-base", "other/base"),
"valid": pinned,
}[case]
(tmp_path / "plane").mkdir()
(tmp_path / "plane/task-base.digest").write_text(json.dumps({"base": ref}))
output = tmp_path / "output"
monkeypatch.chdir(tmp_path)
monkeypatch.setenv("GITHUB_OUTPUT", str(output))
if case == "valid":
exec(compile(script, "release-pin-gate", "exec"), {})
assert output.read_text() == "base_tag=base-1234567\nbase_digest=sha256:" + "a" * 64 + "\n"
else:
with pytest.raises(SystemExit) as stopped:
exec(compile(script, "release-pin-gate", "exec"), {})
assert stopped.value.code == "base: unpublished/invalid pin; run task-base-image and update plane/task-base.digest"
assert not output.exists()
def test_base_preserves_executor_build_toolchains(): def test_base_preserves_executor_build_toolchains():
common = read("plane/Dockerfile.base").split("FROM ${TASK_BASE_REF} AS base-browser")[0] common = read("plane/Dockerfile.base").split("FROM ${TASK_BASE_REF} AS base-browser")[0]
commands = " ".join(instructions("plane/Dockerfile.base")).split("FROM ${TASK_BASE_REF} AS base-browser")[0] commands = " ".join(instructions("plane/Dockerfile.base")).split("FROM ${TASK_BASE_REF} AS base-browser")[0]