From f77586dc60829f24f672cea9686decffef3d3aea Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 22 Nov 2026 21:47:53 +0000 Subject: [PATCH] ci(molecule): remove each scenario's containers in the workflow instead of molecule's destroy molecule's trailing destroy runs the Docker driver's destroy playbook, whose "Wait for instance(s) deletion to complete" task alone costs about 5.6 s per scenario, about 84 s over the 15 scenarios of a full run. The whole destroy phase measured about 103 s per full run (the median across full runs, among them 4764, 4714, 4698 and 4578). The workflow already removes stale containers before the run, so it can remove each scenario's containers itself with `docker rm -f` as soon as the scenario ends, pass or fail, and skip the playbook. The names come from each scenario's molecule.yml (platforms[].name) via the molecule venv's Python and PyYAML, so no list is kept in the workflow. A failed removal fails the step. The test_sequence rule in the workflow guidance now says both destroys are left out and that platform names are literal. Assisted-by: Claude Code:claude-opus-5-5 --- .gitea/workflows/AGENTS.md | 9 +++++---- .gitea/workflows/molecule.yml | 20 ++++++++++++++++--- .../molecule/image-smoke-2604/molecule.yml | 8 +++----- extensions/molecule/image-smoke/molecule.yml | 8 +++----- .../molecule/check_mode/molecule.yml | 8 +++----- .../molecule/default/molecule.yml | 8 +++----- roles/docker/molecule/default/molecule.yml | 8 +++----- roles/fail2ban/molecule/default/molecule.yml | 8 +++----- roles/gitea/molecule/default/molecule.yml | 8 +++----- .../molecule/default/molecule.yml | 8 +++----- .../molecule/default/molecule.yml | 8 +++----- roles/sshd/molecule/default/molecule.yml | 8 +++----- .../molecule/default/molecule.yml | 8 +++----- .../molecule/default/molecule.yml | 8 +++----- roles/traefik/molecule/default/molecule.yml | 8 +++----- roles/ufw/molecule/default/molecule.yml | 8 +++----- .../molecule/default/molecule.yml | 8 +++----- 17 files changed, 67 insertions(+), 82 deletions(-) diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index f2a1145..1b81bf2 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -92,10 +92,11 @@ issue. 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. -- **Every scenario sets `scenario.test_sequence` to molecule's default minus the leading - `destroy`;** copy it into a new scenario. *Why:* the workflow clears stale containers first, - and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves none - behind. *Held:* review. +- **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 + those names as soon as it ends, which skips the driver's destroy wait, and the molecule state + lives in the job's own `ANSIBLE_HOME`, so a killed run leaves none behind. *Held:* review. - **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index a467f55..32dc456 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -128,9 +128,11 @@ jobs: # 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. + # The scenarios leave out molecule's destroy (see their test_sequence): the step removes each + # scenario's containers itself, by the platform names in its molecule.yml, as soon as it ends. + # That skips the driver's destroy playbook: its deletion wait is about 5.6 s per scenario (about + # 84 s over 15), and the whole destroy phase measured about 103 s a full run. A cancelled run + # is killed before it can, so the step first removes what one left. - name: Run the scenarios working-directory: ac/ansible_collections/mortis/kamino env: @@ -169,6 +171,17 @@ jobs: echo "::notice::no base copy of $sel; running this checkout's copy" fi selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1 + # Removes the containers of the scenario in directory $1 by its platform names (literal in + # molecule.yml), whether or not they exist; a failure fails the step. + 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="$("$MOLECULE_VENV/bin/python3" -I -c "$py" "$1/molecule.yml")" && [ -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 + [ -z "$ids" ] || docker rm -f $ids >/dev/null + } failed="" ran=0 while IFS= read -r dir; do @@ -188,6 +201,7 @@ jobs: (cd "roles/$role" && molecule test -s "$name"