cleanup action
This commit is contained in:
parent
75569b3b3b
commit
424b8c1ac2
1 changed files with 39 additions and 0 deletions
39
.forgejo/workflows/cleanup.yml
Normal file
39
.forgejo/workflows/cleanup.yml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
name: Ryd op i Forgejo Container Registry
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0' # Kører hver søndag ved midnat
|
||||
workflow_dispatch: # Gør det muligt at køre den manuelt
|
||||
|
||||
jobs:
|
||||
delete-old-images:
|
||||
runs-on: almalinux-10
|
||||
steps:
|
||||
- name: Slet gamle versioner
|
||||
run: |
|
||||
REGISTRY="forge.pc-rytteren.dk"
|
||||
OWNER="${{ github.repository_owner }}"
|
||||
IMAGE="my-ostree-os"
|
||||
MIN_KEEP=50
|
||||
TOKEN="${{ secrets.PACKAGE_TOKEN }}"
|
||||
|
||||
# Hent alle tags for imaget via Forgejo API
|
||||
TAGS=$(curl -s -H "Authorization: token ${TOKEN}" \
|
||||
"https://${REGISTRY}/api/v1/packages/${OWNER}/container/${IMAGE}/tags" \
|
||||
| tr ',' '\n' | grep '"name"' | sed 's/.*"name":"\([^"]*\)".*/\1/' | sort -r)
|
||||
|
||||
TOTAL=$(echo "$TAGS" | wc -l)
|
||||
echo "Fundet ${TOTAL} tags totalt, beholder ${MIN_KEEP}"
|
||||
|
||||
if [ "$TOTAL" -le "$MIN_KEEP" ]; then
|
||||
echo "Ingen tags at slette"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Slet tags ud over MIN_KEEP (ældste først)
|
||||
TO_DELETE=$(echo "$TAGS" | tail -n +$((MIN_KEEP + 1)))
|
||||
for TAG in $TO_DELETE; do
|
||||
echo "Sletter tag: ${TAG}"
|
||||
curl -s -X DELETE -H "Authorization: token ${TOKEN}" \
|
||||
"https://${REGISTRY}/api/v1/packages/${OWNER}/container/${IMAGE}/${TAG}"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue