ci(molecule): run Molecule in the molecule-controller image
Molecule ran in the ci image, so a ci pin bump for a tool only Lint uses selected every scenario (ADR 0003). The workflow now pins molecule-controller 0.1.0 by digest as CONTROLLER_IMAGE, the hand-made first pin the ADR calls for. - The run script checks /opt/molecule-pins.sha256 and installs requirements-molecule.lock when a pull request changed a pin file. - The selector reads CONTROLLER_IMAGE: a controller pin change selects every scenario; a ci pin bump touches only lint.yml and build.yml, which are on IGNORED, so it selects none. - Tests show requirements-molecule.* selects every scenario and requirements-dev.* none. - Renovate's molecule.yml regex matches CONTROLLER_IMAGE. Closes #434 Assisted-by: Claude Code
This commit is contained in:
1 parent
6e89e4d857
commit
89bd579e87
7 files changed
+58
-32
No files matched your search
@@ -11,11 +11,12 @@ name: Molecule
|
|||||||
# own workflow file. The boundaries are write access, which only trusted people have, and Gitea's
|
# 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.
|
# 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
|
# molecule runs in the pinned molecule-controller image via `docker run` with the runner's Docker
|
||||||
# scenario containers start beside it on the runner's daemon; the job tree is mounted at the same
|
# socket, so the scenario containers start beside it on the runner's daemon; the job tree is mounted
|
||||||
# path, so the paths molecule hands the daemon resolve. Like Lint and Build, it installs the pull
|
# at the same path, so the paths molecule hands the daemon resolve. Like Lint and Build, it installs
|
||||||
# request's pins when they differ from the image's. The images are pinned by tag and digest: bump
|
# the pull request's pins when they differ from the image's. The images are pinned by tag and
|
||||||
# them here when image.yml publishes a new ci, molecule-ubuntu2404 or molecule-ubuntu2604 version.
|
# digest: bump them here when image.yml publishes a new molecule-controller, molecule-ubuntu2404 or
|
||||||
|
# molecule-ubuntu2604 version.
|
||||||
on: # yamllint disable-line rule:truthy
|
on: # yamllint disable-line rule:truthy
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
@@ -57,9 +58,10 @@ jobs:
|
|||||||
# age past which the sweep step removes a run's containers; a script test holds the two equal.
|
# age past which the sweep step removes a run's containers; a script test holds the two equal.
|
||||||
timeout-minutes: 90
|
timeout-minutes: 90
|
||||||
env:
|
env:
|
||||||
# The tools and collections molecule runs with: the image Lint and Build use.
|
# The tools and collections molecule runs with, apart from Lint's (ADR 0003), so a tool
|
||||||
CI_IMAGE: >-
|
# bump only Lint uses selects no scenario.
|
||||||
git.rkdr.net/mortis/ci:0.2.48@sha256:d1c6653255abf366462c0265d9372626d5b59095084fe74ae95b9ebe7414007d
|
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
|
# Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run
|
||||||
# one locally.
|
# one locally.
|
||||||
MOLECULE_IMAGE: >-
|
MOLECULE_IMAGE: >-
|
||||||
@@ -163,7 +165,7 @@ jobs:
|
|||||||
-v "$ac_root:$ac_root" -v "$ac_root/passwd:/etc/passwd:ro" -w "$PWD" \
|
-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 "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 \
|
-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.
|
# A cancelled run can leave its containers running when the docker client is killed.
|
||||||
- name: Remove this run's containers
|
- name: Remove this run's containers
|
||||||
|
|||||||
+3
-3
@@ -79,12 +79,12 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"customType": "regex",
|
"customType": "regex",
|
||||||
"description": "The CI_IMAGE, MOLECULE_IMAGE and MOLECULE_IMAGE_<release> 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_<release> 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": [
|
"managerFilePatterns": [
|
||||||
"/^\\.gitea/workflows/molecule\\.yml$/"
|
"/^\\.gitea/workflows/molecule\\.yml$/"
|
||||||
],
|
],
|
||||||
"matchStrings": [
|
"matchStrings": [
|
||||||
"(?:CI_IMAGE|MOLECULE_IMAGE(?:_[0-9]+)?):\\s*>-\\s*\\n\\s*(?<depName>git\\.rkdr\\.net/mortis/[a-z0-9._-]+):(?<currentValue>[^@\\s]+)@(?<currentDigest>sha256:[0-9a-f]{64})"
|
"(?:CONTROLLER_IMAGE|MOLECULE_IMAGE(?:_[0-9]+)?):\\s*>-\\s*\\n\\s*(?<depName>git\\.rkdr\\.net/mortis/[a-z0-9._-]+):(?<currentValue>[^@\\s]+)@(?<currentDigest>sha256:[0-9a-f]{64})"
|
||||||
],
|
],
|
||||||
"datasourceTemplate": "docker",
|
"datasourceTemplate": "docker",
|
||||||
"versioningTemplate": "semver"
|
"versioningTemplate": "semver"
|
||||||
@@ -168,7 +168,7 @@
|
|||||||
"automerge": false
|
"automerge": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Pin follow-up for our own images (git.rkdr.net/mortis/*): moves the image:<version>@sha256:<digest> 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:<version>@sha256:<digest> 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": [
|
"matchPackageNames": [
|
||||||
"git.rkdr.net/mortis/**"
|
"git.rkdr.net/mortis/**"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# 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
|
# The Molecule workflow's run inside the molecule-controller image, from the checkout root: when a
|
||||||
# from the image's, install the pull request's pins into $AC_ROOT/pins (/opt is not writable for the
|
# pin file differs from the image's, install the pull request's pins into $AC_ROOT/pins (/opt is not
|
||||||
# runner user) and put them first, then check that the scenarios on stdin load this checkout and run
|
# writable for the runner user) and put them first, then check that the scenarios on stdin load this
|
||||||
# them. CI_BASE_PYTHON is a test seam.
|
# checkout and run them. CI_BASE_PYTHON is a test seam.
|
||||||
#
|
#
|
||||||
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
|
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -13,12 +13,12 @@ set -euo pipefail
|
|||||||
selected="$(cat)"
|
selected="$(cat)"
|
||||||
pins="$AC_ROOT/pins"
|
pins="$AC_ROOT/pins"
|
||||||
extra_collections=""
|
extra_collections=""
|
||||||
if sha256sum --quiet -c /opt/ci-pins.sha256; then
|
if sha256sum --quiet -c /opt/molecule-pins.sha256; then
|
||||||
echo "The pin files match the ci image; using the baked tools."
|
echo "The pin files match the molecule-controller image; using the baked tools."
|
||||||
else
|
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"
|
"${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"
|
export PATH="$pins/venv/bin:$PATH"
|
||||||
# The target alone on the path, so a baked copy is not taken as already installed.
|
# 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
|
for req in requirements.yml extensions/molecule/requirements.yml; do
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ label_of() {
|
|||||||
# Removes the scenario's containers by the platform names in its molecule.yml, expanded by molecule's
|
# 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
|
# 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
|
# 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.
|
# and the Docker SDK of molecule's Docker driver.
|
||||||
remove_instances() {
|
remove_instances() {
|
||||||
python3 -I - "$1/molecule.yml" <<'EOF'
|
python3 -I - "$1/molecule.yml" <<'EOF'
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ Only a pull request is narrowed, and only when <base-ref> is given and EVENT_NAM
|
|||||||
* .gitea/workflows/molecule.yml, when only comments, blank lines (both outside a block
|
* .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
|
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,
|
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
|
or every scenario when a shared molecule file names it; for CONTROLLER_IMAGE (the tools
|
||||||
runs with), every scenario. Any other change to it is "any other file";
|
molecule runs with), every scenario. Any other change to it is "any other file";
|
||||||
* any other file selects every scenario.
|
* any other file selects every scenario.
|
||||||
|
|
||||||
A role uses another when any file under its directory names it as `mortis.kamino.<other>`
|
A role uses another when any file under its directory names it as `mortis.kamino.<other>`
|
||||||
@@ -120,7 +120,7 @@ IGNORED = (
|
|||||||
WORKFLOW = ".gitea/workflows/molecule.yml"
|
WORKFLOW = ".gitea/workflows/molecule.yml"
|
||||||
# The image pins of WORKFLOW, each a `KEY: >-` line followed by its value line, in the shape
|
# The image pins of WORKFLOW, each a `KEY: >-` line followed by its value line, in the shape
|
||||||
# Renovate writes.
|
# 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(
|
PIN_VALUE = re.compile(
|
||||||
r"(\s+)git\.rkdr\.net/mortis/[a-z0-9._-]+:[^@\s]+@sha256:[0-9a-f]{64}"
|
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:
|
for path in changed:
|
||||||
if is_ignored(path):
|
if is_ignored(path):
|
||||||
continue
|
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
|
image_pins = pins
|
||||||
for pin in pins:
|
for pin in pins:
|
||||||
by_image.update(naming(all_scenarios, pin, root))
|
by_image.update(naming(all_scenarios, pin, root))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# 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
|
Run with: python3 -m unittest discover -s tests/scripts
|
||||||
"""
|
"""
|
||||||
@@ -105,7 +106,7 @@ class RunMoleculeInCiImageTest(unittest.TestCase):
|
|||||||
result = self.run_script()
|
result = self.run_script()
|
||||||
self.assertEqual(result.returncode, 0, result.stderr)
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
(check,) = self.calls("sha256sum")
|
(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("python"), [])
|
||||||
self.assertEqual(self.calls("ansible-galaxy"), [])
|
self.assertEqual(self.calls("ansible-galaxy"), [])
|
||||||
self.assertEqual(len(self.calls("ansible")), 1)
|
self.assertEqual(len(self.calls("ansible")), 1)
|
||||||
@@ -132,8 +133,8 @@ class RunMoleculeInCiImageTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
(pip,) = self.calls("pip")
|
(pip,) = self.calls("pip")
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"args=install --quiet --require-hashes -r requirements-dev.lock"
|
"args=install --quiet --require-hashes -r requirements-molecule.lock"
|
||||||
" -r requirements-dev.txt ",
|
" -r requirements-molecule.txt ",
|
||||||
pip,
|
pip,
|
||||||
)
|
)
|
||||||
galaxy = self.calls("ansible-galaxy")
|
galaxy = self.calls("ansible-galaxy")
|
||||||
|
|||||||
@@ -206,6 +206,23 @@ class SelectTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(chosen, [])
|
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):
|
def test_ignored_does_not_mask_a_role(self):
|
||||||
chosen, _reason = self.select(["docs/x.md", "roles/docker/tasks/main.yml"])
|
chosen, _reason = self.select(["docs/x.md", "roles/docker/tasks/main.yml"])
|
||||||
self.assertEqual(chosen, ["roles/docker/molecule/default"])
|
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
|
return self.pin(key).split("@sha256:")[0] + "@sha256:" + "0" * 64
|
||||||
|
|
||||||
def test_the_workflow_has_each_pin_where_the_selector_looks(self):
|
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)
|
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):
|
def test_comments_and_blank_lines_change_nothing(self):
|
||||||
self.assertEqual(self.edited("# Behavioural tests", "# Other words"), set())
|
self.assertEqual(self.edited("# Behavioural tests", "# Other words"), set())
|
||||||
self.assertEqual(self.edited("\njobs:\n", "\n\n\njobs:\n"), 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):
|
def test_comments_only_select_nothing(self):
|
||||||
self.assertEqual(self.select(set()), [])
|
self.assertEqual(self.select(set()), [])
|
||||||
|
|
||||||
def test_the_ci_image_or_no_analysis_selects_everything(self):
|
def test_the_controller_image_or_no_analysis_selects_everything(self):
|
||||||
self.assertEqual(self.select({"CI_IMAGE", "MOLECULE_IMAGE"}), ALL)
|
self.assertEqual(self.select({"CONTROLLER_IMAGE"}), ALL)
|
||||||
|
self.assertEqual(self.select({"CONTROLLER_IMAGE", "MOLECULE_IMAGE"}), ALL)
|
||||||
self.assertEqual(self.select(None), ALL)
|
self.assertEqual(self.select(None), ALL)
|
||||||
|
|
||||||
def test_pins_do_not_narrow_another_file(self):
|
def test_pins_do_not_narrow_another_file(self):
|
||||||
|
|||||||
Reference in new issue
Block a user