in english
This commit is contained in:
parent
b5aa207c26
commit
568b25889c
1 changed files with 11 additions and 11 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
name: Ryd op i Forgejo Container Registry
|
name: Clean up Forgejo Container Registry
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * 0' # Kører hver søndag ved midnat
|
- cron: '0 0 * * 0' # Runs every Sunday at midnight
|
||||||
workflow_dispatch: # Gør det muligt at køre den manuelt
|
workflow_dispatch: # Allows manual triggering
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
delete-old-images:
|
delete-old-images:
|
||||||
runs-on: almalinux-10
|
runs-on: almalinux-10
|
||||||
steps:
|
steps:
|
||||||
- name: Slet gamle versioner
|
- name: Delete old versions
|
||||||
run: |
|
run: |
|
||||||
REGISTRY="forge.pc-rytteren.dk"
|
REGISTRY="forge.pc-rytteren.dk"
|
||||||
OWNER="${{ github.repository_owner }}"
|
OWNER="${{ github.repository_owner }}"
|
||||||
|
|
@ -17,27 +17,27 @@ jobs:
|
||||||
MIN_KEEP=50
|
MIN_KEEP=50
|
||||||
TOKEN="${{ secrets.PACKAGE_TOKEN }}"
|
TOKEN="${{ secrets.PACKAGE_TOKEN }}"
|
||||||
|
|
||||||
# Hent alle pakker af typen container med dette navn, sorteret ældste først (via id)
|
# Fetch all container packages with this name, sorted oldest first (by id)
|
||||||
# API returnerer en liste af package-objekter, hvert med "id" og "version"
|
# API returns a list of package objects, each with "id" and "version"
|
||||||
RAW=$(curl -s -H "Authorization: token ${TOKEN}" \
|
RAW=$(curl -s -H "Authorization: token ${TOKEN}" \
|
||||||
"https://${REGISTRY}/api/v1/packages/${OWNER}?type=container&q=${IMAGE}&limit=200")
|
"https://${REGISTRY}/api/v1/packages/${OWNER}?type=container&q=${IMAGE}&limit=200")
|
||||||
|
|
||||||
# Filtrer kun pakker med korrekt navn og udtræk id + created_at, sorter ældste først
|
# Filter only packages with the correct name and extract id, sort oldest first
|
||||||
IDS=$(echo "$RAW" | tr '{' '\n' | grep "\"name\":\"${IMAGE}\"" | \
|
IDS=$(echo "$RAW" | tr '{' '\n' | grep "\"name\":\"${IMAGE}\"" | \
|
||||||
sed 's/.*"id":\([0-9]*\).*/\1/' | sort -n)
|
sed 's/.*"id":\([0-9]*\).*/\1/' | sort -n)
|
||||||
|
|
||||||
TOTAL=$(echo "$IDS" | grep -c '[0-9]' || true)
|
TOTAL=$(echo "$IDS" | grep -c '[0-9]' || true)
|
||||||
echo "Fundet ${TOTAL} pakker totalt, beholder ${MIN_KEEP}"
|
echo "Found ${TOTAL} packages total, keeping ${MIN_KEEP}"
|
||||||
|
|
||||||
if [ "$TOTAL" -le "$MIN_KEEP" ]; then
|
if [ "$TOTAL" -le "$MIN_KEEP" ]; then
|
||||||
echo "Ingen pakker at slette"
|
echo "No packages to delete"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Slet de ældste (laveste id'er) ud over MIN_KEEP
|
# Delete the oldest (lowest ids) beyond MIN_KEEP
|
||||||
TO_DELETE=$(echo "$IDS" | head -n $(( TOTAL - MIN_KEEP )))
|
TO_DELETE=$(echo "$IDS" | head -n $(( TOTAL - MIN_KEEP )))
|
||||||
for ID in $TO_DELETE; do
|
for ID in $TO_DELETE; do
|
||||||
echo "Sletter pakke id: ${ID}"
|
echo "Deleting package id: ${ID}"
|
||||||
curl -s -X DELETE -H "Authorization: token ${TOKEN}" \
|
curl -s -X DELETE -H "Authorization: token ${TOKEN}" \
|
||||||
"https://${REGISTRY}/api/v1/packages/${OWNER}/${ID}"
|
"https://${REGISTRY}/api/v1/packages/${OWNER}/${ID}"
|
||||||
done
|
done
|
||||||
Loading…
Add table
Add a link
Reference in a new issue