-
-
Notifications
You must be signed in to change notification settings - Fork 97
37 lines (30 loc) · 1.14 KB
/
cleanup-images.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 }}