Skip to content

Commit

Permalink
Clean docker images (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Feb 15, 2025
1 parent 3a66f03 commit 5d70263
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,26 @@ jobs:
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
push: false

cleanup-ghcr-images:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Cleanup old GHCR images
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ghcr_images=$(gh api -H "Accept: application/vnd.github.v3+json" /orgs/gnosis/packages/container/mech-tool-deployment/versions | jq -r '.[] | select(.created_at < (now - 86400 | todate)) | .id')
for image_id in $ghcr_images; do
tags=$(gh api -H "Accept: application/vnd.github.v3+json" /orgs/gnosis/packages/container/mech-tool-deployment/versions/$image_id | jq -r '.metadata.container.tags[]')
if [[ ! " ${tags[@]} " =~ " main " ]]; then
echo "Deleting image with ID: $image_id"
gh api --silent --method DELETE "/orgs/gnosis/packages/container/mech-tool-deployment/versions/$image_id"
else
echo "Skipping image with ID: $image_id as it is tagged as main"
fi
done

0 comments on commit 5d70263

Please sign in to comment.