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