ci(images): add the molecule-controller image

ADR 0003 moves Molecule out of the ci image, so a ci bump for a tool
only Lint uses stops selecting every scenario. This builds and publishes
the image; nothing pins it yet (#431).

It bakes requirements-molecule.lock (ansible-core, molecule,
molecule-plugins[docker]) on the Python of .python-version and the
collections of both requirements.yml files, and records their checksums
in /opt/molecule-pins.sha256. Its last RUN checks the tool versions
against the lock, the Docker driver, every pinned collection and the
pin record, so a broken image fails its build. It has no image-smoke
scenario: it is the controller of every scenario, and the full run of
its pin pull request proves it; images/AGENTS.md records the exception.

check_image_versions.py pins now checks the Python header of both locks
and fails when their ansible-core pins differ, so Lint and Molecule
judge the code with one ansible-core. The new requirements files stay
off the selector's IGNORED list, so a bump there runs every scenario.

Refs #477

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-29 17:03:35 +00:00
1 parent 26c6026d1a
commit fd448d7e9e
9 files changed
+1199 -28

No files matched your search

+91 -7
View File
@@ -517,6 +517,20 @@ class PureTest(unittest.TestCase):
files = civ.inputs_of(entry, (root / entry["dockerfile"]).read_text())[1]
self.assertIn("extensions/molecule/requirements.yml", files)
def test_the_controller_pins_are_inputs_of_the_controller_image(self):
root = pathlib.Path(__file__).resolve().parents[2]
entry = civ.matrix_of((root / civ.MATRIX_FILE).read_text())[
"molecule-controller"
]
files = civ.inputs_of(entry, (root / entry["dockerfile"]).read_text())[1]
for pin in (
"requirements-molecule.txt",
"requirements-molecule.lock",
"requirements.yml",
"extensions/molecule/requirements.yml",
):
self.assertIn(pin, files)
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())
@@ -542,7 +556,7 @@ class PythonPinTest(unittest.TestCase):
def check(self, pin="3.13\n", lock=None, dockerfiles=None):
return civ.check_python_pin(
pin,
self.LOCK if lock is None else lock,
{"requirements-dev.lock": self.LOCK if lock is None else lock},
{"images/ci/Dockerfile": self.DOCKERFILE}
if dockerfiles is None
else dockerfiles,
@@ -563,6 +577,19 @@ class PythonPinTest(unittest.TestCase):
self.assertIn("header says Python 3.14", errors[0])
self.assertIn("lock-requirements.sh", errors[0])
def test_every_lock_header_must_match(self):
errors = civ.check_python_pin(
"3.13\n",
{
"requirements-dev.lock": self.LOCK,
"requirements-molecule.lock": self.LOCK.replace("3.13", "3.14"),
},
{"images/ci/Dockerfile": self.DOCKERFILE},
)
self.assertEqual(len(errors), 1)
self.assertTrue(errors[0].startswith("requirements-molecule.lock: header says"))
self.assertIn("lock-requirements.sh requirements-molecule.txt", errors[0])
def test_lock_without_header_is_an_error(self):
errors = self.check(lock="six==1.0 \\\n")
self.assertEqual(len(errors), 1)
@@ -614,8 +641,14 @@ class PythonPinTest(unittest.TestCase):
self.assertEqual(
civ.check_python_pin(
(root / ".python-version").read_text(),
(root / "requirements-dev.lock").read_text(),
{"images/ci/Dockerfile": (root / "images/ci/Dockerfile").read_text()},
{lock: (root / lock).read_text() for lock in civ.LOCK_FILES},
{
path: (root / path).read_text()
for path in (
"images/ci/Dockerfile",
"images/molecule-controller/Dockerfile",
)
},
),
[],
)
@@ -625,6 +658,43 @@ class PythonPinTest(unittest.TestCase):
self.assertEqual(len(errors), 1)
class AnsibleCorePinTest(unittest.TestCase):
DEV = "ansible-core==2.22.0 \\\n --hash=sha256:" + "a" * 64 + "\n"
MOL = "#\nansible-core==2.22.0 \\\n # via -r requirements-molecule.txt\n"
def check(self, dev=None, mol=None):
return civ.check_ansible_core_pins(
{
"requirements-dev.lock": self.DEV if dev is None else dev,
"requirements-molecule.lock": self.MOL if mol is None else mol,
}
)
def test_equal_pins_pass(self):
self.assertEqual(self.check(), [])
def test_differing_pins_fail(self):
errors = self.check(mol=self.MOL.replace("2.22.0", "2.21.3"))
self.assertEqual(len(errors), 1)
self.assertIn("2.22.0", errors[0])
self.assertIn("2.21.3", errors[0])
self.assertIn("requirements-molecule.lock", errors[0])
def test_a_lock_without_ansible_core_fails(self):
errors = self.check(dev="reuse==6.3.0 \\\n")
self.assertEqual(len(errors), 1)
self.assertIn("requirements-dev.lock: no ansible-core==", errors[0])
def test_the_committed_locks_agree(self):
root = pathlib.Path(__file__).resolve().parents[2]
self.assertEqual(
civ.check_ansible_core_pins(
{lock: (root / lock).read_text() for lock in civ.LOCK_FILES}
),
[],
)
class GitTest(unittest.TestCase):
"""Run the script as CI does, in a throwaway repository."""
@@ -643,10 +713,12 @@ class GitTest(unittest.TestCase):
),
)
self.write(".python-version", "3.13\n")
self.write(
"requirements-dev.lock",
"# This file is autogenerated by pip-compile with Python 3.13\n",
)
for lock in civ.LOCK_FILES:
self.write(
lock,
"# This file is autogenerated by pip-compile with Python 3.13\n"
"ansible-core==2.22.0 \\\n",
)
self.write("images/mol/Dockerfile", labelled("mol"))
self.write("docs/images/ci.md", "ci\n")
self.write("docs/images/mol.md", "mol\n")
@@ -692,6 +764,18 @@ class GitTest(unittest.TestCase):
self.assertEqual(code, 1)
self.assertIn("other.yaml: mentions git.rkdr.net/defame1297/", err)
def test_pins_cli_fails_when_the_locks_pin_different_ansible_core(self):
self.write(".gitea/workflows/lint.yml", "name: Lint\n")
self.assertEqual(self.script("pins")[0], 0)
self.write(
"requirements-molecule.lock",
"# This file is autogenerated by pip-compile with Python 3.13\n"
"ansible-core==2.21.3 \\\n",
)
self.assert_clean_failure(
self.script("pins"), "the locks pin different ansible-core versions"
)
def test_bump_mode_is_gone(self):
self.write(".gitea/workflows/lint.yml", "name: Lint\n")
self.assertEqual(self.script("bump", "main")[0], 2)