DigitalOcean Cleanup Images #2565
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
name: DigitalOcean Cleanup Images | |
on: | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: "0 17 * * *" | |
workflow_dispatch: | |
jobs: | |
cleanup: | |
name: Cleanup Docker Images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v4 | |
- name: Install doctl 🌊 | |
uses: digitalocean/action-doctl@v2.5.1 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_TOKEN }} | |
- name: Authenticate to DigitalOcean 🔐 | |
run: doctl registry login --expiry-seconds 600 | |
- name: Delete old images 🧹 | |
run: |- | |
DIGESTS=$(doctl registry repository list-tags ${{ secrets. DIGITALOCEAN_APP_NAME }} -o json | jq -r "sort_by(.updated_at) | reverse | .[10:] | .[] | .manifest_digest" | tr '\n' ' ') | |
[[ -n "$DIGESTS" ]] && doctl registry repository delete-manifest --force ${{ secrets. DIGITALOCEAN_APP_NAME }} $DIGESTS | |
echo "Done" | |
- name: Run garbage collection 🗑 | |
if: ${{ github.event_name == 'schedule' }} | |
run: |- | |
doctl registry garbage-collection start --include-untagged-manifests --force ${{ secrets.DIGITALOCEAN_REGISTRY }} |