From 33b89cb48407fb9f6c3d77c3abd600a8c7c85fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 12 Jun 2026 17:08:55 +0200 Subject: [PATCH] Add staging reaper for timetracker branch deployments Removes timetracker staging containers/volumes/images whose branch no longer exists on Gitea. Backstop for missed branch-delete events from the staging workflow in the timetracker repo. Co-Authored-By: Claude Fable 5 --- scripts/staging-reaper.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 scripts/staging-reaper.sh diff --git a/scripts/staging-reaper.sh b/scripts/staging-reaper.sh new file mode 100755 index 0000000..2b49120 --- /dev/null +++ b/scripts/staging-reaper.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Removes timetracker staging containers (deployed by .gitea/workflows/staging.yml +# in the timetracker repo) whose branch no longer exists on Gitea. +# Backstop for missed branch-delete events; safe to run any time. +set -euo pipefail + +API="https://git.kucharczyk.xyz/api/v1/repos/lukas/timetracker/branches?limit=50" + +# If the API is unreachable, set -e aborts here and nothing gets reaped. +branches=$(curl -fsS "$API" | python3 -c 'import json,sys; print("\n".join(b["name"] for b in json.load(sys.stdin)))') + +docker ps -a --filter label=xyz.kucharczyk.staging=timetracker --format '{{.Names}}' | while read -r name; do + branch=$(docker inspect "$name" --format '{{ index .Config.Labels "xyz.kucharczyk.staging.branch" }}') + if ! grep -qxF "$branch" <<<"$branches"; then + image=$(docker inspect "$name" --format '{{ .Config.Image }}') + docker rm -f "$name" >/dev/null + docker volume rm "$name" >/dev/null 2>&1 || true + docker rmi "$image" >/dev/null 2>&1 || true + echo "reaped ${name} (branch '${branch}' no longer exists)" + fi +done