ci(molecule): check container removal by listing what is left
A removal that fails because another run's sweep was first is harmless, but checking that with `docker container inspect` also passed when the daemon could not be reached. Both removal steps now remove what they can and then list the containers they meant to remove; a failing list or a container still listed fails the step. The workflow rules name the test that holds the sweep's age bound to the job timeout. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
3726b5c53f
commit
1885b3fe99
3 files changed
+20
-16
No files matched your search
@@ -98,16 +98,20 @@ jobs:
|
||||
# The job's timeout-minutes (a script test holds them equal): a shorter bound would remove a
|
||||
# live run's containers.
|
||||
cutoff="$(date -d '30 minutes ago' +%s)"
|
||||
old=""
|
||||
for id in $ids; do
|
||||
# a container removed since the listing, by its run or another run's sweep, is skipped
|
||||
created="$(docker inspect --format '{{.Created}}' "$id")" || continue
|
||||
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
|
||||
if [ "$created" -lt "$cutoff" ]; then
|
||||
old="$old $id"
|
||||
docker rm -f "$id" >/dev/null || true
|
||||
fi
|
||||
done
|
||||
# A removal may fail because another run's sweep was first; only one still listed counts.
|
||||
left=""
|
||||
for id in $old; do left="$left$(docker ps -aq --filter "id=$id")"; done
|
||||
if [ -n "$left" ]; then echo "::error::could not remove ${left//$'\n'/ }"; exit 1; fi
|
||||
|
||||
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
||||
# explains the rules); the nightly run and a manual dispatch run all of them, a few at a time.
|
||||
@@ -159,10 +163,8 @@ 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=$KAMINO_RUN_ID")"
|
||||
for id in $ids; do
|
||||
# another run's sweep may have removed it first, once this run passed its timeout
|
||||
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 removal may fail because another run's sweep was first, once this run passed its
|
||||
# timeout; only a container still listed counts.
|
||||
for id in $ids; do docker rm -f "$id" >/dev/null || true; done
|
||||
left="$(docker ps -aq --filter "label=net.rkdr.mortis.molecule-run=$KAMINO_RUN_ID")"
|
||||
if [ -n "$left" ]; then echo "::error::could not remove ${left//$'\n'/ }"; exit 1; fi
|
||||
Reference in new issue
Block a user