Docker images : Nightly image cleanup - update workflow file
This commit is contained in:
13
.github/workflows/docker-nightly-cleanup.yml
vendored
13
.github/workflows/docker-nightly-cleanup.yml
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
name: Cleanup old nightly docker images
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '10 0 * * *'
|
- cron: '10 0 * * *'
|
||||||
@@ -6,7 +8,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
delete-package-versions:
|
delete-package-versions:
|
||||||
name: Delete old nightly docker images
|
name: Cleanup old nightly docker images
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Get list of all docker image versions in registry
|
- name: Get list of all docker image versions in registry
|
||||||
@@ -16,12 +18,14 @@ jobs:
|
|||||||
gh api --paginate -X GET "/orgs/Kozea/packages/container/Radicale/versions" -F package_type=container -F per_page=200 > data.json
|
gh api --paginate -X GET "/orgs/Kozea/packages/container/Radicale/versions" -F package_type=container -F per_page=200 > data.json
|
||||||
|
|
||||||
- name: Delete each nightly image older than cutoff date
|
- name: Delete each nightly image older than cutoff date
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
cutoff_date=$(date --date="30 days ago" --iso-8601)
|
cutoff_date=$(date --date="30 days ago" --iso-8601)
|
||||||
echo "Cutoff date is: $cutoff_date"
|
echo "Cutoff date is: $cutoff_date"
|
||||||
|
|
||||||
# Loop through each nightly container version (tag) older than the cutoff date
|
# Loop through each nightly image version (tag) older than the cutoff date
|
||||||
for tag in $(jq --arg cutoff_date $cutoff_date -r '.[] | select((.metadata.container.tags | any(. | contains("nightly"))) and (.created_at < $cutoff_date)) | .metadata.container.tags[]' data.json); do
|
jq --arg cutoff_date "$cutoff_date" -r '.[] | select((.metadata.container.tags | any(. | contains("nightly"))) and (.created_at < $cutoff_date)) | [.metadata.container.tags[], .id] | @tsv' data.json | while IFS=$'\t' read -r tag nightly_image_id ; do
|
||||||
echo "Tag - $tag"
|
echo "Tag - $tag"
|
||||||
|
|
||||||
# Because of multi-platform, manifest for each tag would contain more than 1 image. Loop through all
|
# Because of multi-platform, manifest for each tag would contain more than 1 image. Loop through all
|
||||||
@@ -31,4 +35,7 @@ jobs:
|
|||||||
echo "Deleting $image_id"
|
echo "Deleting $image_id"
|
||||||
gh api -X DELETE "/orgs/Kozea/packages/container/Radicale/versions/$image_id"
|
gh api -X DELETE "/orgs/Kozea/packages/container/Radicale/versions/$image_id"
|
||||||
done
|
done
|
||||||
|
# Now that all dependents are deleted, delete this tag
|
||||||
|
echo "Deleting $tag with ID: $nightly_image_id"
|
||||||
|
gh api -X DELETE "/orgs/Kozea/packages/container/Radicale/versions/$nightly_image_id"
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user