feat(molecule): add the molecule workflow and an image smoke scenario
.gitea/workflows/molecule.yml runs every molecule scenario of the Collection on the kamino-molecule host-executor label of kamino-runner (the Docker daemon of the runner LXC, no job container, no Docker socket handed out), against the molecule-ubuntu2404 image pinned by tag and digest. Scenarios are discovered: extensions/molecule/*/ and roles/*/molecule/*/, so the wave-1 roles only add their scenario directory. extensions/molecule/image-smoke tests the image itself: Ubuntu 24.04, systemd as PID 1 and reachable over the container connection, the packages the roles manage, ssh enabled, the python bindings Ansible needs, NET_ADMIN. A rebuilt or re-pinned image therefore has to pass before a role scenario trusts it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
be673b266d
commit
12c70ec7dc
4 files changed
+209
No files matched your search
@@ -0,0 +1,117 @@
|
||||
name: Molecule
|
||||
|
||||
# Behavioural tests of the Collection: every molecule scenario under
|
||||
# extensions/molecule/*/ and roles/*/molecule/*/. extensions/molecule/image-smoke
|
||||
# tests the test image itself, so it runs 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, Runner isolation). The runner's firewall is inert until
|
||||
# the Proxmox datacenter firewall is enabled, so a scenario can reach the whole LAN:
|
||||
# keep mortis/kamino private and accepting no fork pull requests until then. The `if:`
|
||||
# guard is a convenience filter, not a boundary: the workflow file comes from the PR
|
||||
# head. The real condition is that only trusted people can push branches here.
|
||||
#
|
||||
# Tooling is provisioned on the runner by the gitea_runner role (molecule venv and the
|
||||
# collections the roles use); this job installs nothing. 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 version.
|
||||
on: # yamllint disable-line rule:truthy
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths: &paths
|
||||
- 'roles/**'
|
||||
- 'extensions/**'
|
||||
- 'plugins/**'
|
||||
- 'meta/**'
|
||||
- 'galaxy.yml'
|
||||
- '.gitea/workflows/molecule.yml'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths: *paths
|
||||
workflow_dispatch: {}
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# Scenarios use fixed container names on the runner's shared Docker daemon.
|
||||
concurrency:
|
||||
group: molecule
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
molecule:
|
||||
# Same-repo, non-bot branches only; a push to main or a manual dispatch always runs.
|
||||
if: >-
|
||||
github.repository == 'mortis/kamino' &&
|
||||
(github.event_name != 'pull_request' ||
|
||||
(github.event.pull_request.head.repo.full_name == github.repository &&
|
||||
!startsWith(github.head_ref, 'renovate/')))
|
||||
runs-on: [kamino-molecule]
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
MOLECULE_VENV: /opt/molecule-venv
|
||||
MOLECULE_COLLECTIONS: /opt/molecule-collections
|
||||
# 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.0@sha256:80dbfa7f88309072e954ae20e80ee8171bd750abc7c1d9563c746bf6f0121f04
|
||||
steps:
|
||||
# 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: |
|
||||
test -x "$MOLECULE_VENV/bin/molecule" || { echo "::error::molecule is not installed on this runner: run install_services for kamino-runner first"; exit 1; }
|
||||
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)"
|
||||
|
||||
# molecule test destroys its instance on success and on failure.
|
||||
- name: Run the scenarios
|
||||
working-directory: ac/ansible_collections/mortis/kamino
|
||||
run: |
|
||||
# molecule calls ansible-config and ansible-playbook by name
|
||||
export PATH="$MOLECULE_VENV/bin:$PATH"
|
||||
# the collection under test first, then what the roles use
|
||||
export ANSIBLE_COLLECTIONS_PATH="$(cd ../../.. && pwd):$MOLECULE_COLLECTIONS"
|
||||
failed=""
|
||||
ran=0
|
||||
for cfg in extensions/molecule/*/molecule.yml; do
|
||||
[ -e "$cfg" ] || continue
|
||||
name="$(basename "$(dirname "$cfg")")"
|
||||
echo "::group::molecule test: $name"
|
||||
molecule test -s "$name" || failed="$failed $name"
|
||||
ran=$((ran + 1))
|
||||
echo "::endgroup::"
|
||||
done
|
||||
for cfg in roles/*/molecule/*/molecule.yml; do
|
||||
[ -e "$cfg" ] || continue
|
||||
role="${cfg#roles/}"
|
||||
role="${role%%/*}"
|
||||
name="$(basename "$(dirname "$cfg")")"
|
||||
echo "::group::molecule test: $role/$name"
|
||||
(cd "roles/$role" && molecule test -s "$name") || failed="$failed $role/$name"
|
||||
ran=$((ran + 1))
|
||||
echo "::endgroup::"
|
||||
done
|
||||
echo "Scenarios run: $ran"
|
||||
test "$ran" -gt 0 || { echo "::error::no molecule scenario found"; exit 1; }
|
||||
test -z "$failed" || { echo "::error::Failed:$failed"; exit 1; }
|
||||
Reference in new issue
Block a user