#!/bin/bash set -e # Configuration REGISTRY_DATA="/opt/infra/registry/data/docker/registry/v2" KEEP_TAGS=3 echo "๐Ÿฅ Starting Aggressive Registry & Docker Maintenance..." # 1. Prune Registry Tags (Filesystem level) for repo_dir in "$REGISTRY_DATA/repositories/mintel/"*; do repo_name=$(basename "$repo_dir") tags_dir="$repo_dir/_manifests/tags" if [ -d "$tags_dir" ]; then echo "๐Ÿ” Processing repository: mintel/$repo_name" # Prune main-* tags echo " ๐Ÿ“ฆ Pruning main tags..." main_tags=$(ls -dt "$tags_dir"/main-* 2>/dev/null || true) count=0 for tag_path in $main_tags; do ((++count)) if [ $count -gt $KEEP_TAGS ]; then echo " ๐Ÿ—‘๏ธ Deleting old main tag: $(basename "$tag_path")" rm -rf "$tag_path" fi done # Prune version tags (v* and rc*) echo " ๐Ÿท๏ธ Pruning version tags..." version_tags=$(ls -dt "$tags_dir"/v1* 2>/dev/null || true) count=0 for tag_path in $version_tags; do ((++count)) if [ $count -gt $KEEP_TAGS ]; then echo " ๐Ÿ—‘๏ธ Deleting old version tag: $(basename "$tag_path")" rm -rf "$tag_path" fi done # Always prune buildcache (as it rebuilds quickly) if [ -d "$tags_dir/buildcache" ]; then echo " ๐Ÿงน Deleting buildcache tag" rm -rf "$tags_dir/buildcache" fi fi done # 2. Run Garbage Collection echo "โ™ป๏ธ Running Registry Garbage Collection..." docker exec registry-registry-1 bin/registry garbage-collect /etc/docker/registry/config.yml # 3. Prune Host Docker resources (Shorter window: 24h) echo "๐Ÿงน Pruning Host Docker resources..." docker system prune -af --filter "until=24h" docker volume prune -f echo "โœ… Maintenance complete!" df -h /