ci: prune old build-NNN images and stale build cache after deploy
Some checks failed
Build & Deploy / build-and-deploy (push) Has been cancelled
Some checks failed
Build & Deploy / build-and-deploy (push) Has been cancelled
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user