From d6f343c176a2e32342a371f5a8a0ebbb418b6b40 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Fri, 26 Jul 2024 14:31:55 +0200 Subject: [PATCH] Update container image cleanup GitHub actions Switch to dataaxiom/ghcr-cleanup-action which treats multi-arch images correctly and refactor the cleanup jobs so that we delete untagged versions once a day from Monday to Friday and delete PR tags once the PR is closed (merged or unmerged). --- .../gitlab-container-image-cleanup-pr-tag.yml | 21 +++++++++++++++++++ .../workflows/prune-old-container-images.yml | 12 +++++------ 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/gitlab-container-image-cleanup-pr-tag.yml diff --git a/.github/workflows/gitlab-container-image-cleanup-pr-tag.yml b/.github/workflows/gitlab-container-image-cleanup-pr-tag.yml new file mode 100644 index 0000000..43a6b80 --- /dev/null +++ b/.github/workflows/gitlab-container-image-cleanup-pr-tag.yml @@ -0,0 +1,21 @@ +--- +name: Delete closed PR container image tag + +"on": + pull_request: + types: + - closed + +jobs: + cleanup-pr-tag: + uses: ubuntu-latest + steps: + - name: Set image version for PR to branch name + run: echo "VERSION=${GITHUB_HEAD_REF//\//-}" >> ${GITHUB_ENV} + + - name: Delete PR container image tag + uses: dataaxiom/ghcr-cleanup-action@v1 + with: + tags: ${{ env.VERSION }} + package: ${{ github.event.repository.name }}/gitlab + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/prune-old-container-images.yml b/.github/workflows/prune-old-container-images.yml index 641ef66..f219a49 100644 --- a/.github/workflows/prune-old-container-images.yml +++ b/.github/workflows/prune-old-container-images.yml @@ -1,5 +1,5 @@ --- -name: Prune old container images +name: Prune untagged container images "on": schedule: @@ -10,10 +10,8 @@ jobs: prune: runs-on: ubuntu-latest steps: - - uses: actions/delete-package-versions@v5 + - uses: dataaxiom/ghcr-cleanup-action@v1 with: - package-name: "${{ github.repository }}-gitlab" - package-type: container - # never delete release versions or latest - ignore-versions: "^(v.*|latest)$" - min-versions-to-keep: 3 + token: ${{ secrets.GITHUB_TOKEN }} + package: ${{ github.event.repository.name }}/gitlab + validate: true