fix: prune stale Docker images and build cache after each deploy

Adds a post-deploy step that removes Docker images and build cache
older than 24 hours. Prevents the gradual disk bloat from repeated
docker compose --build invocations (was 71GB on the Pi).
This commit is contained in:
Jannis Braun
2026-03-26 03:31:52 +01:00
parent c5188c1702
commit 2b2f64e7f9
+5 -1
View File
@@ -70,10 +70,14 @@ deploy() {
./ "$PI_USER@$host:$path"
# Rebuild
echo " [3/3] Building and restarting..."
echo " [3/4] Building and restarting..."
# Clean up stale renamed containers left by failed recreates (e.g. "d420a6c00439_backspace")
ssh "$PI_USER@$host" "cd $path && docker rm -f \$(docker ps -aq --filter 'name=_backspace' 2>/dev/null) 2>/dev/null; docker compose up -d --build"
# Prune old images and build cache to prevent disk bloat
echo " [4/4] Pruning stale Docker data..."
ssh "$PI_USER@$host" "docker image prune -af --filter 'until=24h' 2>/dev/null; docker builder prune -af --filter 'until=24h' 2>/dev/null" || true
echo ""
echo " Done: $name"
}