ci(molecule): run Molecule from the ci image instead of the runner's venv #345

Merged
Defame1297 merged 5 commits from ci/225-molecule-in-ci-image into main 2026-11-24 08:25:22 +00:00
29 changed files with 473 additions and 283 deletions

No files matched your search

+9 -8
View File
@@ -53,10 +53,10 @@ issue.
- **Lint and Build run in the pinned `ci` image and compare the pin files with the checksums
baked into it (`/opt/ci-pins.sha256`).** A pull request that changes `requirements-dev.txt`,
`requirements-dev.lock`, `requirements.yml` or `.pre-commit-config.yaml` takes the slow path,
which installs the pinned tools and collections. *Why:* a pull request is tested on its own
pins, and an unchanged one starts in seconds. *Held:* control: the "Check the baked tooling
against the pins" step.
`requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml` or
`.pre-commit-config.yaml` takes the slow path, which installs the pinned tools and collections.
*Why:* a pull request is tested on its own pins, and an unchanged one starts in seconds.
*Held:* control: the "Check the baked tooling against the pins" step.
- **Triggers:** both run on pull requests to `main`, on push to `main` until #166 removes that
trigger, and on manual dispatch; Build also runs on `v*` tags, where it checks the tag against
`galaxy.yml`. *Why:* the tag is what consumers install. *Held:* review.
@@ -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
+2 -1
View File
@@ -64,7 +64,8 @@ jobs:
if sha256sum --quiet -c /opt/ci-pins.sha256; then
echo "The pin files match the ci image; using the baked tools."
else
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml," \
"extensions/molecule/requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
"installing the pinned tools for this run."
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
fi
+1
View File
@@ -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: {}
+4 -3
View File
@@ -6,8 +6,8 @@ name: Lint
# The tools come from the ci image (images/ci, built by image.yml): the pinned Python
# tools of requirements-dev.txt, the collections of requirements.yml and the hook
# environments of .pre-commit-config.yaml are baked in. When a PR changes one of those
# files the checksum check below fails and the job installs the pinned tools and
# collections itself for this run (slower, same result).
# files or extensions/molecule/requirements.yml the checksum check below fails and the
# job installs the pinned tools and collections itself for this run (slower, same result).
on: # yamllint disable-line rule:truthy
pull_request:
branches:
@@ -64,7 +64,8 @@ jobs:
if sha256sum --quiet -c /opt/ci-pins.sha256; then
echo "The pin files match the ci image; using the baked tools."
else
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml," \
"extensions/molecule/requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
"installing the pinned tools and collections for this run."
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
# --force: the baked copy of a changed pin is replaced, not kept as "already installed".
+37 -49
View File
@@ -11,12 +11,11 @@ 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 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.
on: # yamllint disable-line rule:truthy
pull_request:
branches:
@@ -33,7 +32,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 +65,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 +76,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 and labelled 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 +101,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 +119,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 +132,28 @@ 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. The driver's connection plugin
# (community.docker.docker) runs the docker CLI, which the image lacks: the host's goes in.
ac_root="$(cd ../../.. && pwd)"
sock_gid="$(stat -c %g /var/run/docker.sock)"
docker_cli="$(readlink -f "$(command -v docker)")"
mkdir -p "$ac_root/home"
docker run --rm -i --init --name "$RUN_CONTAINER" \
--label "net.rkdr.mortis.molecule-run=$RUN_CONTAINER" \
--user "$(id -u):$(id -g)" --group-add "$sock_gid" \
-v /var/run/docker.sock:/var/run/docker.sock -v "$docker_cli:/usr/local/bin/docker:ro" \
-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" scripts/run_molecule_in_ci_image.sh <<< "$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
@@ -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 ``<gitea_runner_molecule_label>: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
``<gitea_runner_home>/molecule-requirements.yml`` by hand if nothing else uses them.
+19 -12
View File
@@ -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,24 @@ 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
The Molecule job runs on the `kamino-molecule` runner, a host executor, so it starts the image itself with
`docker run`, as the runner user, with the Docker socket and the checkout mounted at the same path (molecule
hands the daemon paths in the checkout); `scripts/run_molecule_in_ci_image.sh` does the same pin check inside it.
Read `.gitea/workflows/molecule.yml` for the full command.
`/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
- `<version>` 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:<version>@sha256:<digest>`; the digest decides what is pulled. Consumers: `lint.yml`, `build.yml` and
`gitea-release-key.yml`.
- Pin `ci:<version>@sha256:<digest>`; 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 +83,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
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
+4 -4
View File
@@ -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
+20 -11
View File
@@ -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<MINOR> 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. Pin it by tag and digest, as a job container or with docker run; 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<PYTHON_VERSION> (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<PYTHON_VERSION> (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \
net.rkdr.mortis.usage="Lint and Build: job container on the kamino-docker runner, git.rkdr.net/mortis/ci:version@sha256:digest with PRE_COMMIT_HOME set to /opt/pre-commit. Molecule (host executor, kamino-molecule runner): docker run as the runner user, with the Docker socket and the checkout mounted at the same path. In both, run sha256sum -c /opt/ci-pins.sha256 in the checkout root 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
+2 -2
View File
@@ -77,12 +77,12 @@
},
{
"customType": "regex",
"description": "The 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 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.",
"managerFilePatterns": [
"/^\\.gitea/workflows/molecule\\.yml$/"
],
"matchStrings": [
"MOLECULE_IMAGE(?:_[0-9]+)?:\\s*>-\\s*\\n\\s*(?<depName>git\\.rkdr\\.net/mortis/[a-z0-9._-]+):(?<currentValue>[^@\\s]+)@(?<currentDigest>sha256:[0-9a-f]{64})"
"(?: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})"
],
"datasourceTemplate": "docker",
"versioningTemplate": "semver"
+43 -3
View File
@@ -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 \
+3 -1
View File
@@ -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
+2 -2
View File
@@ -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:
+4 -8
View File
@@ -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 `<label>:host`. |
| `gitea_runner_molecule_venv` | `/opt/molecule-venv` | Tooling virtualenv. |
| `gitea_runner_collections_requirements_file` | empty (asserted when the molecule tooling is enabled) | Collections file on the control host that the molecule install reads; a change reinstalls the collections. |
| `gitea_runner_molecule_collections_path` | `/opt/molecule-collections` | Collections for the tested roles, installed from that file. |
| `gitea_runner_molecule_version`, `_plugins_version`, `_ansible_core_version`, `_docker_sdk_version` | pinned in `defaults/main.yml` | Tooling pins. |
## Tags
@@ -90,7 +86,7 @@ Change the registration scope of a registered runner: set `gitea_runner_registra
## Tests
The `default` molecule scenario runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the molecule tooling install are not covered.
The `default` molecule scenario runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the host packages of the host-executor label are not covered.
## Notes
+3 -14
View File
@@ -77,21 +77,10 @@ gitea_runner_gitea_install_dir: "/usr/local/bin"
gitea_runner_gitea_user: "git"
gitea_runner_gitea_app_dir: "/etc/gitea"
# Optional molecule tooling for role tests. A host-executor label runs the molecule job on this
# host, against its own Docker daemon, so no job container needs the Docker socket. The tooling
# lives in a venv and is installed at provision time, so a CI run installs nothing.
# Optional host-executor label for role tests. A job on it runs on this host and brings its
# toolchain in an image it runs on this host's Docker daemon, so no job container needs the
# Docker socket; the role installs only git and python3, which the job uses on the host.
# A job on that label runs as the runner user, who is in the docker group, so it is
# root-equivalent on this host: see Notes in the README before enabling it.
gitea_runner_molecule_enabled: false
gitea_runner_molecule_label: molecule
gitea_runner_molecule_venv: /opt/molecule-venv
gitea_runner_molecule_collections_path: /opt/molecule-collections
# Collections requirements file, on the control host, that the molecule install reads. No
# default: required when gitea_runner_molecule_enabled is true.
gitea_runner_collections_requirements_file: ""
gitea_runner_molecule_version: "26.11.0"
gitea_runner_molecule_plugins_version: "26.11.0"
# Held below 2.22: ansible-core 2.22 requires Python 3.13 or newer, and the venv uses the
# system Python of Ubuntu 24.04 (3.12).
gitea_runner_molecule_ansible_core_version: "2.21.6"
gitea_runner_molecule_docker_sdk_version: "7.2.0"
+8 -42
View File
@@ -8,7 +8,8 @@ argument_specs:
the runner user, installs Docker and the C(gitea-runner) binary on first install, registers the runner when no
C(.runner) file exists, renders C(config.yaml), writes the systemd unit and starts the service. Optionally
schedules a Docker prune, updates the binary (C(gitea_runner_update)) with rollback through the internal
C(mortis.kamino._binary_update) role, and installs molecule test tooling (C(gitea_runner_molecule_enabled)).
C(mortis.kamino._binary_update) role, and adds a host-executor label for jobs that use the host's Docker
daemon (C(gitea_runner_molecule_enabled)).
The role builds no container image.
- >-
Registration delegates C(gitea actions generate-runner-token) to the inventory host C(gitea_runner_token_host),
@@ -92,7 +93,7 @@ argument_specs:
type: path
default: /home/gitea-runner
description:
- Home of the runner user. The molecule tooling copies the collections requirements file there.
- Home of the runner user.
gitea_runner_install_dir:
type: path
default: /usr/local/bin
@@ -273,47 +274,12 @@ argument_specs:
default: false
description:
- >-
When true the molecule venv and collections are installed and the C(<gitea_runner_molecule_label>:host)
label is added to the runner. The runner user is in the C(docker) group, so a job on that label is
root-equivalent on the host. Needs C(gitea_runner_collections_requirements_file).
When true the C(<gitea_runner_molecule_label>:host) label is added to the runner and C(git) and
C(python3) are installed on the host. A job on that label runs on the host and uses its Docker daemon;
it brings its own toolchain in an image, and the role installs no test tooling. The runner user is in
the C(docker) group, so a job on that label is root-equivalent on the host.
gitea_runner_molecule_label:
type: str
default: molecule
description:
- Name of the host-executor label, registered as C(<label>:host).
gitea_runner_molecule_venv:
type: path
default: /opt/molecule-venv
description:
- Virtualenv that holds the pinned molecule tooling.
gitea_runner_collections_requirements_file:
type: str
default: ""
description:
- >-
Collections requirements file, on the control host, that the molecule install reads. No role default:
asserted non-empty at role start when C(gitea_runner_molecule_enabled) is true.
- Its checksum is the molecule install stamp, so a change reinstalls the collections.
gitea_runner_molecule_collections_path:
type: path
default: /opt/molecule-collections
description:
- Collections path that receives the collections of the requirements file.
gitea_runner_molecule_version:
type: str
description:
- Pinned molecule release installed into the venv; see C(defaults/main.yml).
gitea_runner_molecule_plugins_version:
type: str
description:
- Pinned molecule-plugins release installed into the venv; see C(defaults/main.yml).
gitea_runner_molecule_ansible_core_version:
type: str
description:
- >-
Pinned ansible-core release installed into the venv; see C(defaults/main.yml). Held below 2.22, which
needs a newer Python than Ubuntu 24.04 ships.
gitea_runner_molecule_docker_sdk_version:
type: str
description:
- Pinned Docker SDK for Python release installed into the venv; see C(defaults/main.yml).
- Name of the host-executor label, registered as C(<label>:host), for jobs that use the host's Docker daemon.
+1 -1
View File
@@ -4,7 +4,7 @@ galaxy_info:
namespace: mortis
author: Defame1297
license: GPL-3.0-or-later
description: Install, register, configure, update and remove a Gitea Actions runner with Docker and optional molecule test tooling.
description: Install, register, configure, update and remove a Gitea Actions runner with Docker and an optional host-executor label.
min_ansible_version: "2.19"
platforms:
- name: Ubuntu
@@ -17,7 +17,6 @@
gitea_runner_docker_prune_disk_threshold_percent: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_disk_threshold_percent | default(90) }}"
gitea_runner_docker_prune_disk_check_schedule: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_disk_check_schedule | default('hourly') }}"
gitea_runner_docker_prune_builder_keep_storage: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_builder_keep_storage | default('10GB') }}"
gitea_runner_molecule_enabled: "{{ gitea_runner_test_refused.vars.gitea_runner_molecule_enabled | default(false) }}"
# Only reached when the include returned. The message must not contain the expected
# text, so the rescue below cannot mistake it for the assert.
@@ -443,9 +443,6 @@
- name: disk threshold without a count
vars: {gitea_runner_docker_prune_keep_per_repository: 0}
expect: needs gitea_runner_docker_prune_keep_per_repository above 0
- name: molecule tooling without a requirements file
vars: {gitea_runner_molecule_enabled: true}
expect: gitea_runner_collections_requirements_file must name
loop_control:
loop_var: gitea_runner_test_refused
label: "{{ gitea_runner_test_refused.name }}"
+1 -1
View File
@@ -133,7 +133,7 @@
when: gitea_runner_update | bool
tags: [gitea_runner, update]
- name: Install the molecule test tooling
- name: Install the host packages of the host-executor label
ansible.builtin.include_tasks: molecule.yml
when: gitea_runner_molecule_enabled | bool
tags: [gitea_runner, molecule]
+4 -78
View File
@@ -1,86 +1,12 @@
---
# Everything the molecule job needs is installed here, at provision time, so a CI
# run only executes tests: pinned tooling in a venv and the collections the roles use.
# The role builds no test image: the scenarios are expected to pull theirs from a registry.
# gitea_runner_collections_requirements_file is asserted non-empty in validate.yml.
- name: Install molecule venv prerequisites
# A job on the host-executor label brings its toolchain in an image it runs on this host's
# Docker daemon; on the host itself it only clones the checkout and runs stdlib Python.
- name: Install the host packages of the host-executor label
become: true
ansible.builtin.apt:
name:
- python3-venv
- python3-pip
- git
# community.docker.docker_image runs on this host via the Docker SDK.
- python3-requests
- python3-docker
- python3
state: present
cache_valid_time: 3600
tags: [gitea_runner, molecule]
- name: Install pinned molecule tooling into its venv
become: true
ansible.builtin.pip:
name:
- "molecule=={{ gitea_runner_molecule_version }}"
- "molecule-plugins[docker]=={{ gitea_runner_molecule_plugins_version }}"
- "ansible-core=={{ gitea_runner_molecule_ansible_core_version }}"
- "docker=={{ gitea_runner_molecule_docker_sdk_version }}"
virtualenv: "{{ gitea_runner_molecule_venv }}"
virtualenv_command: python3 -m venv
tags: [gitea_runner, molecule]
# The collections come from gitea_runner_collections_requirements_file and are
# reinstalled when it changes. requirements.sha256 in the collections path records the
# checksum of the file the installed set came from; it is written only after a
# successful install, so a failed install is retried on the next run (a guard on the
# copied file changing would skip it forever). --force: without it ansible-galaxy skips
# a collection it finds on any other collections path of this host and installs
# nothing into -p, leaving the molecule job without the modules it needs.
- name: Copy the pinned collections file to the runner host
become: true
ansible.builtin.copy:
src: "{{ gitea_runner_collections_requirements_file }}"
dest: "{{ gitea_runner_home }}/molecule-requirements.yml"
owner: root
group: root
mode: "0644"
tags: [gitea_runner, molecule]
- name: Read the requirements checksum of the installed collections
become: true
ansible.builtin.slurp:
src: "{{ gitea_runner_molecule_collections_path }}/requirements.sha256"
register: gitea_runner_molecule_collections_stamp
failed_when: false
tags: [gitea_runner, molecule]
- name: Install the collections the tested roles use
when: gitea_runner_molecule_collections_stamp.content | default('') | b64decode | trim != gitea_runner_molecule_requirements_sha256
vars:
gitea_runner_molecule_requirements_sha256: "{{ lookup('ansible.builtin.file', gitea_runner_collections_requirements_file) | hash('sha256') }}"
tags: [gitea_runner, molecule]
block:
- name: Install the collections of the requirements file
become: true
ansible.builtin.command:
argv:
- "{{ gitea_runner_molecule_venv }}/bin/ansible-galaxy"
- collection
- install
- --force
- -r
- "{{ gitea_runner_home }}/molecule-requirements.yml"
- -p
- "{{ gitea_runner_molecule_collections_path }}"
changed_when: true
tags: [gitea_runner, molecule]
- name: Record the checksum of the installed collections
become: true
ansible.builtin.copy:
content: "{{ gitea_runner_molecule_requirements_sha256 }}\n"
dest: "{{ gitea_runner_molecule_collections_path }}/requirements.sha256"
owner: root
group: root
mode: "0644"
tags: [gitea_runner, molecule]
-11
View File
@@ -79,14 +79,3 @@
the pressure prune removes images by that count.
quiet: true
when: gitea_runner_docker_prune_enabled | bool
- name: Require the collections requirements file for the molecule tooling
ansible.builtin.assert:
that:
- gitea_runner_collections_requirements_file is string
- gitea_runner_collections_requirements_file | length > 0
fail_msg: >-
gitea_runner_molecule_enabled is true, so gitea_runner_collections_requirements_file must name
the collections requirements file on the control host that the molecule install reads.
quiet: true
when: gitea_runner_molecule_enabled | bool
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# 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 run the scenarios on stdin. CI_BASE_PYTHON is a test seam.
#
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
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."
else
echo "::warning::a pin file differs from the ci 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
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
extra_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:${extra_collections}/opt/collections"
exec scripts/run_molecule_scenarios.sh "$AC_ROOT/molecule-runs" <<< "$selected"
+17 -9
View File
@@ -27,16 +27,24 @@ label_of() {
# Removes the scenario's containers by the literal platform names in its molecule.yml, 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.
# python3 is the molecule venv's, with PyYAML.
# The ci 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() {
local names ids
local py='import sys, yaml; print(*(p["name"] for p in yaml.safe_load(open(sys.argv[1]))["platforms"]))'
names="$(python3 -I -c "$py" "$1/molecule.yml")" || return 1
[ -n "$names" ] || return 1
# shellcheck disable=SC2046,SC2086 # names and ids are one word each
ids="$(docker ps -aq $(printf -- '--filter name=^/%s$ ' $names))" || return 1
# shellcheck disable=SC2086
if [ -n "$ids" ]; then docker rm -f $ids >/dev/null || return 1; fi
python3 -I - "$1/molecule.yml" <<'EOF'
import sys
import docker
import yaml
names = [p["name"] for p in yaml.safe_load(open(sys.argv[1]))["platforms"]]
if not names:
sys.exit("no platform names in " + sys.argv[1])
containers = docker.from_env().containers
for name in names:
for container in containers.list(all=True, filters={"name": f"^/{name}$"}):
if container.name == name:
container.remove(force=True)
EOF
}
# Runs scenario $2 into $work/$1/. Its outcome is the rc file, which a lane that died lacks.
@@ -511,6 +511,12 @@ class PureTest(unittest.TestCase):
)
self.assertEqual(civ.dockerfile_labels('FROM c\nLABEL a="unbalanced\n'), {})
def test_the_molecule_collections_are_an_input_of_the_ci_image(self):
root = pathlib.Path(__file__).resolve().parents[2]
entry = civ.matrix_of((root / civ.MATRIX_FILE).read_text())["ci"]
files = civ.inputs_of(entry, (root / entry["dockerfile"]).read_text())[1]
self.assertIn("extensions/molecule/requirements.yml", 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())
@@ -0,0 +1,157 @@
# 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.
Run with: python3 -m unittest discover -s tests/scripts
"""
import os
import pathlib
import shutil
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[2]
SCRIPT = REPO / "scripts" / "run_molecule_in_ci_image.sh"
# Each stub appends its name, arguments and the paths it saw to STUB_LOG; STUB_FAIL_<name> fails it.
STUB = """#!/usr/bin/env bash
name="$(basename "$0")"
echo "$name args=$* path=$PATH acp=${ANSIBLE_COLLECTIONS_PATH:-}" >> "$STUB_LOG"
key="STUB_FAIL_$(printf %s "$name" | tr -c 'A-Za-z0-9' _)"
[ -n "${!key:-}" ] && exit 1
exit 0
"""
# The base python: `-m venv <dir>` makes a venv whose bin holds a pip stub.
PYTHON_STUB = """#!/usr/bin/env bash
echo "python args=$*" >> "$STUB_LOG"
[ -n "${STUB_FAIL_python:-}" ] && exit 1
[ "$1 $2" = "-m venv" ] || exit 1
mkdir -p "$3/bin"
cp "$STUB_SOURCE" "$3/bin/pip"
"""
# The scenario runner: records its arguments, paths and stdin.
RUNNER_STUB = """#!/usr/bin/env bash
echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH stdin=[$(cat | tr '\\n' ' ')]" >> "$STUB_LOG"
"""
@unittest.skipUnless(shutil.which("bash"), "bash is required")
class RunMoleculeInCiImageTest(unittest.TestCase):
def setUp(self):
self.tmp = pathlib.Path(tempfile.mkdtemp(prefix="kamino-runci-")).resolve()
self.addCleanup(shutil.rmtree, self.tmp, True)
self.ac_root = self.tmp / "ac"
self.checkout = self.ac_root / "ansible_collections" / "mortis" / "kamino"
(self.checkout / "scripts").mkdir(parents=True)
runner = self.checkout / "scripts" / "run_molecule_scenarios.sh"
runner.write_text(RUNNER_STUB)
runner.chmod(0o755)
bin_dir = self.tmp / "bin"
bin_dir.mkdir()
stub = self.tmp / "stub"
stub.write_text(STUB)
stub.chmod(0o755)
for name in ("sha256sum", "ansible-galaxy", "ansible", "molecule"):
shutil.copy(stub, bin_dir / name)
python = self.tmp / "python"
python.write_text(PYTHON_STUB)
python.chmod(0o755)
self.log = self.tmp / "stub.log"
self.log.touch()
self.env = {
"PATH": f"{bin_dir}:{os.environ['PATH']}",
"HOME": str(self.tmp),
"AC_ROOT": str(self.ac_root),
"CI_BASE_PYTHON": str(python),
"STUB_LOG": str(self.log),
"STUB_SOURCE": str(stub),
}
self.pins = self.ac_root / "pins"
def run_script(self, selection="roles/alpha/molecule/default\n", **env):
return subprocess.run(
["bash", str(SCRIPT)],
cwd=self.checkout,
env={**self.env, **env},
input=selection,
capture_output=True,
text=True,
check=False,
)
def calls(self, name):
return [
line
for line in self.log.read_text().splitlines()
if line.split(" ", 1)[0] == name
]
def test_matching_pins_use_the_baked_tools(self):
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.assertEqual(self.calls("python"), [])
self.assertEqual(self.calls("ansible-galaxy"), [])
self.assertEqual(len(self.calls("ansible")), 1)
self.assertEqual(len(self.calls("molecule")), 1)
(runner,) = self.calls("runner")
self.assertIn(f"acp={self.ac_root}:/opt/collections ", runner)
self.assertIn(f"args={self.ac_root}/molecule-runs ", runner)
def test_changed_pins_are_installed_and_put_first(self):
result = self.run_script(STUB_FAIL_sha256sum="1")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(
self.calls("python"), [f"python args=-m venv {self.pins}/venv"]
)
(pip,) = self.calls("pip")
self.assertIn(
"args=install --quiet --require-hashes -r requirements-dev.lock"
" -r requirements-dev.txt ",
pip,
)
galaxy = self.calls("ansible-galaxy")
self.assertEqual(len(galaxy), 2)
for line, req in zip(
galaxy, ("requirements.yml", "extensions/molecule/requirements.yml")
):
self.assertIn(
f"args=collection install --force -r {req} -p {self.pins}/collections ",
line,
)
# The target alone, so a baked copy is not taken as already installed.
self.assertTrue(line.endswith(f"acp={self.pins}/collections"), line)
(runner,) = self.calls("runner")
self.assertIn(f"path={self.pins}/venv/bin:", runner)
self.assertIn(
f"acp={self.ac_root}:{self.pins}/collections:/opt/collections ", runner
)
def test_the_selection_reaches_the_scenario_runner(self):
selection = "roles/alpha/molecule/default\nextensions/molecule/image-smoke\n"
result = self.run_script(selection)
self.assertEqual(result.returncode, 0, result.stderr)
(runner,) = self.calls("runner")
self.assertIn(
"stdin=[roles/alpha/molecule/default extensions/molecule/image-smoke ]",
runner,
)
def test_a_failing_install_fails_the_run(self):
for stub in ("python", "pip", "ansible-galaxy"):
with self.subTest(stub=stub):
self.log.write_text("")
shutil.rmtree(self.pins, True)
key = "STUB_FAIL_" + stub.replace("-", "_")
result = self.run_script(STUB_FAIL_sha256sum="1", **{key: "1"})
self.assertNotEqual(result.returncode, 0)
self.assertEqual(self.calls("runner"), [])
if __name__ == "__main__":
unittest.main()
+75 -15
View File
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
"""Tests for scripts/run_molecule_scenarios.sh with stub molecule and docker on PATH.
"""Tests for scripts/run_molecule_scenarios.sh with a stub molecule and a stub Docker SDK.
Run with: python3 -m unittest discover -s tests/scripts
"""
@@ -11,6 +11,7 @@ import re
import shutil
import signal
import subprocess
import sys
import tempfile
import time
import unittest
@@ -42,15 +43,62 @@ esac
echo "$label end $(date +%s.%N)" >> "$STUB_LOG"
"""
# `ps` lists a container id per name filter; `rm` records the ids or fails on request.
DOCKER_STUB = """#!/usr/bin/env bash
echo "docker $*" >> "$STUB_DOCKER_LOG"
case "$1" in
ps) for a in "$@"; do case "$a" in name=*) n="${a#name=^/}"; echo "id-${n%$}" ;; esac; done ;;
rm) [ -z "${STUB_RM_FAIL:-}" ] || exit 1 ;;
esac
# The Docker SDK as the script uses it: each container a name filter matches is listed, and its
# removal is recorded or fails on request.
DOCKER_SDK_STUB = """import os, re
class Container:
def __init__(self, name):
self.name = name
self.id = "id-" + name
def remove(self, force=False):
if os.environ.get("STUB_RM_FAIL"):
raise RuntimeError("removal refused")
with open(os.environ["STUB_DOCKER_LOG"], "a") as log:
log.write(f"remove {self.name} force={force}\\n")
class Containers:
def list(self, all=False, filters=None):
name = re.fullmatch(r"\\^/(.+)\\$", filters["name"])[1]
with open(os.environ["STUB_DOCKER_LOG"], "a") as log:
log.write(f"list {name} all={all}\\n")
return [Container(name), Container(name + "-other")]
class Client:
containers = Containers()
def from_env():
return Client()
"""
def stub_python(where):
"""A venv whose python3 imports the Docker SDK stub; `python3 -I` ignores PYTHONPATH, not a venv."""
subprocess.run(
[sys.executable, "-m", "venv", "--without-pip", str(where)], check=True
)
site = subprocess.run(
[
str(where / "bin" / "python3"),
"-c",
"import sysconfig; print(sysconfig.get_path('purelib'))",
],
check=True,
capture_output=True,
text=True,
).stdout.strip()
site = pathlib.Path(site)
(site / "docker.py").write_text(DOCKER_SDK_STUB)
# PyYAML from the environment running the tests
(site / "outer.pth").write_text(str(pathlib.Path(yaml.__file__).parents[1]) + "\n")
return where / "bin"
PLATFORMS = {
"roles/alpha/molecule/default": ["alpha-instance"],
"roles/beta/molecule/default": ["beta-instance", "beta2-instance"],
@@ -61,6 +109,15 @@ PLATFORMS = {
@unittest.skipUnless(shutil.which("bash"), "bash is required")
class RunMoleculeScenariosTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.venv_tmp = tempfile.mkdtemp(prefix="kamino-runmol-venv-")
cls.python_bin = stub_python(pathlib.Path(cls.venv_tmp) / "venv")
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.venv_tmp, True)
def setUp(self):
self.tmp = pathlib.Path(tempfile.mkdtemp(prefix="kamino-runmol-")).resolve()
self.addCleanup(shutil.rmtree, self.tmp, True)
@@ -73,15 +130,14 @@ class RunMoleculeScenariosTest(unittest.TestCase):
(d / "molecule.yml").write_text(yaml.safe_dump({"platforms": platforms}))
bin_dir = self.tmp / "bin"
bin_dir.mkdir()
for name, body in (("molecule", MOLECULE_STUB), ("docker", DOCKER_STUB)):
(bin_dir / name).write_text(body)
(bin_dir / name).chmod(0o755)
(bin_dir / "molecule").write_text(MOLECULE_STUB)
(bin_dir / "molecule").chmod(0o755)
self.log = self.tmp / "molecule.log"
self.docker_log = self.tmp / "docker.log"
self.log.touch()
self.docker_log.touch()
self.env = {
"PATH": f"{bin_dir}:{os.environ['PATH']}",
"PATH": f"{bin_dir}:{self.python_bin}:{os.environ['PATH']}",
"HOME": str(self.tmp),
"STUB_ROOT": str(self.root),
"STUB_LOG": str(self.log),
@@ -160,10 +216,14 @@ class RunMoleculeScenariosTest(unittest.TestCase):
self.assertEqual(proc.returncode, 1)
self.assertIn("::error::Failed: beta/default\n", proc.stdout)
self.assertIn("Scenarios run: 4", proc.stdout)
docker = self.docker_log.read_text()
docker = self.docker_log.read_text().splitlines()
for name in (n for names in PLATFORMS.values() for n in names):
self.assertIn(f"--filter name=^/{name}$", docker)
self.assertIn("docker rm -f id-beta-instance id-beta2-instance", docker)
self.assertIn(f"list {name} all=True", docker)
self.assertIn(f"remove {name} force=True", docker)
# a filter match by another name is left alone
self.assertFalse(
[line for line in docker if line.endswith("-other force=True")]
)
def test_molecule_gets_no_stdin(self):
proc = self.run_script(list(PLATFORMS), STUB_alpha_default="stdin")