fix(image): act on the review of the image metadata
Label parser: split the LABEL instruction like a shell (a value may hold NAME=value text), read the last stage only, require base.name and tie it to the FROM tag, require the documentation link to be <source>/src/branch/main/docs/images/<name>.md and the page to be non-empty. Docs: do not name a Python version the base may not ship, show the lint.yml pin check as it is, say which workflow paths start a build, name the system-language local hooks, add the apparmor option and the registry path to the molecule usage, and soften unverified Renovate and host-release statements. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
c3c665e799
commit
aa1848a995
8 files changed
+142
-85
No files matched your search
@@ -41,7 +41,9 @@ def labelled(name, body=""):
|
||||
"""A Dockerfile text with the labels check_image_metadata requires."""
|
||||
values = {key: "x" for key in civ.REQUIRED_LABELS}
|
||||
values["org.opencontainers.image.title"] = name
|
||||
values["org.opencontainers.image.source"] = "https://example.org"
|
||||
values["org.opencontainers.image.documentation"] = f"https://example.org/src/branch/main/docs/images/{name}.md"
|
||||
values["org.opencontainers.image.base.name"] = "ubuntu:24.04"
|
||||
return (f"FROM {JOB}\nLABEL " + " \\\n ".join(f'{k}="{v}"' for k, v in values.items()) + "\n" + body)
|
||||
|
||||
|
||||
@@ -295,38 +297,46 @@ class PureTest(unittest.TestCase):
|
||||
def test_image_metadata_labels_and_documentation(self):
|
||||
text = IMAGE_YML.format(mol="0.1.0", ci="0.2.0")
|
||||
matrix = civ.matrix_of(text)
|
||||
base = "https://git.rkdr.net/mortis/kamino/src/branch/main/docs/images"
|
||||
|
||||
def dockerfile(name, drop=(), doc=None):
|
||||
values = {key: "x" for key in civ.REQUIRED_LABELS}
|
||||
values["org.opencontainers.image.title"] = name
|
||||
values["org.opencontainers.image.documentation"] = doc or f"{base}/{name}.md"
|
||||
keys = [k for k in values if k not in drop]
|
||||
return f"FROM {JOB}\nLABEL " + " \\\n ".join(f'{k}="{values[k]}"' for k in keys) + "\n"
|
||||
|
||||
files = {"images/mol/Dockerfile": dockerfile("mol"), "images/ci/Dockerfile": dockerfile("ci")}
|
||||
have = {"docs/images/mol.md", "docs/images/ci.md"}
|
||||
files = {"images/mol/Dockerfile": labelled("mol"), "images/ci/Dockerfile": labelled("ci")}
|
||||
sizes = {"docs/images/mol.md": 5, "docs/images/ci.md": 5}
|
||||
|
||||
def check():
|
||||
return civ.check_image_metadata(matrix, lambda path: files[path], lambda path: path in have)
|
||||
return civ.check_image_metadata(matrix, lambda path: files[path], sizes.get)
|
||||
|
||||
self.assertEqual(check(), [])
|
||||
files["images/ci/Dockerfile"] = dockerfile("ci", drop=("net.rkdr.mortis.usage",))
|
||||
self.assertEqual(len(check()), 1)
|
||||
files["images/ci/Dockerfile"] = labelled("ci").replace('net.rkdr.mortis.usage="x"', 'net.rkdr.mortis.usage=""')
|
||||
self.assertIn("lacks the label(s) net.rkdr.mortis.usage", check()[0])
|
||||
files["images/ci/Dockerfile"] = dockerfile("ci", doc=f"{base}/other.md")
|
||||
self.assertIn("must link to docs/images/ci.md", check()[0])
|
||||
files["images/ci/Dockerfile"] = dockerfile("renamed")
|
||||
files["images/ci/Dockerfile"] = labelled("ci").replace("docs/images/ci.md", "docs/images/other.md")
|
||||
self.assertIn("documentation label must be", check()[0])
|
||||
files["images/ci/Dockerfile"] = labelled("ci").replace("https://example.org/src", "https://evil.example/src")
|
||||
self.assertIn("documentation label must be", check()[0])
|
||||
files["images/ci/Dockerfile"] = labelled("renamed")
|
||||
self.assertTrue(any("expected the image name" in e for e in check()))
|
||||
files["images/ci/Dockerfile"] = dockerfile("ci")
|
||||
have.discard("docs/images/ci.md")
|
||||
self.assertIn("docs/images/ci.md is missing", check()[0])
|
||||
files["images/ci/Dockerfile"] = labelled("ci").replace('base.name="ubuntu:24.04"', 'base.name="ubuntu:22.04"')
|
||||
self.assertIn("base.name label 'ubuntu:22.04' differs", check()[0])
|
||||
files["images/ci/Dockerfile"] = labelled("ci")
|
||||
sizes["docs/images/ci.md"] = 0
|
||||
self.assertIn("docs/images/ci.md is missing or empty", check()[0])
|
||||
del sizes["docs/images/ci.md"]
|
||||
self.assertIn("docs/images/ci.md is missing or empty", check()[0])
|
||||
del files["images/ci/Dockerfile"]
|
||||
sizes["docs/images/ci.md"] = 5
|
||||
with self.assertRaises(KeyError):
|
||||
check()
|
||||
|
||||
def test_dockerfile_labels_parse_like_a_shell(self):
|
||||
text = ('FROM a AS b\nLABEL builder=1\nFROM c\n'
|
||||
'LABEL one="x y=z w" two=\'q r\' \\\n three=plain\n'
|
||||
'LABEL four="PRE_COMMIT_HOME=/opt/pre-commit; done" legacy value\n')
|
||||
self.assertEqual(civ.dockerfile_labels(text),
|
||||
{"one": "x y=z w", "two": "q r", "three": "plain", "four": "PRE_COMMIT_HOME=/opt/pre-commit; done"})
|
||||
self.assertEqual(civ.dockerfile_labels('FROM c\nLABEL a="unbalanced\n'), {})
|
||||
|
||||
def test_real_dockerfiles_carry_the_metadata(self):
|
||||
root = pathlib.Path(__file__).resolve().parents[2]
|
||||
matrix = civ.matrix_of((root / civ.MATRIX_FILE).read_text())
|
||||
self.assertEqual(civ.check_image_metadata(matrix, lambda p: (root / p).read_text(),
|
||||
lambda p: (root / p).is_file()), [])
|
||||
lambda p: (root / p).stat().st_size if (root / p).is_file() else None), [])
|
||||
|
||||
def test_scripts_do_not_import_yaml(self):
|
||||
# The bump step runs in the Renovate image, whose python3 has no PyYAML (dry run 2453).
|
||||
|
||||
Reference in new issue
Block a user