diff --git a/clear-registry b/clear-registry index f609a18..3221bc5 100644 --- a/clear-registry +++ b/clear-registry @@ -117,15 +117,15 @@ fi echo "🔍 Fetching list of tags for $1..." echo "📦 Will keep $KEEP_TAGS recent tags (excluding latest)" -# Fetch all tags -allTags=$(skopeo list-tags docker://"$1" 2>/dev/null | jq -r '.Tags[]') +# Fetch all tags (sorted alphabetically, which is chronological for YYYYMMDDHHMMSS-hash format) +allTags=$(skopeo list-tags docker://"$1" 2>/dev/null | jq -r '.Tags[]' | sort) if [ -z "$allTags" ]; then echo "❌ Error: could not fetch tag list or repository is empty" exit 1 fi -# Count total number of tags +# Count total number of tags2 totalTags=$(echo "$allTags" | wc -l) # Determine how many tags to delete @@ -138,7 +138,7 @@ if [ "$tagsToDelete" -le 0 ]; then fi # Get tags to delete (exclude latest and keep KEEP_TAGS recent ones) -oldTags=$(echo "$allTags" | grep -v "latest" | sort | head -n -"$KEEP_TAGS") +oldTags=$(echo "$allTags" | grep -v "latest" | head -n -"$KEEP_TAGS") echo "📊 Total tags: $totalTags (including latest)" echo "🗑️ Will be deleted: $(echo "$oldTags" | wc -l) tags"