From 2e32016c43698e2a11d9bcb8e20bb85eddb0c195 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Tue, 24 Nov 2026 07:14:19 +0000 Subject: [PATCH] ci(molecule): run Molecule from the ci image instead of the runner's venv Pin molecule and its Docker driver in requirements-dev.txt and bake them, with the driver's collection, into the ci image. The Molecule job runs docker run on the pinned ci image with the Docker socket and the checkout mounted at the same path, as the runner user. A pull request whose pins differ from the image installs its own pins first, so a core bump runs its scenarios on the new core. gitea_runner no longer installs the molecule venv and collections. Closes #225 Assisted-by: Claude Code --- .gitea/workflows/AGENTS.md | 9 +- .gitea/workflows/image.yml | 1 + .gitea/workflows/molecule.yml | 111 ++++++++++-------- .../gitea-runner-molecule-tooling-removed.yml | 13 ++ docs/images/ci.md | 26 ++-- docs/images/molecule-ubuntu2404.md | 4 +- docs/images/molecule-ubuntu2604.md | 4 +- extensions/molecule/requirements.yml | 8 +- images/ci/Dockerfile | 31 +++-- renovate.json | 4 +- requirements-dev.lock | 46 +++++++- requirements-dev.txt | 4 +- requirements.yml | 4 +- roles/gitea_runner/README.md | 12 +- roles/gitea_runner/defaults/main.yml | 17 +-- roles/gitea_runner/meta/argument_specs.yml | 50 ++------ roles/gitea_runner/meta/main.yml | 2 +- .../molecule/default/tasks/refused_input.yml | 1 - .../gitea_runner/molecule/default/verify.yml | 3 - roles/gitea_runner/tasks/main.yml | 2 +- roles/gitea_runner/tasks/molecule.yml | 82 +------------ roles/gitea_runner/tasks/validate.yml | 11 -- scripts/run_molecule_scenarios.sh | 26 ++-- tests/scripts/test_check_image_versions.py | 6 + tests/scripts/test_run_molecule_scenarios.py | 90 +++++++++++--- 25 files changed, 292 insertions(+), 275 deletions(-) create mode 100644 changelogs/fragments/gitea-runner-molecule-tooling-removed.yml diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index 729f7f7..d85349c 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -90,10 +90,11 @@ issue. names first (#166). *Why:* a cancelled run is killed before it can remove its instances, and two overlapping scenarios or runs would collide on the same names. *Held:* review; that no two scenarios share a platform name is held by the test the `test_sequence` rule below names. -- **Molecule tests the pull request's pins, as Lint and Build do.** *Why:* the pull request that - raises the ansible-core floor must be behaviour-tested on the new core before it automerges. - *Held:* aspirational until #225 runs Molecule from the `ci` image with the pin comparison - against `/opt/ci-pins.sha256`; today it runs from the runner's own venv. +- **Molecule tests the pull request's pins, as Lint and Build do.** It runs molecule in the pinned + `ci` image and, when a pin file differs from `/opt/ci-pins.sha256`, installs the pull request's + tools and the collections of `requirements.yml` and `extensions/molecule/requirements.yml` first. + *Why:* a pull request that raises the ansible-core floor must run its scenarios on the new core + before it automerges. *Held:* control: the pin comparison in `molecule.yml`. - **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy` steps, and names its platforms literally in its `molecule.yml`;** copy it into a new scenario. *Why:* the workflow clears stale containers first and removes each scenario's containers by diff --git a/.gitea/workflows/image.yml b/.gitea/workflows/image.yml index 482004b..e7eb749 100644 --- a/.gitea/workflows/image.yml +++ b/.gitea/workflows/image.yml @@ -42,6 +42,7 @@ on: # yamllint disable-line rule:truthy - 'requirements-dev.txt' - 'requirements-dev.lock' - 'requirements.yml' + - 'extensions/molecule/requirements.yml' - '.pre-commit-config.yaml' - '.gitea/workflows/image.yml' workflow_dispatch: {} diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index f4a022c..cd7afc7 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -11,12 +11,12 @@ name: Molecule # own workflow file. So the repository does not accept fork pull requests; the real # condition is that only trusted people can push branches or open pull requests here. # -# The molecule venv is provisioned on the runner, not by this workflow. The collections -# the roles use are this repository's own pins (requirements.yml, the file the ci image bakes -# for Lint), and the driver's own collection is pinned in extensions/molecule/requirements.yml: -# the job installs both, cached on the runner by their checksum. The test image is pulled from -# the registry by tag and digest (the digest is what is enforced). Bump both here when -# image.yml publishes a new molecule-ubuntu2404 or molecule-ubuntu2604 version. +# molecule runs in the pinned ci image, started with `docker run` and the runner's Docker socket, +# so the scenario containers it creates run beside it on the runner's daemon; the job tree is +# mounted at the same path, so paths molecule hands the daemon resolve. Like Lint and Build, the +# job compares the pin files with the image and installs the pull request's pins when they differ. +# The test images are pulled by tag and digest (the digest is what is enforced). Bump both here +# when image.yml publishes a new ci, molecule-ubuntu2404 or molecule-ubuntu2604 version. on: # yamllint disable-line rule:truthy pull_request: branches: @@ -33,7 +33,7 @@ on: # yamllint disable-line rule:truthy - 'requirements.yml' - '.gitea/workflows/molecule.yml' # Every scenario, nightly: a pull request runs only the scenarios of the roles it changes, so - # drift in the others (a package mirror, the runner's molecule venv) would otherwise wait for + # drift in the others (a package mirror) would otherwise wait for # the next push to main. After Renovate's 03:17 run, which can take 30 minutes of the one slot. schedule: - cron: "43 4 * * *" @@ -66,7 +66,9 @@ jobs: runs-on: [kamino-molecule] timeout-minutes: 30 env: - MOLECULE_VENV: /opt/molecule-venv + # The tools and collections molecule runs with: the image Lint and Build use. + CI_IMAGE: >- + git.rkdr.net/mortis/ci:0.2.39@sha256:61c25c2c6ad83361e596175bd4fa76141c6a910d27bbb7fc6692f752fdbd29ef # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run # one locally. MOLECULE_IMAGE: >- @@ -75,15 +77,11 @@ jobs: # `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604. MOLECULE_IMAGE_2604: >- git.rkdr.net/mortis/molecule-ubuntu2604:0.1.6@sha256:d7c216b33d18fa8f1ecbfee8795eb4adc867fe5ad8e7a73b7c67effe301cf771 + # The container molecule runs in, named by the run so the cleanup step finds it. + RUN_CONTAINER: kamino-molecule-${{ github.run_id }}-${{ github.run_attempt }} steps: - # The molecule venv is provisioned on the runner, not by this job; fail with a clear - # message when it is missing. - - name: Check the provisioned tooling + - name: Check the Docker daemon run: | - if ! test -x "$MOLECULE_VENV/bin/molecule"; then - echo "::error::molecule is not installed on this runner: provision its molecule venv first" - exit 1 - fi docker version --format '{{.Server.Version}}' || { echo "::error::the Docker daemon is not reachable by the runner user"; exit 1; } # The Collection must sit at ansible_collections/mortis/kamino for FQCNs to resolve. @@ -104,29 +102,6 @@ jobs: git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; } echo "Checked out $(git rev-parse HEAD)" - # The collections of requirements.yml (what the roles call) and extensions/molecule/requirements.yml - # (what molecule's Docker driver calls), exactly as pinned. They are installed into a temporary - # directory and renamed into place, so a cancelled run never leaves a half-installed set, and - # the directory is named by the checksum of both files, so a changed pin installs a new set and - # an unchanged one is reused. ANSIBLE_COLLECTIONS_PATH is set to the target for the install: - # a copy found elsewhere (the runner user's ~/.ansible) would be skipped as already installed. - - name: Install the pinned collections - working-directory: ac/ansible_collections/mortis/kamino - run: | - export PATH="$MOLECULE_VENV/bin:$PATH" - sum="$(cat requirements.yml extensions/molecule/requirements.yml | sha256sum | cut -c1-16)" - dest="${XDG_CACHE_HOME:-$HOME/.cache}/kamino-collections/$sum" - if [ ! -d "$dest/ansible_collections" ]; then - mkdir -p "$(dirname "$dest")" - tmp="$(mktemp -d "$dest.XXXXXX")" - ANSIBLE_COLLECTIONS_PATH="$tmp" ansible-galaxy collection install -r requirements.yml -p "$tmp" - ANSIBLE_COLLECTIONS_PATH="$tmp" ansible-galaxy collection install -r extensions/molecule/requirements.yml -p "$tmp" - rm -rf "$dest" - mv -T "$tmp" "$dest" - fi - ANSIBLE_COLLECTIONS_PATH="$dest" ansible-galaxy collection list - echo "KAMINO_COLLECTIONS=$dest" >> "$GITHUB_ENV" - # A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py # explains the rules); a push to main and a manual dispatch run all of them, a few at a time. # scripts/run_molecule_scenarios.sh runs them and removes each scenario's containers as soon as @@ -145,16 +120,6 @@ jobs: # shellcheck disable=SC2086 # container ids, one word each docker rm -f $stale fi - # molecule calls ansible-config and ansible-playbook by name - export PATH="$MOLECULE_VENV/bin:$PATH" - # The collection under test first, then the pinned collections the roles use. molecule also - # installs the collection under test into ANSIBLE_HOME, which the run script gives each - # scenario inside the job tree, so no run resolves a copy another run left in the runner - # user's home (the version stays 0.1.0, so a stale copy would look current). The rm - # clears a copy left there by runs before this was set. - ac_root="$(cd ../../.. && pwd)" - export ANSIBLE_COLLECTIONS_PATH="$ac_root:$KAMINO_COLLECTIONS" - rm -rf "$HOME/.ansible/collections/ansible_collections/mortis" # The selector comes from the base branch, so a pull request cannot edit the rules it is # judged by (lint.yml does the same for check_bot_pr_diff.py); the first pull request that # adds it has no base copy yet and uses its own. @@ -168,4 +133,52 @@ jobs: echo "::notice::no base copy of $sel; running this checkout's copy" fi selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1 - scripts/run_molecule_scenarios.sh "$ac_root/molecule-runs" <<< "$selected" + + # As the runner user, with the socket's group, so nothing in the job tree is left + # root-owned; HOME (ansible's temp and caches) is in the job tree too. The user has no + # passwd entry in the image, so USER names it. + ac_root="$(cd ../../.. && pwd)" + sock_gid="$(stat -c %g /var/run/docker.sock)" + mkdir -p "$ac_root/home" + docker run --rm -i --init --name "$RUN_CONTAINER" \ + --user "$(id -u):$(id -g)" --group-add "$sock_gid" \ + -v /var/run/docker.sock:/var/run/docker.sock -v "$ac_root:$ac_root" -w "$PWD" \ + -e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \ + -e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 \ + "$CI_IMAGE" bash -c "$(cat <<'EOF' + set -euo pipefail + selected="$(cat)" + # The pull request's own pins when they differ from the image's. /opt is not writable for + # this user, so they go to the job tree, first on the paths. + pins="$AC_ROOT/pins" + collections="" + if sha256sum --quiet -c /opt/ci-pins.sha256; then + echo "The pin files match the ci 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." + /opt/venv/bin/python -m venv "$pins/venv" + "$pins/venv/bin/pip" install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.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 + ANSIBLE_COLLECTIONS_PATH="$pins/collections" \ + ansible-galaxy collection install --force -r "$req" -p "$pins/collections" + done + collections="$pins/collections:" + fi + ansible --version + molecule --version + # The collection under test first; molecule also installs it into each scenario's + # ANSIBLE_HOME, which the run script keeps in the job tree. + export ANSIBLE_COLLECTIONS_PATH="$AC_ROOT:$collections/opt/collections" + exec scripts/run_molecule_scenarios.sh "$AC_ROOT/molecule-runs" <<< "$selected" + EOF + )" <<< "$selected" + + # A cancelled run can leave the container running when the docker client is killed. + - name: Remove the molecule container + if: always() + run: | + if docker container inspect "$RUN_CONTAINER" >/dev/null 2>&1; then + docker rm -f "$RUN_CONTAINER" + fi diff --git a/changelogs/fragments/gitea-runner-molecule-tooling-removed.yml b/changelogs/fragments/gitea-runner-molecule-tooling-removed.yml new file mode 100644 index 0000000..6eca460 --- /dev/null +++ b/changelogs/fragments/gitea-runner-molecule-tooling-removed.yml @@ -0,0 +1,13 @@ +--- +breaking_changes: + - >- + gitea_runner - With ``gitea_runner_molecule_enabled`` the role no longer installs molecule tooling or collections: a job on + the ``:host`` label brings its own toolchain in an image and runs it on the host's Docker + daemon. The role still registers that label and now installs only ``git`` and ``python3`` on the host, which the job uses + there, and no longer needs PyPI or Ansible Galaxy access. The inputs ``gitea_runner_molecule_venv``, + ``gitea_runner_molecule_collections_path``, ``gitea_runner_collections_requirements_file``, + ``gitea_runner_molecule_version``, ``gitea_runner_molecule_plugins_version``, + ``gitea_runner_molecule_ansible_core_version`` and ``gitea_runner_molecule_docker_sdk_version`` are removed; a value set + in the inventory is ignored. The role does not delete a venv or collections directory an earlier version installed: + remove ``/opt/molecule-venv``, ``/opt/molecule-collections`` (the old defaults) and + ``/molecule-requirements.yml`` by hand if nothing else uses them. diff --git a/docs/images/ci.md b/docs/images/ci.md index 3a3c7f8..9c1ccfa 100644 --- a/docs/images/ci.md +++ b/docs/images/ci.md @@ -1,17 +1,19 @@ # ci -The **CI tooling image** of the [`mortis.kamino`](https://git.rkdr.net/mortis/kamino) Collection: everything the Lint and Build -workflows used to install on each run is baked in, so a job only checks out the code and runs. +The **CI tooling image** of the [`mortis.kamino`](https://git.rkdr.net/mortis/kamino) Collection: everything the Lint, Build and +Molecule workflows used to install on each run is baked in, so a job only checks out the code and runs. ## What is in it Ubuntu 26.04 with: - **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`, - `ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`. + `ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule` and + `molecule-plugins[docker]` (the Docker driver, with the `docker` Python SDK). - **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from `requirements.yml`: `community.general` and `ansible.posix` at the exact versions CI tests against, so - `ansible-lint --offline` resolves their modules instead of mocking them. + `ansible-lint --offline` resolves their modules instead of mocking them; and from + `extensions/molecule/requirements.yml`, `community.docker`, which the Molecule Docker driver's own playbooks call. - **Every pre-commit hook environment** of `.pre-commit-config.yaml` in `/opt/pre-commit` (`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks, actionlint and zizmor. The Go hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to @@ -23,7 +25,7 @@ Ubuntu 26.04 with: `python3`, so sanity runs its compile test for those interpreters instead of skipping it. - `git`, `shellcheck` (actionlint runs it over `run:` blocks), `python3`, `python3-venv` and `ca-certificates`. The image runs as root and sets no working directory. -- `/opt/ci-pins.sha256`: the checksums of the four pin files this image was built from. +- `/opt/ci-pins.sha256`: the checksums of the five pin files this image was built from. It has no Node, so JavaScript actions (`actions/checkout`) cannot run in it: clone with `git`. @@ -56,19 +58,19 @@ jobs: pre-commit run --all-files --show-diff-on-failure ``` -`/opt/ci-pins.sha256` lists the four pin files by relative name, so `sha256sum -c` runs in the checkout root. When -the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and +`/opt/ci-pins.sha256` lists the five pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When +the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and collections are used as they are. When a pull request changes a pin the check fails and the job installs the pinned tools and collections itself for that run -(slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml` and `gitea-release-key.yml` are the -real consumers. +(slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml`, `molecule.yml` and `gitea-release-key.yml` +are the real consumers. ## Tags and pinning - `` is semver, independent of the Collection's version. A published version is never moved or rebuilt, so one digest belongs to exactly one version. `latest` is the newest version, for looking only. -- Pin `ci:@sha256:`; the digest decides what is pulled. Consumers: `lint.yml`, `build.yml` and - `gitea-release-key.yml`. +- Pin `ci:@sha256:`; the digest decides what is pulled. Consumers: `lint.yml`, `build.yml`, + `molecule.yml` and `gitea-release-key.yml`. - Renovate is configured to move the pins to a new version after the image is built on `main` (the rule is in `renovate.json`; the first pin of a brand-new image is made by hand). @@ -76,7 +78,7 @@ real consumers. `.gitea/workflows/image.yml` builds it with kaniko (repository root as build context, because the pin files are copied in). The workflow runs on pushes to `main` that touch `images/**`, `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, -`.pre-commit-config.yaml` or the workflow itself, never on a pull request, and builds an image only when its +`extensions/molecule/requirements.yml`, `.pre-commit-config.yaml` or the workflow itself, never on a pull request, and builds an image only when its inputs differ from those of its newest published version (`scripts/next_image_version.py` compares a checksum label). It then publishes the next patch of the matrix's `base:`, and Renovate opens the pull request that moves the pins to it. Each pushed layer stays below 100 MB (Cloudflare's request limit), which is why the Go toolchains diff --git a/docs/images/molecule-ubuntu2404.md b/docs/images/molecule-ubuntu2404.md index d844cd9..98e8dec 100644 --- a/docs/images/molecule-ubuntu2404.md +++ b/docs/images/molecule-ubuntu2404.md @@ -48,7 +48,7 @@ platforms: systemd needs a writable cgroup (`cgroupns_mode: host`, the `/sys/fs/cgroup` mount and tmpfs on `/run`), the firewall tools need `NET_ADMIN`, AppArmor is left unconfined for the container (`apparmor=unconfined`), and -nothing runs privileged. The docker driver needs molecule's docker plugin, which the runner provides. +nothing runs privileged. The docker driver needs molecule's docker plugin, which the ci image provides. The scenario `extensions/molecule/image-smoke` tests this image against that contract (release, systemd, packages, the `dbus` and `ssh` units, the Python bindings, `NET_ADMIN`). @@ -66,7 +66,7 @@ systemd, packages, the `dbus` and `ssh` units, the Python bindings, `NET_ADMIN`) ## How it is built and kept up to date `.gitea/workflows/image.yml` builds it with kaniko. The workflow runs on pushes to `main` that touch `images/**`, -`requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `.pre-commit-config.yaml` or the workflow itself, never on a pull request, and builds an +`requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml`, `.pre-commit-config.yaml` or the workflow itself, never on a pull request, and builds an image only when its inputs differ from those of its newest published version. A change under `images/molecule-ubuntu2404/` therefore needs no version edit: the merge publishes the next patch of the matrix's `base:`. The Ubuntu release is fixed by the name: a new Ubuntu release is a new image (`molecule-ubuntuNNNN`), and the roles diff --git a/docs/images/molecule-ubuntu2604.md b/docs/images/molecule-ubuntu2604.md index 2755bb7..f6e449c 100644 --- a/docs/images/molecule-ubuntu2604.md +++ b/docs/images/molecule-ubuntu2604.md @@ -47,7 +47,7 @@ platforms: systemd needs a writable cgroup (`cgroupns_mode: host`, the `/sys/fs/cgroup` mount and tmpfs on `/run`), the firewall tools need `NET_ADMIN`, AppArmor is left unconfined for the container (`apparmor=unconfined`), and -nothing runs privileged. The docker driver needs molecule's docker plugin, which the runner provides. +nothing runs privileged. The docker driver needs molecule's docker plugin, which the ci image provides. The scenario `extensions/molecule/image-smoke-2604` tests this image against that contract (release, systemd, packages, the `dbus` and `ssh` units, the Python bindings, `NET_ADMIN`). @@ -65,7 +65,7 @@ systemd, packages, the `dbus` and `ssh` units, the Python bindings, `NET_ADMIN`) ## How it is built and kept up to date `.gitea/workflows/image.yml` builds it with kaniko. The workflow runs on pushes to `main` that touch `images/**`, -`requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `.pre-commit-config.yaml` or the workflow itself, never on a pull request, and builds an +`requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml`, `.pre-commit-config.yaml` or the workflow itself, never on a pull request, and builds an image only when its inputs differ from those of its newest published version. A change under `images/molecule-ubuntu2604/` therefore needs no version edit: the merge publishes the next patch of the matrix's `base:`. The Ubuntu release is fixed by the name: a new Ubuntu release is a new image (`molecule-ubuntuNNNN`), and the roles diff --git a/extensions/molecule/requirements.yml b/extensions/molecule/requirements.yml index ba4458b..5f967f9 100644 --- a/extensions/molecule/requirements.yml +++ b/extensions/molecule/requirements.yml @@ -1,9 +1,9 @@ --- # Collections the Molecule test harness itself calls, as opposed to the roles under test (those are -# in the requirements.yml at the repository root, which the ci image also bakes for Lint). The -# Docker driver of molecule-plugins runs community.docker modules in its own create and destroy -# playbooks, so every scenario needs it. The Molecule job (.gitea/workflows/molecule.yml) installs -# this file next to the root one; the ci image does not, because Lint never runs a driver. +# in the requirements.yml at the repository root). The Docker driver of molecule-plugins runs +# community.docker modules in its own create and destroy playbooks, so every scenario needs it. +# The ci image (images/ci) bakes it into /opt/collections next to the root one; a pull request that +# changes it fails the image's pin check, so the Molecule job installs it itself. # Renovate (renovate.json, ansible-galaxy manager) bumps this pin. collections: - name: community.docker diff --git a/images/ci/Dockerfile b/images/ci/Dockerfile index 051ada8..a2ad49e 100644 --- a/images/ci/Dockerfile +++ b/images/ci/Dockerfile @@ -1,4 +1,4 @@ -# CI image for the Lint and Build workflows of this Collection: every tool they used +# CI image for the Lint, Build and Molecule workflows of this Collection: every tool they used # to install on each run is baked in, so a job only checks out the code and runs. # # Built by .gitea/workflows/image.yml with kaniko (repository root as build context, @@ -12,11 +12,12 @@ # - OS packages: git, shellcheck (actionlint runs it over run: blocks), the # distribution's python3 and ca-certificates. # - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit, -# antsibull-changelog, galaxy-importer, reuse), on the Python of +# antsibull-changelog, galaxy-importer, reuse, molecule and its Docker driver), on the Python of # .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv uses. # - /opt/collections: the collections of requirements.yml (the versions the roles are # tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline` -# resolves their modules without a mock list. +# resolves their modules without a mock list; and those of extensions/molecule/requirements.yml +# (community.docker), which the Molecule Docker driver's own playbooks call. # - /opt/pre-commit: every hook environment of .pre-commit-config.yaml, installed by # `pre-commit install-hooks` (gitleaks and actionlint are built from source by # pre-commit, which downloads a Go toolchain: that is most of the time saved). @@ -25,8 +26,8 @@ # - Python 3.11, 3.13 and PYTHON_VERSION as python on PATH, so that # `ansible-test sanity` runs its compile test for them instead of skipping it. # They come from python-build-standalone through uv, pinned by the uv version. -# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt, requirements-dev.lock, requirements.yml and -# .pre-commit-config.yaml this image was built from. A job runs +# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt, requirements-dev.lock, requirements.yml, +# extensions/molecule/requirements.yml and .pre-commit-config.yaml this image was built from. A job runs # `sha256sum -c /opt/ci-pins.sha256` in its checkout; when a pull request changes a # pin the check fails and the job installs the tools as before, until the image # is rebuilt from main. @@ -64,6 +65,8 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ WORKDIR /src COPY requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-config.yaml ./ +# Kept at its checkout path: its name matches the root requirements.yml. +COPY extensions/molecule/requirements.yml extensions/molecule/ # The interpreters come first: /opt/venv is built from the pinned one (PYTHON_VERSION, kept equal to # .python-version and to the lock header by `check_image_versions.py pins`), not from the distribution's @@ -95,11 +98,13 @@ RUN "$(echo /opt/python/cpython-${PYTHON_VERSION}.*/bin/python${PYTHON_VERSION}) && /opt/venv/bin/python --version \ && /opt/venv/bin/pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt -# The collections of requirements.yml. ANSIBLE_COLLECTIONS_PATH is set to the target for the +# The collections of requirements.yml and extensions/molecule/requirements.yml. ANSIBLE_COLLECTIONS_PATH is set to the target for the # install only: a collection found anywhere else on the path would be skipped as "already # installed" and not copied here. RUN ANSIBLE_COLLECTIONS_PATH=/opt/collections \ /opt/venv/bin/ansible-galaxy collection install -r requirements.yml -p /opt/collections \ + && ANSIBLE_COLLECTIONS_PATH=/opt/collections \ + /opt/venv/bin/ansible-galaxy collection install -r extensions/molecule/requirements.yml -p /opt/collections \ && du -sh /opt/collections # pre-commit needs a git repository to resolve a config. The hook repositories are @@ -172,16 +177,16 @@ FROM os AS final ARG PYTHON_VERSION=3.14 LABEL org.opencontainers.image.title="ci" \ - org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, the collections of requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Use it as a job container pinned by tag and digest; it has no Node, so clone with git." \ + org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint, Build and Molecule workflows run in it, so a job only checks out the code and runs. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule with its Docker driver, the collections of requirements.yml and extensions/molecule/requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Use it as a job container pinned by tag and digest; it has no Node, so clone with git." \ org.opencontainers.image.source="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.url="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.documentation="https://git.rkdr.net/mortis/kamino/src/branch/main/docs/images/ci.md" \ org.opencontainers.image.licenses="GPL-3.0-or-later" \ org.opencontainers.image.authors="Defame1297 and contributors" \ org.opencontainers.image.base.name="ubuntu:26.04" \ - net.rkdr.mortis.purpose="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs." \ - net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse), /opt/collections (community.general, ansible.posix), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \ - net.rkdr.mortis.usage="Job container on the kamino-docker runner: container image git.rkdr.net/mortis/ci:version@sha256:digest with PRE_COMMIT_HOME set to /opt/pre-commit; in the checkout root run sha256sum -c /opt/ci-pins.sha256 and install the pinned tools and collections when a pull request changed them, else use /opt/venv/bin and ANSIBLE_COLLECTIONS_PATH=/opt/collections. See the documentation label." + net.rkdr.mortis.purpose="CI tooling image for the mortis.kamino Ansible Collection: the Lint, Build and Molecule workflows run in it, so a job only checks out the code and runs." \ + net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, molecule-plugins[docker]), /opt/collections (community.general, ansible.posix, community.docker), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \ + net.rkdr.mortis.usage="Job container of the Lint, Build and Molecule jobs on the kamino-docker runner: container image git.rkdr.net/mortis/ci:version@sha256:digest with PRE_COMMIT_HOME set to /opt/pre-commit; in the checkout root run sha256sum -c /opt/ci-pins.sha256 and install the pinned tools and collections when a pull request changed them, else use /opt/venv/bin and ANSIBLE_COLLECTIONS_PATH=/opt/collections. See the documentation label." ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ PRE_COMMIT_HOME=/opt/pre-commit \ @@ -197,14 +202,18 @@ COPY --from=build /root/.ansible/test /root/.ansible/test # The target interpreters ansible-test looks for on PATH, and the pin record. COPY --from=build /src/requirements-dev.txt /src/requirements-dev.lock /src/requirements.yml /src/.pre-commit-config.yaml /opt/ci-pins/ +# Under its checkout path, so `sha256sum -c` in a checkout root finds it. +COPY --from=build /src/extensions/molecule/requirements.yml /opt/ci-pins/extensions/molecule/ RUN set -eu; \ for v in $(printf '%s\n' 3.11 3.13 "${PYTHON_VERSION}" | sort -u); do \ ln -sf "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}"; \ "python${v}" --version; \ done; \ cd /opt/ci-pins; \ - sha256sum requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-config.yaml > /opt/ci-pins.sha256; \ + sha256sum requirements-dev.txt requirements-dev.lock requirements.yml extensions/molecule/requirements.yml \ + .pre-commit-config.yaml > /opt/ci-pins.sha256; \ ansible --version | head -n1; \ ansible-galaxy collection list; \ pre-commit --version; \ + molecule --version; \ shellcheck --version | sed -n 2p diff --git a/renovate.json b/renovate.json index 8e00f61..6193547 100644 --- a/renovate.json +++ b/renovate.json @@ -77,12 +77,12 @@ }, { "customType": "regex", - "description": "The 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 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.", "managerFilePatterns": [ "/^\\.gitea/workflows/molecule\\.yml$/" ], "matchStrings": [ - "MOLECULE_IMAGE(?:_[0-9]+)?:\\s*>-\\s*\\n\\s*(?git\\.rkdr\\.net/mortis/[a-z0-9._-]+):(?[^@\\s]+)@(?sha256:[0-9a-f]{64})" + "(?:CI_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" diff --git a/requirements-dev.lock b/requirements-dev.lock index 768e7a7..d0490aa 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -196,7 +196,9 @@ ansible-builder==3.2.0 \ ansible-compat==26.11.0 \ --hash=sha256:35cbe829e0b5a9acb85d34b8d5da2eb45acaf767f6651f90e0ab2f3a96a060bb \ --hash=sha256:c06a486b39ced440f9f6fb9a99583c73d9239c94ece822a27ea2242173462dda - # via ansible-lint + # via + # ansible-lint + # molecule ansible-core==2.22.0 \ --hash=sha256:8285d4cc81c3e3eb2d954e75531724fe0ae154d228475638123451f034a74657 \ --hash=sha256:bf50b4a0cfa985e30585c7ba301897ea7050d224ca49d2816cab10e33a160e1c @@ -205,6 +207,7 @@ ansible-core==2.22.0 \ # ansible-compat # ansible-lint # galaxy-importer + # molecule ansible-lint==26.10.1 \ --hash=sha256:a746c6f3cb5719d1c202bc14e956ef3b0eca704025d1aa92707a27fc73ed73ea \ --hash=sha256:cc26d405ee38c3390e80ec18c4137b5685c36d03ce7d4d8233b0470d9a0e21e9 @@ -589,6 +592,7 @@ click==8.5.1 \ # black # click-default-group # llm + # molecule # reuse # rich-click # sqlite-utils @@ -679,6 +683,11 @@ distro==1.9.0 \ # via # ansible-lint # bindep + # selinux +docker==7.2.0 \ + --hash=sha256:a3f45fdeb9165e2d25d9a1d02ddf3bc70fb572cf5ebbf9b58558c22caf29b71f \ + --hash=sha256:cebb93773d334f778e023a7ee352a8d6e13ab1bd3b863a4d4a59dec897df43ac + # via molecule-plugins docutils==0.23 \ --hash=sha256:25d013af9bf23bc1c7b2b093dff4208166c53a94786c9e447808335ef1185fea \ --hash=sha256:746f5060322511280a1e50eb76846ed6bf2342984b2ac04dc42caa1a8d78799e @@ -686,6 +695,10 @@ docutils==0.23 \ # antsibull-changelog # antsibull-docutils # rstcheck-core +enrich==1.2.7 \ + --hash=sha256:0a2ab0d2931dff8947012602d1234d2a3ee002d9a355b5d70be6bf5466008893 \ + --hash=sha256:f29b2c8c124b4dbd7c975ab5c3568f6c7a47938ea3b7d2106c8a3bd346545e4f + # via molecule filelock==4.3.0 \ --hash=sha256:143407310acf479e82d88068e3b9a6486f45fb410c0ed8729fe7359eaabeb6f1 \ --hash=sha256:f933f39f7e01249a4a49b9abab30edc6d4b874624c3de5dd0b0d137aa8adb979 @@ -883,6 +896,7 @@ jinja2==3.1.6 \ --hash=sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67 # via # ansible-core + # molecule # reuse jiter==0.19.0 \ --hash=sha256:0282eae10bbccfabcb6001ced6a20abc5e05e26c6316e7729c8fc1510bd3b8e1 \ @@ -998,6 +1012,7 @@ jsonschema==4.26.0 \ # ansible-builder # ansible-compat # ansible-lint + # molecule jsonschema-specifications==2025.9.1 \ --hash=sha256:98802fee3a11ee76ecaca44429fda8a41bff98b00a0f2838151b113f210cc6fe \ --hash=sha256:b540987f239e745613c7a9176f3edb72b832a4ac465cf02712288397832b5e8d @@ -1185,6 +1200,16 @@ mdurl==0.1.2 \ --hash=sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8 \ --hash=sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba # via markdown-it-py +molecule==26.11.0 \ + --hash=sha256:5e48f66e97ce03ba1e9cfdf4a3667db499e960543c91bb62f530c6cd6337dd9b \ + --hash=sha256:706bb3d9a34e1531cfe1cda294974aad4ccba70af3ecb2d434266e0df73b0c09 + # via + # -r requirements-dev.txt + # molecule-plugins +molecule-plugins==26.11.0 \ + --hash=sha256:194be2c43d950545cc699ab19f1a55b26853809e6e8c855ea1a42edacf5c7ee7 \ + --hash=sha256:513808288b7027c465b124e66a2a31002c7c907b2fea9002f63ee90bb2d0ef84 + # via -r requirements-dev.txt multidict==7.2.1 \ --hash=sha256:02009b402129a73e1f3da68f48eb999afbacd29f25aef0d5052b84ff5c2786a2 \ --hash=sha256:02d9c04d395a36eeebe89e45f2269614a4675b8e83fddcba15bba2be903971e5 \ @@ -1418,6 +1443,7 @@ packaging==26.3 \ # bindep # black # galaxy-importer + # molecule # virtualenv parsley==1.3 \ --hash=sha256:9444278d47161d5f2be76a767809a3cbe6db4db822f46a4fd7481d4057208d41 \ @@ -1445,6 +1471,7 @@ pluggy==1.7.0 \ --hash=sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8 # via # llm + # molecule # sqlite-utils pre-commit==4.7.0 \ --hash=sha256:1f3deee12b914c8fa184bd2b5953391c2e4f36763e403d4a23dc9983fa7c6e86 \ @@ -1916,6 +1943,7 @@ pyyaml==6.0.4 \ # apm-cli # galaxy-importer # llm + # molecule # pre-commit # python-frontmatter # yamllint @@ -1932,7 +1960,9 @@ requests==2.34.2 \ # via # apm-cli # azure-core + # docker # galaxy-importer + # molecule-plugins resolvelib==1.2.1 \ --hash=sha256:7d08a2022f6e16ce405d60b68c390f054efcfd0477d4b9bd019cc941c28fad1c \ --hash=sha256:fb06b66c8da04172d9e72a21d7d06186d8919e32ae5ab5cdf5b9d920be805ac2 @@ -1946,6 +1976,8 @@ rich==15.0.0 \ --hash=sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36 # via # apm-cli + # enrich + # molecule # rich-click # typer rich-click==1.9.9 \ @@ -2098,6 +2130,10 @@ ruamel-yaml==0.19.1 \ # via # ansible-lint # apm-cli +selinux==0.3.0 \ + --hash=sha256:2a88b337ac46ad0f06f557b2806c3df62421972f766673dd8bf26732fb75a9ea \ + --hash=sha256:ecf7add45c939e9dda682c390a2cd0a845c94a4793a2cce9e8870d4ee9501f99 + # via molecule-plugins semantic-version==2.10.0 \ --hash=sha256:bdabb6d336998cbb378d4b9db3a4b56a1e3235701dc05ea2690d9a997ed5041c \ --hash=sha256:de78a3b8e0feda74cabc54aab2da702113e33ac9d9eb9d2389bcf1f58b7d9177 @@ -2178,7 +2214,9 @@ tzdata==2026.6 \ urllib3==2.8.0 \ --hash=sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3 \ --hash=sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63 - # via requests + # via + # docker + # requests virtualenv==21.15.12 \ --hash=sha256:a3976f886eb6019fcb1d137b223d160adaeff524ab0ad785c729a43c31cc158c \ --hash=sha256:bbbf764388a18dee8c3532c77af7a29680cd8121911d6dcb3484335d76547323 @@ -2232,7 +2270,9 @@ watchdog==7.1.1 \ wcmatch==12.0.4 \ --hash=sha256:23fe77fbfa3fff9e46f0f4a3d1891065270596774bd6131bd2f973fb822242a1 \ --hash=sha256:3e61e404a90a8b6c8bca197fb9ad5f1accbb34ee206b63e0c588a2ab9aa05862 - # via ansible-lint + # via + # ansible-lint + # molecule websockets==16.1.1 \ --hash=sha256:01fbdcbac298efe19360b94bc0039c8f746f0220ba570f327577bfee81059175 \ --hash=sha256:024193f8551a2b0eafbdd160911012c4e6c228c28430c84433253299a9e42d6a \ diff --git a/requirements-dev.txt b/requirements-dev.txt index 855dc73..6f15d73 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ -# Pinned tooling for lint and build, used by CI (.gitea/workflows) and locally: +# Pinned tooling for lint, build and Molecule, used by CI (.gitea/workflows) and locally: # python3 -m venv .venv && . .venv/bin/activate && pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt # This file holds the direct pins; requirements-dev.lock is their hashed lock (every transitive # package too, with the sha256 of each release file) and is what gets installed; pip refuses an @@ -12,6 +12,8 @@ pre-commit==4.7.0 antsibull-changelog==0.37.0 galaxy-importer==0.4.44 reuse==6.3.0 +molecule==26.11.0 +molecule-plugins[docker]==26.11.0 # apm-cli: for changing apm.yml (run apm install, commit the lock). Keep it at 0.36.1 or later (#252): # before 0.29.0, `apm audit --ci` compares the whole .claude/settings.json and fails on any hand-written key. apm-cli==0.36.1 diff --git a/requirements.yml b/requirements.yml index 4d633e5..8641753 100644 --- a/requirements.yml +++ b/requirements.yml @@ -2,8 +2,8 @@ # Collections the roles of this Collection call (the dependencies of galaxy.yml, pinned exactly). # galaxy.yml holds the lower bounds a consumer needs; this file holds the versions CI tests # against. One file feeds every consumer, so they cannot drift apart: -# - the ci image (images/ci/Dockerfile) bakes it into /opt/collections for Lint; -# - the Molecule job (.gitea/workflows/molecule.yml) installs it for the scenarios; +# - the ci image (images/ci/Dockerfile) bakes it into /opt/collections for Lint and Molecule; +# - the Molecule job (.gitea/workflows/molecule.yml) installs it itself when a pull request changes it; # - scripts/dev-setup.sh installs it into .ansible/collections for local lint. # Renovate (renovate.json, ansible-galaxy manager) bumps these pins. collections: diff --git a/roles/gitea_runner/README.md b/roles/gitea_runner/README.md index f908d26..2b8ed90 100644 --- a/roles/gitea_runner/README.md +++ b/roles/gitea_runner/README.md @@ -1,10 +1,10 @@ # gitea_runner -Installs a Gitea Actions runner (`gitea-runner`) with Docker as a systemd service, registers it against a Gitea instance with a token minted on the `gitea_runner_token_host`, renders its `config.yaml`, optionally schedules a Docker prune, installs molecule test tooling behind a host-executor label, and optionally updates or removes the runner. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth. +Installs a Gitea Actions runner (`gitea-runner`) with Docker as a systemd service, registers it against a Gitea instance with a token minted on the `gitea_runner_token_host`, renders its `config.yaml`, optionally schedules a Docker prune, optionally adds a host-executor label for jobs that use the host's Docker daemon, and optionally updates or removes the runner. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth. ## Supported platforms -Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses `ansible.builtin.apt` and installs `docker.io`, so Debian-family hosts only, and needs outbound access to dl.gitea.com and Docker Hub (the Docker check pulls `ubuntu:24.04`); with the molecule tooling enabled also PyPI and Ansible Galaxy. On an unprivileged LXC host, Docker needs nesting enabled on the container. +Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses `ansible.builtin.apt` and installs `docker.io`, so Debian-family hosts only, and needs outbound access to dl.gitea.com and Docker Hub (the Docker check pulls `ubuntu:24.04`). On an unprivileged LXC host, Docker needs nesting enabled on the container. ## Requirements and run order @@ -57,12 +57,8 @@ Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses `an | `gitea_runner_docker_prune_disk_threshold_percent` | `0` (off) | Use % of the Docker root's filesystem above which the pressure prune runs the count prune and a capped builder prune, behind the job gate. 1 to 99; needs the count above 0. | | `gitea_runner_docker_prune_disk_check_schedule` | `hourly` | `OnCalendar` of the pressure prune timer. | | `gitea_runner_docker_prune_builder_keep_storage` | `10GB` | `--keep-storage` of the builder prune under pressure. | -| `gitea_runner_molecule_enabled` | `false` | Install molecule tooling and add the host label. | +| `gitea_runner_molecule_enabled` | `false` | Add the host label and install `git` and `python3`, which a job on it uses on the host; the job brings its own toolchain in an image and runs it on the host's Docker daemon. | | `gitea_runner_molecule_label` | `molecule` | Host-executor label name, registered as `