Skip to content

Commit 3a3a39b

Browse files
committed
Clean-up Docker Hub untagged images also
1 parent 900e4f2 commit 3a3a39b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

.github/workflows/cleanup.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,40 @@ jobs:
2020
echo "Repository name is: $REPOSITORY_NAME"
2121
echo "REPOSITORY_NAME=$REPOSITORY_NAME" >> $GITHUB_ENV
2222
23-
- name: Delete untagged Docker images
23+
- name: Delete untagged images
2424
uses: Chizkiyahu/delete-untagged-ghcr-action@v4
2525
with:
2626
token: ${{ secrets.GHCR_ACCESS_TOKEN }}
2727
owner_type: user
2828
package_name: ${{ env.REPOSITORY_NAME }}
2929
untagged_only: true
3030

31+
docker:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Get repository name
36+
run: |
37+
REPOSITORY_NAME="${{ github.repository }}"
38+
REPOSITORY_NAME="${REPOSITORY_NAME##*/}"
39+
echo "Repository name is: $REPOSITORY_NAME"
40+
echo "REPOSITORY_NAME=$REPOSITORY_NAME" >> $GITHUB_ENV
41+
42+
- name: Download regctl
43+
run: |
44+
curl -sSL https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 -o regctl
45+
chmod +x ./regctl
46+
47+
- name: Registry login
48+
run: |
49+
./regctl registry login docker.io -u "${{ vars.DOCKER_IO_USER }}" -p "${{ secrets.DOCKER_IO_ACCESS_TOKEN }}"
50+
51+
- name: Delete untagged images
52+
run: |
53+
./regctl artifact list "docker.io/${{ vars.DOCKER_IO_USER }}/${{ env.REPOSITORY_NAME }}" --format json | \
54+
jq -r '.[] | select(.tags == null or .tags | length == 0) | .digest' | \
55+
while read digest; do
56+
echo "Deleting untagged digest: $digest"
57+
./regctl manifest rm "docker.io/${{ vars.DOCKER_IO_USER }}/${{ env.REPOSITORY_NAME }}@$digest"
58+
done
59+

0 commit comments

Comments
 (0)