Skip to content

Commit

Permalink
update deletion of old registers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Eijsenring authored and Mauro Eijsenring committed Sep 10, 2024
1 parent 779e963 commit d0cafcd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/chicmoz-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ jobs:
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 600

- name: Remove all old images
run: if [ ! -z "$(doctl registry repository list | grep "$(echo $IMAGE_NAME)")" ]; then doctl registry repository delete-manifest $(echo $IMAGE_NAME) $(doctl registry repository list-tags $(echo $IMAGE_NAME) | grep -o "sha.*") --force; else echo "No repository"; fi
- name: Cleanup old images
run: |
chmod +x "./cleanup-script.sh"
"./cleanup-script.sh"
- name: Save DigitalOcean kubeconfig
run: doctl kubernetes cluster kubeconfig save chicmoz-prod
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/cleanup-script.sh
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."

0 comments on commit d0cafcd

Please sign in to comment.