Clear registry script sort tags
This commit is contained in:
@@ -117,15 +117,15 @@ fi
|
|||||||
echo "🔍 Fetching list of tags for $1..."
|
echo "🔍 Fetching list of tags for $1..."
|
||||||
echo "📦 Will keep $KEEP_TAGS recent tags (excluding latest)"
|
echo "📦 Will keep $KEEP_TAGS recent tags (excluding latest)"
|
||||||
|
|
||||||
# Fetch all 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[]')
|
allTags=$(skopeo list-tags docker://"$1" 2>/dev/null | jq -r '.Tags[]' | sort)
|
||||||
|
|
||||||
if [ -z "$allTags" ]; then
|
if [ -z "$allTags" ]; then
|
||||||
echo "❌ Error: could not fetch tag list or repository is empty"
|
echo "❌ Error: could not fetch tag list or repository is empty"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Count total number of tags
|
# Count total number of tags2
|
||||||
totalTags=$(echo "$allTags" | wc -l)
|
totalTags=$(echo "$allTags" | wc -l)
|
||||||
|
|
||||||
# Determine how many tags to delete
|
# Determine how many tags to delete
|
||||||
@@ -138,7 +138,7 @@ if [ "$tagsToDelete" -le 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Get tags to delete (exclude latest and keep KEEP_TAGS recent ones)
|
# 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 "📊 Total tags: $totalTags (including latest)"
|
||||||
echo "🗑️ Will be deleted: $(echo "$oldTags" | wc -l) tags"
|
echo "🗑️ Will be deleted: $(echo "$oldTags" | wc -l) tags"
|
||||||
|
|||||||
Reference in New Issue
Block a user