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:
1 parent
3c471b8986
commit
c3d0d7df65
7 files changed
+142
-28
No files matched your search
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user