45 lines
1.4 KiB
Bash
45 lines
1.4 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# Configuration
|
|
REGISTRY_DATA="/opt/infra/registry/data/docker/registry/v2"
|
|
KEEP_TAGS=5
|
|
|
|
echo "🏥 Starting Registry & Docker Maintenance..."
|
|
|
|
# 1. Prune Registry Tags (Filesystem level)
|
|
# This identifies main-* tags and keeps only the latest N
|
|
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"
|
|
|
|
# Get main-* tags sorted by modification time (newest first)
|
|
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 tag: $(basename "$tag_path")"
|
|
rm -rf "$tag_path"
|
|
fi
|
|
done
|
|
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
|
|
echo "🧹 Pruning Host Docker resources..."
|
|
# Separate prune commands because --filter and --volumes can be incompatible on some versions
|
|
docker system prune -af --filter "until=168h"
|
|
docker volume prune -f
|
|
|
|
echo "✅ Maintenance complete!"
|
|
df -h /
|