ci: add maintenance workflow (#643) [skip ci]
This commit is contained in:
committed by
GitHub
parent
7657cc588d
commit
3b2f2ae71a
33
.github/workflows/maintenance/delete_ghcr_dangling_images.sh
vendored
Executable file
33
.github/workflows/maintenance/delete_ghcr_dangling_images.sh
vendored
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Simple script to remove dangling images from GHCR
|
||||
# You need to be logged to 'gh' first.
|
||||
|
||||
# package_name syntax. i.e: jellyfin-vue
|
||||
container="$1"
|
||||
temp_file="ghcr_prune.ids"
|
||||
rm -rf $temp_file
|
||||
|
||||
echo "Fetching dangling images from GHCR..."
|
||||
gh api /user/packages/container/${container}/versions --paginate > $temp_file
|
||||
|
||||
ids_to_delete=$(cat "$temp_file" | jq -r '.[] | select(.metadata.container.tags==[]) | .id')
|
||||
|
||||
if [ "${ids_to_delete}" = "" ]
|
||||
then
|
||||
echo "There are no dangling images to remove for this package"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -e "\nDeleting dangling images..."
|
||||
while read -r line; do
|
||||
id="$line"
|
||||
## Workaround for https://github.com/cli/cli/issues/4286 and https://github.com/cli/cli/issues/3937
|
||||
echo -n | gh api --method DELETE /user/packages/container/${container}/versions/${id} --input -
|
||||
echo Dangling image with ID $id deleted successfully
|
||||
done <<< $ids_to_delete
|
||||
|
||||
rm -rf $temp_file
|
||||
echo -e "\nAll the dangling images have been removed successfully"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user