GoogleCloudPlatform / gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no refs were deleted

alexyoux opened this issue · comments

TL;DR

I try to do the image cleanup for the container registry. I have 20 different folders under a container registry repo.

it is only able to clean up a few images in a few folders and most of the folders return

x no refs were deleted

However, there are hundreds of old images inside those folders.

I run it with below

- name: clean up the folder
        uses: 'docker://asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli'
        with:
          args: >-
            -repo=gcr.io/[projectId]
            -keep=3
            -recursive=true

Can anyone please help?

Expected behavior

It should be able to list the images and clean up them

Observed behavior

it's only able to find a few images in the folder

Debug log output

No response

Additional information

No response

never mind, i use the below to do the cleanup in workflow

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v0'

      - name: 'Use gcloud CLI'
        run: |
          IMAGES=$(gcloud container images list --format='get(name)')
          echo "Images list:"
          echo "${IMAGES}"
          for image in $IMAGES
          do
              echo "current image: ${image}"
              # tail +3 start from line 3, keep the last 3 images
              DEADMEN=$(gcloud container images list-tags ${image} --sort-by=~TIMESTAMP --format='get(digest)'| tail +3)
              for digest in $DEADMEN
              do
                  gcloud container images delete -q --force-delete-tags "${image}@${digest}"
              done
          done

You need to use -recursive if you want to go across multiple repos.

You need to use -recursive if you want to go across multiple repos.

yeah, I did try the recursive before. it didn't work. Even with a single repo link, it can only read a few images and then after deletion, no refs can be found.

If you attach debugging info, that will be helpful in narrowing down the issue: https://github.com/GoogleCloudPlatform/gcr-cleaner#debugging