GRM-167: fix: restrict healthcheck disk cleanup to exited/dead containers
This commit was merged in pull request #274.
This commit is contained in:
@@ -112,6 +112,8 @@
|
||||
- "'docker network prune' in healthcheck_script.content | b64decode"
|
||||
- "'status=removing' in healthcheck_script.content | b64decode"
|
||||
- "'status=stopping' in healthcheck_script.content | b64decode"
|
||||
- "'status=exited' in healthcheck_script.content | b64decode"
|
||||
- "'status=dead' in healthcheck_script.content | b64decode"
|
||||
- "gitea_runner_healthcheck_disk_threshold | string in healthcheck_script.content | b64decode"
|
||||
- "gitea_runner_healthcheck_disk_critical | string in healthcheck_script.content | b64decode"
|
||||
fail_msg: "Healthcheck script template is missing expected content"
|
||||
|
||||
@@ -227,9 +227,12 @@ if [[ "$disk_pct" -ge {{ gitea_runner_healthcheck_disk_critical }} ]]; then
|
||||
echo "CRITICAL: Disk usage at ${disk_pct}% (>= {{ gitea_runner_healthcheck_disk_critical }}%), full prune"
|
||||
# Critical level: remove ALL stopped containers (no age filter) and ALL
|
||||
# unused images/volumes. The until=1h gentle prune is insufficient here.
|
||||
# Stop+rm stale non-CI containers regardless of age (failed molecule tests
|
||||
# from the last 59 minutes also consume disk).
|
||||
docker ps -a --format '{% raw %}{{.ID}} {{.Names}}{% endraw %}' 2>/dev/null \
|
||||
# Implements: REQ-1 (GRM-167) — only exited/dead containers are removed.
|
||||
# Running molecule instances are never killed: RunningFor counts creation
|
||||
# time, so an adopted stale instance looks old; and a running container's
|
||||
# writable layer is tiny — images/volumes are what actually fills the disk.
|
||||
docker ps -a --filter "status=exited" --filter "status=dead" \
|
||||
--format '{% raw %}{{.ID}} {{.Names}}{% endraw %}' 2>/dev/null \
|
||||
| grep -v 'GITEA-ACTIONS-TASK' \
|
||||
| awk '{print $1}' \
|
||||
| xargs -r docker rm -f 2>/dev/null || true
|
||||
@@ -240,13 +243,16 @@ if [[ "$disk_pct" -ge {{ gitea_runner_healthcheck_disk_critical }} ]]; then
|
||||
echo "INFO: Disk usage after full prune: ${disk_pct}%"
|
||||
elif [[ "$disk_pct" -ge {{ gitea_runner_healthcheck_disk_threshold }} ]]; then
|
||||
echo "WARN: Disk usage at ${disk_pct}%, pruning runner resources (until=1h)"
|
||||
# Force-remove stale containers (including running ones from failed molecule tests)
|
||||
# that are older than 1 hour. "docker container prune -f" only removes stopped
|
||||
# containers, so running containers from crashed CI jobs accumulate and consume
|
||||
# disk/memory. Exclude CI job containers (name starts with GITEA-ACTIONS-TASK).
|
||||
# Only remove containers older than 1 hour to avoid killing molecule test
|
||||
# containers that CI jobs are actively using.
|
||||
docker ps -a --format '{% raw %}{{.ID}} {{.Names}} {{.RunningFor}}{% endraw %}' 2>/dev/null \
|
||||
# Force-remove stale stopped containers older than 1 hour.
|
||||
# Implements: REQ-1 (GRM-167) — only exited/dead containers are removed.
|
||||
# A running molecule instance must never be janitor-killed: RunningFor
|
||||
# measures creation time, so a stale instance restarted by an active run
|
||||
# looks ">1h old" and would die mid-converge ("No such container",
|
||||
# infra nightly run 5710). Running leftovers are reused or destroyed by
|
||||
# the next molecule create/destroy cycle.
|
||||
# Exclude CI job containers (name starts with GITEA-ACTIONS-TASK).
|
||||
docker ps -a --filter "status=exited" --filter "status=dead" \
|
||||
--format '{% raw %}{{.ID}} {{.Names}} {{.RunningFor}}{% endraw %}' 2>/dev/null \
|
||||
| grep -v 'GITEA-ACTIONS-TASK' \
|
||||
| grep -E '(hour|day|week|month|year)s? ago' \
|
||||
| awk '{print $1}' \
|
||||
|
||||
Reference in New Issue
Block a user