-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mauro Eijsenring
authored and
Mauro Eijsenring
committed
Sep 10, 2024
1 parent
779e963
commit d0cafcd
Showing
2 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# Function to delete old tags for a given repository | ||
delete_old_tags() { | ||
local repo="$1" | ||
echo "Processing repository: $repo" | ||
|
||
# List tags and filter for SHA-based tags, excluding the most recent 5 | ||
SHA_TAGS=$(doctl registry repository list-tags "$repo" --format Tag --no-header | grep -E '^sha' | sort -r | tail -n +6) | ||
|
||
# Delete each old SHA-based tag | ||
while IFS= read -r tag; do | ||
echo "Deleting tag: $tag from repository: $repo" | ||
doctl registry repository delete-manifest "$repo" "$tag" --force | ||
done <<< "$SHA_TAGS" | ||
} | ||
|
||
# List all repositories in the registry | ||
REPOS=$(doctl registry repository list --format Name --no-header) | ||
|
||
# Process each repository | ||
while IFS= read -r repo; do | ||
delete_old_tags "$repo" | ||
done <<< "$REPOS" | ||
|
||
echo "Cleanup completed." |