Retention Policy #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Retention Policy | |
on: | |
workflow_dispatch: # And manually on button click | |
schedule: | |
# every day at 00:05 UTC | |
- cron: '5 0 * * *' | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
clean: | |
runs-on: ubuntu-latest | |
steps: | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Login to registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Protect against partial deletion of multi-platform Docker images. | |
# https://github.com/snok/container-retention-policy/blob/main/README.md#the-solution | |
- name: Fetch multi-platform package version SHAs | |
id: multi-arch-digests | |
run: | | |
package1=$(docker manifest inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | \ | |
jq -r '.manifests[]|.digest' | paste -s -d ' ' -) | |
echo "multi-arch-digests=$package1" >> $GITHUB_OUTPUT | |
# Delete all untagged Docker images after 1 week and 3 days. | |
# https://github.com/snok/container-retention-policy | |
- name: Delete untagged Docker images | |
uses: snok/container-retention-policy@v3.0.0 | |
id: delete | |
with: | |
dry-run: true | |
cut-off: 1w 3d | |
image-tags: "!latest" | |
tag-selection: untagged | |
image-names: ${{ github.event.repository.name }} | |
skip-shas: ${{ steps.multi-arch-digests.outputs.multi-arch-digests }} | |
account: ${{ github.repository_owner }} | |
token: ${{ secrets.GITHUB_TOKEN }} |