fix(image): make the job container check fail closed
Molecule / molecule (pull_request) Skipped
Build / build (pull_request) Failing after 10s
Lint / lint (pull_request) Failing after 6s

Review findings: a non-ubuntu or variable FROM went unchecked, the registry-prefixed
ubuntu forms were missed, the container line could be satisfied by a lookalike in a run
block, and a quoted job_image passed the check but not the bot-diff guard or Renovate.
Also: stale ci Dockerfile base comment, the pins error now says what to edit, and the
docs state that a job_image-only bump rebuilds nothing.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
Defame1297andClaude Sonnet 5.5 committed 2026-10-26 19:03:19 +00:00
1 parent c3d0d7df65
commit bc5ae09de7
5 files changed
+77 -15

No files matched your search

+34 -11
View File
@@ -6,7 +6,7 @@
python3 scripts/check_image_versions.py bump <base-ref>
The matrix of .gitea/workflows/image.yml is the registry of images: name, version,
build context (subpath) and Dockerfile. A published version tag is never moved (Gitea
build context (subpath), Dockerfile and job container (job_image). A published version tag is never moved (Gitea
cannot make a tag immutable), so an image whose content changes under an unchanged
version is pushed as sha-*/latest only, and a hand-pasted <version>@<new digest> pin
would pair a tag with a digest it does not point to.
@@ -190,6 +190,9 @@ def matrix_of(text):
matrix[name] = {"version": values["version"], "subpath": values.get("subpath", ""),
"dockerfile": values["dockerfile"]}
if "job_image" in values:
if (keys["job_image"][0] or "").strip()[:1] in "\"'":
raise CheckError(f"{MATRIX_FILE}: image '{name}': job_image must be written unquoted "
"(the bot-diff guard and Renovate read the plain form)")
matrix[name]["job_image"] = values["job_image"]
return matrix
@@ -317,23 +320,41 @@ def check_pins(matrix, consumer_texts):
JOB_IMAGE_RE = re.compile(r"ubuntu:(?P<release>[0-9]+\.[0-9]+)@sha256:[0-9a-f]{64}")
CONTAINER_LINE_RE = re.compile(r"^\s*image:\s*\$\{\{\s*matrix\.job_image\s*\}\}\s*$", re.MULTILINE)
CONTAINER_LINE_RE = re.compile(r"^\s*container:[ \t]*\n\s*image:\s*\$\{\{\s*matrix\.job_image\s*\}\}[ \t]*$", re.MULTILINE)
UBUNTU_NAMES = ("ubuntu", "library/ubuntu", "docker.io/library/ubuntu")
def dockerfile_releases(dockerfile_text):
"""The `ubuntu:<release>` tags of the FROM lines of a Dockerfile (stage references are skipped)."""
releases = []
for unused, line in _instructions(dockerfile_text):
"""(releases, problems) of a Dockerfile's FROM lines: the `ubuntu:<release>` tag of each external
base, and a message for every FROM this check cannot vouch for. kaniko unpacks every stage over
the job container, so a base that is not Ubuntu, or whose name or tag holds a variable, is a problem.
A reference to an earlier stage (`FROM os AS final`) is skipped."""
releases, problems, stages = [], [], set()
for lineno, line in _instructions(dockerfile_text):
parts = line.split()
if not parts or parts[0].upper() != "FROM":
continue
refs = [p for p in parts[1:] if not p.startswith("--")]
if not refs:
continue
name, unused, tag = refs[0].split("@")[0].partition(":")
if name == "ubuntu":
releases.append(tag)
return releases
ref = refs[0]
if len(refs) >= 3 and refs[1].upper() == "AS":
alias = refs[2].lower()
else:
alias = None
if ref.lower() in stages:
pass
elif "$" in ref:
problems.append(f"line {lineno}: FROM {ref} holds a variable, so its release cannot be read")
else:
name, unused, tag = ref.split("@")[0].partition(":")
if name in UBUNTU_NAMES:
releases.append(tag)
else:
problems.append(f"line {lineno}: FROM {ref} is not an Ubuntu base")
if alias:
stages.add(alias)
return releases, problems
def check_job_images(matrix, read_file, workflow_text):
@@ -352,15 +373,17 @@ def check_job_images(matrix, read_file, workflow_text):
continue
path = str(pathlib.PurePosixPath(entry["subpath"]) / entry["dockerfile"]) if entry["subpath"] else entry["dockerfile"]
try:
releases = dockerfile_releases(read_file(path))
releases, problems = dockerfile_releases(read_file(path))
except OSError as exc:
errors.append(f"image '{name}': cannot read {path}: {exc}")
continue
errors += [f"image '{name}': {path} {problem}" for problem in problems]
if not releases:
errors.append(f"image '{name}': {path} has no `FROM ubuntu:<release>` line")
for release in sorted(set(releases) - {job["release"]}):
errors.append(f"image '{name}': {path} builds on ubuntu:{release} but its job_image is ubuntu:{job['release']}; "
"kaniko unpacks the image over the job container, so the two releases must be equal")
"kaniko unpacks the image over the job container, so the two releases must be equal: edit the "
f"FROM lines of {path} and job_image (tag and digest) in {MATRIX_FILE} in the same pull request")
return errors