Skip to content

Commit

Permalink
Delete older docker dev images from dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
craigk5n committed Sep 26, 2023
1 parent 9b0ae36 commit c13eba3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/docker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ jobs:
${{ secrets.DOCKER_HUB_USERNAME }}/webcalendar:dev-php8-apache
${{ secrets.DOCKER_HUB_USERNAME }}/webcalendar:dev
- name: Cleanup Old Images
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
DOCKER_HUB_REPO: user/app
KEEP_LAST_N_IMAGES: 5
run: |
# Get list of tags
TAGS=$(curl -s -u $DOCKER_HUB_USERNAME:$DOCKER_HUB_PASSWORD https://hub.docker.com/v2/repositories/$DOCKER_HUB_REPO/tags/?page_size=100 | jq -r '.results[].name')
# Sort tags and delete all except for the most recent N
COUNTER=0
for TAG in $(echo $TAGS | tr " " "\n" | sort -V)
do
if [ $COUNTER -ge $KEEP_LAST_N_IMAGES ]
then
echo "Deleting tag $TAG"
curl -X DELETE -u $DOCKER_HUB_USERNAME:$DOCKER_HUB_PASSWORD https://hub.docker.com/v2/repositories/$DOCKER_HUB_REPO/tags/$TAG/
else
echo "Keeping tag $TAG"
fi
COUNTER=$((COUNTER + 1))
done

0 comments on commit c13eba3

Please sign in to comment.