Skip to content

Delete old container images #581

Delete old container images

Delete old container images #581

Workflow file for this run

name: Delete old container images
on:
schedule:
- cron: "0 0 * * *" # every day at midnight
workflow_dispatch:
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set target tags
id: set-tags-matrix
run: |
TAGS_JSON=$(ls Dockerfiles | jq -cnR '[inputs | select(length>0)]')
echo "matrix=$TAGS_JSON" >> $GITHUB_OUTPUT
echo "### Discovered Containers :whale:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for title in $(echo $TAGS_JSON | jq -r '.[]'); do
echo "* $title" | tr '-' ' ' >> $GITHUB_STEP_SUMMARY
done
outputs:
matrix: ${{ steps.set-tags-matrix.outputs.matrix }}
clean-ghcr:
name: Cleanup
runs-on: ubuntu-latest
needs: [prepare]
steps:
- name: Untagged Images (> 1 day)
id: untagged
uses: snok/container-retention-policy@v1
with:
image-names: nocloud/buf
cut-off: A day ago UTC
account-type: personal
untagged-only: true
token: ${{ secrets.PACKAGES_PAT }}
- run: |
echo "### Deleted Untagged Images :wastebasket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for c in $(echo ${{ steps.untagged.deleted }} | sed "s/,/ /g"); do
echo " - $c" >> $GITHUB_STEP_SUMMARY
done
echo "### Failed to delete Untagged Images :warning:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for c in $(echo ${{ steps.untagged.failed }} | sed "s/,/ /g"); do
echo " - $c" >> $GITHUB_STEP_SUMMARY
done
- name: Dev Images (> 2 weeks)
id: dev
uses: snok/container-retention-policy@v1
with:
image-names: nocloud/buf
cut-off: 2 weeks ago UTC
account-type: personal
filter-tags: dev-*
filter-include-untagged: true
token: ${{ secrets.PACKAGES_PAT }}
- run: |
echo "### Deleted Dev Images :wastebasket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for c in $(echo ${{ steps.dev.deleted }} | sed "s/,/ /g"); do
echo " - $c" >> $GITHUB_STEP_SUMMARY
done
echo "### Failed to delete Untagged Images :warning:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for c in $(echo ${{ steps.dev.failed }} | sed "s/,/ /g"); do
echo " - $c" >> $GITHUB_STEP_SUMMARY
done