Files
Kamino/.gitea/workflows/molecule.yml
T
Defame1297andClaude Sonnet 5.5 068bec93a9
Build / build (pull_request) Successful in 11s
Lint / lint (pull_request) Successful in 43s
Molecule / molecule (pull_request) Successful in 6m19s
fix(molecule): install community.docker for the Docker driver
Every scenario failed in its create step (couldn't resolve module community.docker.docker_login): molecule's Docker driver runs community.docker modules in its own create and destroy playbooks, and the collection came from the runner-provisioned /opt/molecule-collections that the previous commit stopped reading. The roles do not call it, so it is not in requirements.yml, which the ci image bakes for Lint and which Renovate would rebuild the image for. It is pinned in extensions/molecule/requirements.yml instead; the Molecule job installs both files, cached by their combined checksum. Renovate tracks the new file and the bot-diff gate allows only its version: lines.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
2026-11-14 14:30:11 +00:00

206 lines
11 KiB
YAML

name: Molecule
# Behavioural tests of the Collection: every molecule scenario under
# extensions/molecule/*/ and roles/*/molecule/*/. extensions/molecule/image-smoke and
# image-smoke-2604 test the test images themselves, so they run even before any role exists.
#
# It runs on the `kamino-molecule` label, a host executor on kamino-runner, which uses
# that LXC's own Docker daemon; no job container is given the Docker socket. That makes
# the job root-equivalent on the runner LXC, which is rebuildable and holds no
# production secret (ADR 0004 in the maintainer's environment repository, Runner
# isolation). The runner sits in an isolated network segment (outbound DNS to two
# resolvers and web traffic only; inbound SSH from two management hosts only), so a
# scenario cannot reach the LAN. A live test on 2026-11-08 showed a fork pull request's
# Build workflow starting on the runner at once, with no approval step (the tester may
# have had write access, so this is unproven for outsiders). The `if:` guard is a
# convenience filter, not a boundary: a fork controls its own workflow file. So the
# repository should not accept fork pull requests from untrusted users until the
# operator decides otherwise; the real condition is that only trusted people can push
# branches or open pull requests here.
#
# The molecule venv is provisioned on the runner by the gitea_runner role. 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.
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
push:
branches:
- main
paths:
- 'roles/**'
- 'extensions/**'
- 'plugins/**'
- 'meta/**'
- 'galaxy.yml'
- '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
# the next push to main. After Renovate's 03:17 run, which can take 30 minutes of the one slot.
schedule:
- cron: "43 4 * * *"
workflow_dispatch: {}
permissions:
contents: read
# A pull request run is cancelled when a newer commit is pushed to the same pull request (the
# same rule as lint.yml and build.yml); a run on main is never cancelled, so its group is the
# commit SHA. Scenarios use fixed container names on the runner's shared Docker daemon, so two
# runs must not overlap. The group no longer guarantees that (it is per pull request now): the
# runner's single slot does (gitea_runner_capacity: 1 in the maintainer's environment
# repository). Raise that capacity and this needs a lock or a shared group again.
concurrency:
group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
molecule:
# Same-repo branches only (bot branches included: a Renovate pin pull request is what tests a new
# image); a push to main or a manual dispatch always runs. No paths filter on pull requests, so
# that Molecule can be a required check: a required check that a pull request never starts would
# block it. A fork pull request is skipped by the guard below.
if: >-
github.repository == 'mortis/kamino' &&
(github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name == github.repository)
runs-on: [kamino-molecule]
timeout-minutes: 30
env:
MOLECULE_VENV: /opt/molecule-venv
# Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run
# one locally.
MOLECULE_IMAGE: >-
git.rkdr.net/mortis/molecule-ubuntu2404:0.1.6@sha256:f1bf4d208aa8f1626f797348a120541af3d4445cb2da0b948d94425df1741909
# The same for Ubuntu 26.04, the release the hosts are moving to; used by
# `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604.
MOLECULE_IMAGE_2604: >-
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.3@sha256:7a90a9ff1819e99be17b28decff273f4f6405470a302c0fe961a61427e72bad6
steps:
# The molecule venv is provisioned by the gitea_runner role (install_services); fail with
# a clear message when this runs before it has.
- name: Check the provisioned tooling
run: |
if ! test -x "$MOLECULE_VENV/bin/molecule"; then
echo "::error::molecule is not installed on this runner: run install_services for kamino-runner 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.
- name: Checkout the commit under test
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: http.extraheader
GIT_CONFIG_VALUE_0: "AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}"
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
REF: ${{ github.ref }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
rm -rf ac
mkdir -p ac/ansible_collections/mortis
git clone "$REPO_URL" ac/ansible_collections/mortis/kamino
cd ac/ansible_collections/mortis/kamino
# A clone has no refs/pull/*: fetch the run's ref when the sha is not on a branch.
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.
# molecule test destroys its instance on success and on failure; a cancelled run is killed
# before it can, so the step first removes what such a run left, since the next run may not
# select the same scenarios.
- name: Run the scenarios
working-directory: ac/ansible_collections/mortis/kamino
env:
EVENT_NAME: ${{ github.event_name }}
# The workflow only runs for pull requests to main; lint.yml uses the same constant.
BASE_REF: origin/main
run: |
# The platform names of every scenario, anchored: <role>-instance and image-smoke[-2604].
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
stale="$(docker ps -aq --filter 'name=^/[a-z0-9-]+-instance$' --filter 'name=^/image-smoke(-2604)?$')"
if [ -n "$stale" ]; then
# 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; keep that 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_HOME="$ac_root/.ansible"
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.
sel=scripts/select_molecule_scenarios.py
if git cat-file -e "$BASE_REF:$sel" 2>/dev/null; then
sel_dir="$(mktemp -d)"
trap 'rm -rf "$sel_dir"' EXIT
git show "$BASE_REF:$sel" > "$sel_dir/select.py"
sel="$sel_dir/select.py"
else
echo "::notice::no base copy of $sel; running this checkout's copy"
fi
selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1
failed=""
ran=0
while IFS= read -r dir; do
[ -n "$dir" ] || continue
name="$(basename "$dir")"
case "$dir" in
extensions/*)
label="$name"
echo "::group::molecule test: $label"
molecule test -s "$name" </dev/null || failed="$failed $label"
;;
*)
role="${dir#roles/}"
role="${role%%/*}"
label="$role/$name"
echo "::group::molecule test: $label"
(cd "roles/$role" && molecule test -s "$name" </dev/null) || failed="$failed $label"
;;
esac
ran=$((ran + 1))
echo "::endgroup::"
done <<< "$selected"
echo "Scenarios run: $ran"
# A scenario that swallowed the rest of the list must not pass quietly.
want="$(grep -c . <<< "$selected" || true)"
test "$ran" -eq "$want" || { echo "::error::ran $ran of $want selected scenarios"; exit 1; }
test -z "$failed" || { echo "::error::Failed:$failed"; exit 1; }