From caeaf51db4886d76f082cb2c1155d46555583e24 Mon Sep 17 00:00:00 2001 From: Chaim Date: Sat, 6 Jun 2026 17:31:28 +0000 Subject: [PATCH] ci: prune old build-NNN images and stale build cache after deploy Old build-NNN tags accumulated in the shared host /var/lib/docker (~1.3GB each, 24 builds = ~30GB) and filled the disk to 100%. Keep the newest 5 build tags, drop dangling images, and prune build cache older than 72h on every run. Co-Authored-By: Claude Opus 4.8 (1M context) --- .gitea/workflows/deploy.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index bc0b762..f632aa5 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -56,3 +56,23 @@ jobs: curl -sf \ "http://coolify:8080/api/v1/deploy?uuid=gyjo0mtw2c42ej3xxvbz8zio&force=true" \ -H "Authorization: Bearer ${{ secrets.COOLIFY_TOKEN }}" + + - name: Prune old build images and cache + if: always() + run: | + BASE="${{ env.REGISTRY }}/${{ env.IMAGE }}" + KEEP=5 + # Keep the newest $KEEP build-NNN tags; remove the rest. + # The build daemon is the shared host daemon, so these images + # otherwise accumulate in /var/lib/docker (~1.3GB each). + docker images "${BASE}" --format '{{.Tag}}' \ + | grep -E '^build-[0-9]+$' \ + | sort -t- -k2 -nr \ + | tail -n +$((KEEP + 1)) \ + | while read -r tag; do + echo "🗑️ Removing ${BASE}:${tag}" + docker rmi "${BASE}:${tag}" || true + done + # Dangling images + build cache older than 72h (keeps recent layers warm) + docker image prune -f || true + docker builder prune -f --filter 'until=72h' || true