ci(molecule): harden the stale-container sweep and correct comments
The sweep now fails the step when a timestamp cannot be parsed or a container it removes is still there, while tolerating one another run's sweep removed first. Its 30-minute bound and the job's timeout point at each other, since a shorter bound would remove a live run's containers. The concurrency comments of Lint and Build now say that runs on one ref queue rather than cancel, and the scenarios' comment names the run script as what removes their containers. The workflow test checks the label filters of the sweep and cleanup steps by name. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
96cb9246c6
commit
6c2e05c95a
21 files changed
+61
-66
No files matched your search
@@ -16,8 +16,8 @@ on: # yamllint disable-line rule:truthy
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A newer push to the same pull request cancels the running run. A tag's ref differs from every
|
||||
# branch's, so a tag run has a group of its own and is never cancelled.
|
||||
# A newer push to the same pull request cancels the running run. Other runs on one ref (a tag,
|
||||
# a dispatched branch) queue instead: a newer one waits and replaces one still waiting.
|
||||
concurrency:
|
||||
group: build-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
@@ -17,8 +17,8 @@ on: # yamllint disable-line rule:truthy
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A newer push to the same pull request makes the running run obsolete; a manual dispatch never
|
||||
# cancels another run.
|
||||
# A newer push to the same pull request makes the running run obsolete. Other runs on one ref
|
||||
# queue instead: a newer one waits for the running one and replaces one still waiting.
|
||||
concurrency:
|
||||
group: lint-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
@@ -47,6 +47,7 @@ jobs:
|
||||
(github.event_name != 'pull_request' ||
|
||||
github.event.pull_request.head.repo.full_name == github.repository)
|
||||
runs-on: [kamino-molecule]
|
||||
# Also the age past which the first step removes a run's containers; keep the two equal.
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
# The tools and collections molecule runs with: the image Lint and Build use.
|
||||
@@ -93,11 +94,17 @@ jobs:
|
||||
run: |
|
||||
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
|
||||
ids="$(docker ps -aq --filter 'label=net.rkdr.mortis.molecule-run')"
|
||||
# The job's timeout-minutes: a shorter bound would remove a live run's containers.
|
||||
cutoff="$(date -d '30 minutes ago' +%s)"
|
||||
for id in $ids; do
|
||||
# a container removed since the listing is skipped
|
||||
# a container removed since the listing, by its run or another run's sweep, is skipped
|
||||
created="$(docker inspect --format '{{.Created}}' "$id")" || continue
|
||||
if [ "$(date -d "$created" +%s)" -lt "$cutoff" ]; then docker rm -f "$id"; fi
|
||||
created="$(date -d "$created" +%s)"
|
||||
if [ "$created" -ge "$cutoff" ]; then continue; fi
|
||||
if ! docker rm -f "$id" >/dev/null && docker container inspect "$id" >/dev/null 2>&1; then
|
||||
echo "::error::could not remove container $id"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
||||
|
||||
@@ -28,9 +28,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -28,9 +28,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -28,9 +28,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -28,9 +28,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -73,9 +73,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -29,9 +29,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -27,9 +27,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -38,9 +38,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -48,9 +48,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -27,9 +27,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -28,9 +28,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -34,9 +34,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -27,9 +27,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -48,9 +48,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -27,9 +27,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -35,9 +35,8 @@ provisioner:
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
|
||||
@@ -24,11 +24,11 @@ label_of() {
|
||||
esac
|
||||
}
|
||||
|
||||
# Removes the scenario's containers by the platform names in its molecule.yml, expanded as molecule
|
||||
# expands them (they carry ${KAMINO_RUN_ID}), 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. The ci image has no docker CLI: python3
|
||||
# is the one molecule runs on, with molecule, PyYAML and the Docker SDK of molecule's Docker driver.
|
||||
# Removes the scenario's containers by the platform names in its molecule.yml, expanded by molecule's
|
||||
# interpolator, 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. 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() {
|
||||
python3 -I - "$1/molecule.yml" <<'EOF'
|
||||
import os
|
||||
|
||||
@@ -358,12 +358,12 @@ def alive(pid):
|
||||
return stat.rsplit(")", 1)[1].split()[0] != "Z"
|
||||
|
||||
|
||||
def label_filters():
|
||||
"""The label filters of the workflow's docker commands, as `--filter label=<key>[=<value>]`."""
|
||||
def label_filters(step_name):
|
||||
"""The label filters of a workflow step's docker commands, as `--filter label=<key>[=<value>]`."""
|
||||
workflow = yaml.safe_load(WORKFLOW.read_text())
|
||||
steps = [s for job in workflow["jobs"].values() for s in job.get("steps", [])]
|
||||
runs = "\n".join(s.get("run", "") for s in steps)
|
||||
return re.findall(r"--filter ['\"]?label=([^'\"\s]+)", runs)
|
||||
run = next(s["run"] for s in steps if s.get("name") == step_name)
|
||||
return re.findall(r"--filter ['\"]?label=([^'\"\s]+)", run)
|
||||
|
||||
|
||||
class ScenarioPlatformsTest(unittest.TestCase):
|
||||
@@ -392,10 +392,14 @@ class ScenarioPlatformsTest(unittest.TestCase):
|
||||
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
|
||||
|
||||
def test_the_workflow_finds_the_containers_by_the_run_label(self):
|
||||
filters = label_filters()
|
||||
# the sweep of earlier runs filters by the key, the cleanup of this run by key and value
|
||||
self.assertIn(RUN_LABEL, filters)
|
||||
self.assertIn(f"{RUN_LABEL}=$KAMINO_RUN_ID", filters)
|
||||
self.assertEqual(
|
||||
label_filters("Remove the containers earlier runs left"), [RUN_LABEL]
|
||||
)
|
||||
self.assertEqual(
|
||||
label_filters("Remove this run's containers"),
|
||||
[f"{RUN_LABEL}=$KAMINO_RUN_ID"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user