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:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
# A newer push to the same pull request cancels the running run. A tag's ref differs from every
|
# A newer push to the same pull request cancels the running run. Other runs on one ref (a tag,
|
||||||
# branch's, so a tag run has a group of its own and is never cancelled.
|
# a dispatched branch) queue instead: a newer one waits and replaces one still waiting.
|
||||||
concurrency:
|
concurrency:
|
||||||
group: build-${{ github.ref }}
|
group: build-${{ github.ref }}
|
||||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ on: # yamllint disable-line rule:truthy
|
|||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
# A newer push to the same pull request makes the running run obsolete; a manual dispatch never
|
# A newer push to the same pull request makes the running run obsolete. Other runs on one ref
|
||||||
# cancels another run.
|
# queue instead: a newer one waits for the running one and replaces one still waiting.
|
||||||
concurrency:
|
concurrency:
|
||||||
group: lint-${{ github.ref }}
|
group: lint-${{ github.ref }}
|
||||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ jobs:
|
|||||||
(github.event_name != 'pull_request' ||
|
(github.event_name != 'pull_request' ||
|
||||||
github.event.pull_request.head.repo.full_name == github.repository)
|
github.event.pull_request.head.repo.full_name == github.repository)
|
||||||
runs-on: [kamino-molecule]
|
runs-on: [kamino-molecule]
|
||||||
|
# Also the age past which the first step removes a run's containers; keep the two equal.
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
env:
|
env:
|
||||||
# The tools and collections molecule runs with: the image Lint and Build use.
|
# The tools and collections molecule runs with: the image Lint and Build use.
|
||||||
@@ -93,11 +94,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
|
# 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')"
|
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)"
|
cutoff="$(date -d '30 minutes ago' +%s)"
|
||||||
for id in $ids; do
|
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
|
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
|
done
|
||||||
|
|
||||||
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -73,9 +73,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -38,9 +38,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -48,9 +48,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -34,9 +34,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -48,9 +48,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -35,9 +35,8 @@ provisioner:
|
|||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
scenario:
|
scenario:
|
||||||
# molecule's default sequence minus both destroys: the workflow removes the container as soon as
|
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||||
# this scenario ends, and a later run removes one a killed run left; molecule's destroy only adds
|
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||||
# the driver's poll wait. After a local run, run `molecule destroy` yourself.
|
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ label_of() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Removes the scenario's containers by the platform names in its molecule.yml, expanded as molecule
|
# Removes the scenario's containers by the platform names in its molecule.yml, expanded by molecule's
|
||||||
# expands them (they carry ${KAMINO_RUN_ID}), in place of molecule's destroy, which the scenarios
|
# interpolator, in place of molecule's destroy, which the scenarios leave out: its driver waits about
|
||||||
# leave out: its driver waits about 5.6 s per scenario for the deletion (about 84 s over 15), and
|
# 5.6 s per scenario for the deletion (about 84 s over 15), and the whole destroy phase measured about
|
||||||
# the whole destroy phase measured about 103 s a full run. The ci image has no docker CLI: python3
|
# 103 s a full run. The ci image has no docker CLI: python3 is the one molecule runs on, with PyYAML
|
||||||
# is the one molecule runs on, with molecule, PyYAML and the Docker SDK of molecule's Docker driver.
|
# and the Docker SDK of molecule's Docker driver.
|
||||||
remove_instances() {
|
remove_instances() {
|
||||||
python3 -I - "$1/molecule.yml" <<'EOF'
|
python3 -I - "$1/molecule.yml" <<'EOF'
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -358,12 +358,12 @@ def alive(pid):
|
|||||||
return stat.rsplit(")", 1)[1].split()[0] != "Z"
|
return stat.rsplit(")", 1)[1].split()[0] != "Z"
|
||||||
|
|
||||||
|
|
||||||
def label_filters():
|
def label_filters(step_name):
|
||||||
"""The label filters of the workflow's docker commands, as `--filter label=<key>[=<value>]`."""
|
"""The label filters of a workflow step's docker commands, as `--filter label=<key>[=<value>]`."""
|
||||||
workflow = yaml.safe_load(WORKFLOW.read_text())
|
workflow = yaml.safe_load(WORKFLOW.read_text())
|
||||||
steps = [s for job in workflow["jobs"].values() for s in job.get("steps", [])]
|
steps = [s for job in workflow["jobs"].values() for s in job.get("steps", [])]
|
||||||
runs = "\n".join(s.get("run", "") for s in steps)
|
run = next(s["run"] for s in steps if s.get("name") == step_name)
|
||||||
return re.findall(r"--filter ['\"]?label=([^'\"\s]+)", runs)
|
return re.findall(r"--filter ['\"]?label=([^'\"\s]+)", run)
|
||||||
|
|
||||||
|
|
||||||
class ScenarioPlatformsTest(unittest.TestCase):
|
class ScenarioPlatformsTest(unittest.TestCase):
|
||||||
@@ -392,10 +392,14 @@ class ScenarioPlatformsTest(unittest.TestCase):
|
|||||||
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
|
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
|
||||||
|
|
||||||
def test_the_workflow_finds_the_containers_by_the_run_label(self):
|
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
|
# the sweep of earlier runs filters by the key, the cleanup of this run by key and value
|
||||||
self.assertIn(RUN_LABEL, filters)
|
self.assertEqual(
|
||||||
self.assertIn(f"{RUN_LABEL}=$KAMINO_RUN_ID", filters)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user