diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 467f866..407ea5b 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -11,11 +11,12 @@ name: Molecule # own workflow file. The boundaries are write access, which only trusted people have, and Gitea's # approval gate on fork runs, which the fork rule in docs/contributing/reviewing.md keeps shut. # -# molecule runs in the pinned ci image via `docker run` with the runner's Docker socket, so the -# scenario containers start beside it on the runner's daemon; the job tree is mounted at the same -# path, so the paths molecule hands the daemon resolve. Like Lint and Build, it installs the pull -# request's pins when they differ from the image's. The images are pinned by tag and digest: bump -# them here when image.yml publishes a new ci, molecule-ubuntu2404 or molecule-ubuntu2604 version. +# molecule runs in the pinned molecule-controller image via `docker run` with the runner's Docker +# socket, so the scenario containers start beside it on the runner's daemon; the job tree is mounted +# at the same path, so the paths molecule hands the daemon resolve. Like Lint and Build, it installs +# the pull request's pins when they differ from the image's. The images are pinned by tag and +# digest: bump them here when image.yml publishes a new molecule-controller, molecule-ubuntu2404 or +# molecule-ubuntu2604 version. on: # yamllint disable-line rule:truthy pull_request: branches: @@ -57,9 +58,10 @@ jobs: # age past which the sweep step removes a run's containers; a script test holds the two equal. timeout-minutes: 90 env: - # The tools and collections molecule runs with: the image Lint and Build use. - CI_IMAGE: >- - git.rkdr.net/mortis/ci:0.2.48@sha256:d1c6653255abf366462c0265d9372626d5b59095084fe74ae95b9ebe7414007d + # The tools and collections molecule runs with, apart from Lint's (ADR 0003), so a tool + # bump only Lint uses selects no scenario. + CONTROLLER_IMAGE: >- + git.rkdr.net/mortis/molecule-controller:0.1.0@sha256:d4ab16d58851eead751c8f0bada8edd76c9e5dcd5c2acaa1ac93c5f6035b29e2 # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run # one locally. MOLECULE_IMAGE: >- @@ -163,7 +165,7 @@ jobs: -v "$ac_root:$ac_root" -v "$ac_root/passwd:/etc/passwd:ro" -w "$PWD" \ -e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \ -e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 -e KAMINO_RUN_ID -e MOLECULE_LANES \ - "$CI_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$selected" + "$CONTROLLER_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$selected" # A cancelled run can leave its containers running when the docker client is killed. - name: Remove this run's containers diff --git a/renovate.json b/renovate.json index 4d851f9..1f3e705 100644 --- a/renovate.json +++ b/renovate.json @@ -79,12 +79,12 @@ }, { "customType": "regex", - "description": "The CI_IMAGE, MOLECULE_IMAGE and MOLECULE_IMAGE_ values of molecule.yml are a multi-line `>-` scalar, which the github-actions manager does not read; matched here by its exact shape. Used by the pin-follow rule below.", + "description": "The CONTROLLER_IMAGE (molecule-controller), MOLECULE_IMAGE and MOLECULE_IMAGE_ values of molecule.yml are a multi-line `>-` scalar, which the github-actions manager does not read; matched here by its exact shape. Used by the pin-follow rule below.", "managerFilePatterns": [ "/^\\.gitea/workflows/molecule\\.yml$/" ], "matchStrings": [ - "(?:CI_IMAGE|MOLECULE_IMAGE(?:_[0-9]+)?):\\s*>-\\s*\\n\\s*(?git\\.rkdr\\.net/mortis/[a-z0-9._-]+):(?[^@\\s]+)@(?sha256:[0-9a-f]{64})" + "(?:CONTROLLER_IMAGE|MOLECULE_IMAGE(?:_[0-9]+)?):\\s*>-\\s*\\n\\s*(?git\\.rkdr\\.net/mortis/[a-z0-9._-]+):(?[^@\\s]+)@(?sha256:[0-9a-f]{64})" ], "datasourceTemplate": "docker", "versioningTemplate": "semver" @@ -168,7 +168,7 @@ "automerge": false }, { - "description": "Pin follow-up for our own images (git.rkdr.net/mortis/*): moves the image:@sha256: pins of lint.yml, build.yml, molecule.yml and gitea-release-key.yml to the newest published version and its digest, and automerges. The Images workflow's completion starts a Renovate run, so this pull request opens minutes after a new version is pushed. The pull request's own Lint and Build run in the new image before the merge, and scripts/check_bot_pr_diff.py allows only these pin lines. The registry lists tags and digests anonymously, so no hostRules are needed. A major version stays manual (rule above). One pull request moves every image an Images run published (ci and both molecule images), so one Molecule run tests them together. Exempt from the weekly schedule, so the pins on main catch up with a new image within minutes.", + "description": "Pin follow-up for our own images (git.rkdr.net/mortis/*): moves the image:@sha256: pins of lint.yml, build.yml, molecule.yml and gitea-release-key.yml to the newest published version and its digest, and automerges. The Images workflow's completion starts a Renovate run, so this pull request opens minutes after a new version is pushed. The pull request's own Lint and Build run in the new image before the merge, and scripts/check_bot_pr_diff.py allows only these pin lines. The registry lists tags and digests anonymously, so no hostRules are needed. A major version stays manual (rule above). One pull request moves every image an Images run published (ci, molecule-controller and both molecule target images), so one Molecule run tests them together. Exempt from the weekly schedule, so the pins on main catch up with a new image within minutes.", "matchPackageNames": [ "git.rkdr.net/mortis/**" ], diff --git a/scripts/run_molecule_in_ci_image.sh b/scripts/run_molecule_in_ci_image.sh index 4de5037..b246634 100755 --- a/scripts/run_molecule_in_ci_image.sh +++ b/scripts/run_molecule_in_ci_image.sh @@ -2,10 +2,10 @@ # SPDX-FileCopyrightText: Defame1297 and contributors # SPDX-License-Identifier: GPL-3.0-or-later # -# The Molecule workflow's run inside the ci image, from the checkout root: when a pin file differs -# from the image's, install the pull request's pins into $AC_ROOT/pins (/opt is not writable for the -# runner user) and put them first, then check that the scenarios on stdin load this checkout and run -# them. CI_BASE_PYTHON is a test seam. +# The Molecule workflow's run inside the molecule-controller image, from the checkout root: when a +# pin file differs from the image's, install the pull request's pins into $AC_ROOT/pins (/opt is not +# writable for the runner user) and put them first, then check that the scenarios on stdin load this +# checkout and run them. CI_BASE_PYTHON is a test seam. # # AC_ROOT= scripts/run_molecule_in_ci_image.sh < scenario-dirs set -euo pipefail @@ -13,12 +13,12 @@ set -euo pipefail selected="$(cat)" pins="$AC_ROOT/pins" extra_collections="" -if sha256sum --quiet -c /opt/ci-pins.sha256; then - echo "The pin files match the ci image; using the baked tools." +if sha256sum --quiet -c /opt/molecule-pins.sha256; then + echo "The pin files match the molecule-controller image; using the baked tools." else - echo "::warning::a pin file differs from the ci image; installing the pinned tools and collections for this run." + echo "::warning::a pin file differs from the molecule-controller image; installing the pinned tools and collections for this run." "${CI_BASE_PYTHON:-/opt/venv/bin/python}" -m venv "$pins/venv" - "$pins/venv/bin/pip" install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt + "$pins/venv/bin/pip" install --quiet --require-hashes -r requirements-molecule.lock -r requirements-molecule.txt export PATH="$pins/venv/bin:$PATH" # The target alone on the path, so a baked copy is not taken as already installed. for req in requirements.yml extensions/molecule/requirements.yml; do diff --git a/scripts/run_molecule_scenarios.sh b/scripts/run_molecule_scenarios.sh index 249faf6..3b4e9ca 100755 --- a/scripts/run_molecule_scenarios.sh +++ b/scripts/run_molecule_scenarios.sh @@ -39,7 +39,7 @@ label_of() { # Removes the scenario's containers by the platform names in its molecule.yml, expanded by molecule's # interpolator, in place of molecule's destroy, which the scenarios leave out: its driver waits about # 5.6 s per scenario for the deletion (about 84 s over 15), and the whole destroy phase measured about -# 103 s a full run. The ci image has no docker CLI: python3 is the one molecule runs on, with PyYAML +# 103 s a full run. The controller image has no docker CLI: python3 is the one molecule runs on, with PyYAML # and the Docker SDK of molecule's Docker driver. remove_instances() { python3 -I - "$1/molecule.yml" <<'EOF' diff --git a/scripts/select_molecule_scenarios.py b/scripts/select_molecule_scenarios.py index 1562d13..c96f780 100644 --- a/scripts/select_molecule_scenarios.py +++ b/scripts/select_molecule_scenarios.py @@ -21,8 +21,8 @@ Only a pull request is narrowed, and only when is given and EVENT_NAM * .gitea/workflows/molecule.yml, when only comments, blank lines (both outside a block scalar such as `run: |`) or the image pins changed: nothing for comments; for MOLECULE_IMAGE or MOLECULE_IMAGE_2604, every scenario whose directory names that variable, - or every scenario when a shared molecule file names it; for CI_IMAGE (the tools molecule - runs with), every scenario. Any other change to it is "any other file"; + or every scenario when a shared molecule file names it; for CONTROLLER_IMAGE (the tools + molecule runs with), every scenario. Any other change to it is "any other file"; * any other file selects every scenario. A role uses another when any file under its directory names it as `mortis.kamino.` @@ -120,7 +120,7 @@ IGNORED = ( WORKFLOW = ".gitea/workflows/molecule.yml" # The image pins of WORKFLOW, each a `KEY: >-` line followed by its value line, in the shape # Renovate writes. -PIN_KEY = re.compile(r"(\s+)(CI_IMAGE|MOLECULE_IMAGE|MOLECULE_IMAGE_2604): >-") +PIN_KEY = re.compile(r"(\s+)(CONTROLLER_IMAGE|MOLECULE_IMAGE|MOLECULE_IMAGE_2604): >-") PIN_VALUE = re.compile( r"(\s+)git\.rkdr\.net/mortis/[a-z0-9._-]+:[^@\s]+@sha256:[0-9a-f]{64}" ) @@ -331,7 +331,7 @@ def select(all_scenarios, changed, root=".", pins=None): for path in changed: if is_ignored(path): continue - if path == WORKFLOW and pins is not None and "CI_IMAGE" not in pins: + if path == WORKFLOW and pins is not None and "CONTROLLER_IMAGE" not in pins: image_pins = pins for pin in pins: by_image.update(naming(all_scenarios, pin, root)) diff --git a/tests/scripts/test_run_molecule_in_ci_image.py b/tests/scripts/test_run_molecule_in_ci_image.py index ca7f4b2..a77bace 100644 --- a/tests/scripts/test_run_molecule_in_ci_image.py +++ b/tests/scripts/test_run_molecule_in_ci_image.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: Defame1297 and contributors # SPDX-License-Identifier: GPL-3.0-or-later -"""Tests for scripts/run_molecule_in_ci_image.sh with stub tools in place of the ci image's. +"""Tests for scripts/run_molecule_in_ci_image.sh with stub tools in place of the molecule-controller +image's. Run with: python3 -m unittest discover -s tests/scripts """ @@ -105,7 +106,7 @@ class RunMoleculeInCiImageTest(unittest.TestCase): result = self.run_script() self.assertEqual(result.returncode, 0, result.stderr) (check,) = self.calls("sha256sum") - self.assertIn("args=--quiet -c /opt/ci-pins.sha256 ", check) + self.assertIn("args=--quiet -c /opt/molecule-pins.sha256 ", check) self.assertEqual(self.calls("python"), []) self.assertEqual(self.calls("ansible-galaxy"), []) self.assertEqual(len(self.calls("ansible")), 1) @@ -132,8 +133,8 @@ class RunMoleculeInCiImageTest(unittest.TestCase): ) (pip,) = self.calls("pip") self.assertIn( - "args=install --quiet --require-hashes -r requirements-dev.lock" - " -r requirements-dev.txt ", + "args=install --quiet --require-hashes -r requirements-molecule.lock" + " -r requirements-molecule.txt ", pip, ) galaxy = self.calls("ansible-galaxy") diff --git a/tests/scripts/test_select_molecule_scenarios.py b/tests/scripts/test_select_molecule_scenarios.py index f7f7808..eec4106 100644 --- a/tests/scripts/test_select_molecule_scenarios.py +++ b/tests/scripts/test_select_molecule_scenarios.py @@ -206,6 +206,23 @@ class SelectTest(unittest.TestCase): ) self.assertEqual(chosen, []) + def test_a_ci_pin_bump_in_lint_or_build_selects_nothing(self): + chosen, _reason = self.select( + [".gitea/workflows/lint.yml", ".gitea/workflows/build.yml"] + ) + self.assertEqual(chosen, []) + + def test_lint_requirements_select_nothing(self): + # requirements-dev.* pin Lint's tools; Molecule's come from requirements-molecule.*. + chosen, _reason = self.select(["requirements-dev.txt", "requirements-dev.lock"]) + self.assertEqual(chosen, []) + + def test_molecule_requirements_select_everything(self): + # An ansible-core or molecule bump there changes the tools every scenario runs with. + for path in ("requirements-molecule.txt", "requirements-molecule.lock"): + chosen, _reason = self.select([path]) + self.assertEqual(chosen, ALL, path) + def test_ignored_does_not_mask_a_role(self): chosen, _reason = self.select(["docs/x.md", "roles/docker/tasks/main.yml"]) self.assertEqual(chosen, ["roles/docker/molecule/default"]) @@ -660,9 +677,14 @@ class WorkflowPinsTest(unittest.TestCase): return self.pin(key).split("@sha256:")[0] + "@sha256:" + "0" * 64 def test_the_workflow_has_each_pin_where_the_selector_looks(self): - for key in ("CI_IMAGE", "MOLECULE_IMAGE", "MOLECULE_IMAGE_2604"): + for key in ("CONTROLLER_IMAGE", "MOLECULE_IMAGE", "MOLECULE_IMAGE_2604"): self.assertEqual(self.edited(self.pin(key), self.bumped(key)), {key}, key) + def test_the_workflow_runs_in_the_controller_image_not_ci(self): + # A ci pin bump must touch only Lint and Build, which IGNORED lists (ADR 0003). + self.assertIn("/mortis/molecule-controller:", self.pin("CONTROLLER_IMAGE")) + self.assertNotIn("/mortis/ci:", self.WORKFLOW) + def test_comments_and_blank_lines_change_nothing(self): self.assertEqual(self.edited("# Behavioural tests", "# Other words"), set()) self.assertEqual(self.edited("\njobs:\n", "\n\n\njobs:\n"), set()) @@ -772,8 +794,9 @@ class SelectByPinTest(unittest.TestCase): def test_comments_only_select_nothing(self): self.assertEqual(self.select(set()), []) - def test_the_ci_image_or_no_analysis_selects_everything(self): - self.assertEqual(self.select({"CI_IMAGE", "MOLECULE_IMAGE"}), ALL) + def test_the_controller_image_or_no_analysis_selects_everything(self): + self.assertEqual(self.select({"CONTROLLER_IMAGE"}), ALL) + self.assertEqual(self.select({"CONTROLLER_IMAGE", "MOLECULE_IMAGE"}), ALL) self.assertEqual(self.select(None), ALL) def test_pins_do_not_narrow_another_file(self):