51 lines
1.9 KiB
Bash
51 lines
1.9 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# Configuration
|
|
REGISTRY_DATA="/mnt/HC_Volume_104575103/registry-data/docker/registry/v2"
|
|
KEEP_TAGS=3
|
|
|
|
echo "🏥 Starting Aggressive Mintel Infrastructure Optimization..."
|
|
|
|
# 1. Prune Registry Tags (Filesystem level)
|
|
if [ -d "$REGISTRY_DATA" ]; then
|
|
echo "🔍 Processing Registry tags..."
|
|
for repo_dir in "$REGISTRY_DATA/repositories/mintel/"*; do
|
|
[ -e "$repo_dir" ] || continue
|
|
repo_name=$(basename "$repo_dir")
|
|
|
|
# EXCLUDE base images from pruning to prevent breaking downstream builds
|
|
if [[ "$repo_name" == "runtime" || "$repo_name" == "nextjs" || "$repo_name" == "gatekeeper" ]]; then
|
|
echo " 🛡️ Skipping protected repository: mintel/$repo_name"
|
|
continue
|
|
fi
|
|
|
|
tags_dir="$repo_dir/_manifests/tags"
|
|
|
|
if [ -d "$tags_dir" ]; then
|
|
echo " 📦 Pruning mintel/$repo_name..."
|
|
# Note: keeping latest and up to KEEP_TAGS of each pattern
|
|
PATTERNS=("main-*" "testing-*" "branch-*" "v*" "rc*" "[0-9a-f]*")
|
|
for pattern in "${PATTERNS[@]}"; do
|
|
find "$tags_dir" -maxdepth 1 -name "$pattern" -print0 2>/dev/null | xargs -0 ls -dt 2>/dev/null | tail -n +$((KEEP_TAGS + 1)) | xargs rm -rf 2>/dev/null || true
|
|
done
|
|
rm -rf "$tags_dir/buildcache"* 2>/dev/null || true
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# 2. Registry Garbage Collection
|
|
REGISTRY_CONTAINER=$(docker ps --format "{{.Names}}" | grep registry | head -1 || true)
|
|
if [ -n "$REGISTRY_CONTAINER" ]; then
|
|
echo "♻️ Running Registry GC..."
|
|
docker exec "$REGISTRY_CONTAINER" bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged || true
|
|
fi
|
|
|
|
# 3. Global Docker Pruning
|
|
echo "🧹 Pruning Docker resources..."
|
|
docker system prune -af --filter "until=24h"
|
|
docker volume prune -f
|
|
|
|
echo "✅ Optimization complete!"
|
|
df -h /mnt/HC_Volume_104575103
|