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:
1 parent
26c6026d1a
commit
fd448d7e9e
9 files changed
+1199
-28
No files matched your search
@@ -386,6 +386,10 @@ def check_pins(matrix, consumer_texts):
|
||||
|
||||
PYTHON_PIN_FILE = ".python-version"
|
||||
LOCK_FILE = "requirements-dev.lock"
|
||||
# The molecule-controller image's lock (ADR 0003).
|
||||
MOLECULE_LOCK_FILE = "requirements-molecule.lock"
|
||||
LOCK_FILES = (LOCK_FILE, MOLECULE_LOCK_FILE)
|
||||
ANSIBLE_CORE_RE = re.compile(r"^ansible-core==([^\s;\\]+)", re.MULTILINE)
|
||||
PYTHON_PIN_RE = re.compile(r"[0-9]+\.[0-9]+")
|
||||
LOCK_PYTHON_RE = re.compile(
|
||||
r"^# This file is autogenerated by pip-compile with Python ([0-9]+\.[0-9]+)\s*$",
|
||||
@@ -397,25 +401,27 @@ ARG_PYTHON_RE = re.compile(
|
||||
)
|
||||
|
||||
|
||||
def check_python_pin(pin_text, lock_text, dockerfiles):
|
||||
"""Errors where the Python of .python-version, the header of requirements-dev.lock and the
|
||||
def check_python_pin(pin_text, locks, dockerfiles):
|
||||
"""Errors where the Python of .python-version, the header of each lock (path -> text) and the
|
||||
`ARG PYTHON_VERSION=` of an image Dockerfile (path -> text) are not one MAJOR.MINOR version. A
|
||||
clone's virtualenv (scripts/dev-setup.sh) and the ci image's /opt/venv use the first, the lock
|
||||
records the third as the interpreter it was resolved on; at least one Dockerfile must carry the ARG."""
|
||||
clone's virtualenv (scripts/dev-setup.sh) and the images' /opt/venv use the first, a lock
|
||||
records it as the interpreter it was resolved on; at least one Dockerfile must carry the ARG."""
|
||||
pin = pin_text.strip()
|
||||
if not PYTHON_PIN_RE.fullmatch(pin):
|
||||
return [f"{PYTHON_PIN_FILE} must hold one MAJOR.MINOR version, found {pin!r}"]
|
||||
errors = []
|
||||
header = LOCK_PYTHON_RE.search(lock_text)
|
||||
if not header:
|
||||
errors.append(
|
||||
f"{LOCK_FILE}: no 'autogenerated by pip-compile with Python X.Y' header"
|
||||
)
|
||||
elif header.group(1) != pin:
|
||||
errors.append(
|
||||
f"{LOCK_FILE}: header says Python {header.group(1)} but {PYTHON_PIN_FILE} is {pin}; "
|
||||
"regenerate it with scripts/lock-requirements.sh"
|
||||
)
|
||||
for path, lock_text in locks.items():
|
||||
header = LOCK_PYTHON_RE.search(lock_text)
|
||||
if not header:
|
||||
errors.append(
|
||||
f"{path}: no 'autogenerated by pip-compile with Python X.Y' header"
|
||||
)
|
||||
elif header.group(1) != pin:
|
||||
requirements = path.removesuffix(".lock") + ".txt"
|
||||
errors.append(
|
||||
f"{path}: header says Python {header.group(1)} but {PYTHON_PIN_FILE} is {pin}; "
|
||||
f"regenerate it with scripts/lock-requirements.sh {requirements}"
|
||||
)
|
||||
carriers = 0
|
||||
for path, text in dockerfiles.items():
|
||||
for arg in ARG_PYTHON_RE.findall(text):
|
||||
@@ -431,6 +437,25 @@ def check_python_pin(pin_text, lock_text, dockerfiles):
|
||||
return errors
|
||||
|
||||
|
||||
def check_ansible_core_pins(locks):
|
||||
"""Errors where the locks (path -> text) do not pin one ansible-core version: Lint runs the one of
|
||||
requirements-dev.lock and Molecule the one of requirements-molecule.lock, and both judge the same code."""
|
||||
errors, versions = [], {}
|
||||
for path, text in locks.items():
|
||||
m = ANSIBLE_CORE_RE.search(text)
|
||||
if m:
|
||||
versions[path] = m[1]
|
||||
else:
|
||||
errors.append(f"{path}: no ansible-core== entry")
|
||||
if len(set(versions.values())) > 1:
|
||||
pins = ", ".join(f"{path} {version}" for path, version in versions.items())
|
||||
errors.append(
|
||||
f"the locks pin different ansible-core versions ({pins}); Lint and Molecule must run one "
|
||||
"ansible-core, so move both pins in the same pull request"
|
||||
)
|
||||
return errors
|
||||
|
||||
|
||||
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*container:[ \t]*\n\s*image:\s*\$\{\{\s*matrix\.job_image\s*\}\}[ \t]*$",
|
||||
@@ -671,11 +696,11 @@ def run(argv):
|
||||
if pathlib.Path(path).exists():
|
||||
dockerfiles[path] = pathlib.Path(path).read_text()
|
||||
try:
|
||||
locks = {lock: pathlib.Path(lock).read_text() for lock in LOCK_FILES}
|
||||
errors += check_python_pin(
|
||||
pathlib.Path(PYTHON_PIN_FILE).read_text(),
|
||||
pathlib.Path(LOCK_FILE).read_text(),
|
||||
dockerfiles,
|
||||
pathlib.Path(PYTHON_PIN_FILE).read_text(), locks, dockerfiles
|
||||
)
|
||||
errors += check_ansible_core_pins(locks)
|
||||
except OSError as exc:
|
||||
errors.append(f"cannot read the Python pin files: {exc}")
|
||||
workflows = (
|
||||
|
||||
Reference in new issue
Block a user