Skip to content

Delete old container images #774

Delete old container images

Delete old container images #774

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@v4
- 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-base:
name: Cleanup Base Image
runs-on: ubuntu-latest
steps:
- name: Untagged Images (> 1 day)
id: untagged-base
uses: snok/container-retention-policy@v2
with:
image-names: nocloud/base
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-base.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-base.failed }} | sed "s/,/ /g"); do
echo " - $c" >> $GITHUB_STEP_SUMMARY
done
- name: Dev Images (> 2 weeks)
id: dev-base
uses: snok/container-retention-policy@v2
with:
image-names: nocloud/base
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-base.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-base.failed }} | sed "s/,/ /g"); do
echo " - $c" >> $GITHUB_STEP_SUMMARY
done
clean-ghcr:
name: Cleanup
runs-on: ubuntu-latest
needs: [prepare]
strategy:
matrix:
tag: ${{fromJson(needs.prepare.outputs.matrix)}}
steps:
- name: Untagged Images (> 1 day)
id: untagged
uses: snok/container-retention-policy@v2
with:
image-names: nocloud/${{matrix.tag}}
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@v2
with:
image-names: nocloud/${{matrix.tag}}
cut-off: 1 day 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