diff --git a/ansible/roles/gitea_runner/templates/docker-prune.service.j2 b/ansible/roles/gitea_runner/templates/docker-prune.service.j2 index 208c8c0..ce23d43 100644 --- a/ansible/roles/gitea_runner/templates/docker-prune.service.j2 +++ b/ansible/roles/gitea_runner/templates/docker-prune.service.j2 @@ -13,5 +13,8 @@ Environment=XDG_RUNTIME_DIR=/run/user/{{ gitea_runner_uid }} # them kills the active CI job and causes "RWLayer is unexpectedly nil" errors. ExecStart=/bin/sh -c 'docker ps -a --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' ExecStart=/usr/bin/docker system prune -af --filter "until={{ gitea_runner_prune_until }}" --volumes -ExecStart=/usr/bin/docker network prune -f +# Prune networks older than the prune-until threshold to avoid removing +# networks that molecule tests are actively creating (e.g. 'traefik' network +# created during molecule create phase before containers are attached). +ExecStart=/usr/bin/docker network prune -f --filter "until={{ gitea_runner_prune_until }}" ExecStart=/usr/bin/docker builder prune -f diff --git a/ansible/roles/gitea_runner/templates/runner-healthcheck.sh.j2 b/ansible/roles/gitea_runner/templates/runner-healthcheck.sh.j2 index 2e4ba95..88ba20b 100644 --- a/ansible/roles/gitea_runner/templates/runner-healthcheck.sh.j2 +++ b/ansible/roles/gitea_runner/templates/runner-healthcheck.sh.j2 @@ -234,7 +234,10 @@ if [[ "$disk_pct" -ge {{ gitea_runner_healthcheck_disk_threshold }} ]]; then | awk '{print $1}' \ | xargs -r docker rm -f 2>/dev/null || true docker system prune -af --filter "until=1h" --volumes || true - docker network prune -f || true + # Prune networks older than 1 hour to avoid removing networks that + # molecule tests are actively creating (e.g. 'traefik' network created + # during molecule create phase before containers are attached). + docker network prune -f --filter "until=1h" || true disk_pct=$(df -P / | awk 'NR==2 {gsub(/%/, "", $5); print $5}') echo "INFO: Disk usage after prune: ${disk_pct}%" fi