Skip to content

Commit

Permalink
fixup delete action (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Nov 16, 2024
1 parent ae17724 commit e4fd8d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ on:
tag_pattern:
description: 'Wildcard pattern for Docker tags to delete'
required: true
default: "^branch-name.*"
default: "branch-name"

jobs:
find-images:
name: Find docker images needing deleted
runs-on: ubuntu-latest
outputs:
dockerFiles: ${{ steps.images.outputs.images }}
images: ${{ steps.images.outputs.images }}
steps:
- uses: actions/checkout@v4

- name: Find docker files
id: images
run: |
dockerFiles=$(find examples -name Dockerfile | jq -c --raw-input --slurp 'split("\n")| .[0:-1]')
images=$(echo "$dockerFiles" | jq -r '.[]' | \
images=$(find examples -name Dockerfile | jq -c --raw-input --slurp 'split("\n")| .[0:-1]' | jq -r '.[]' | \
awk -F'/' '{print "scyllaridae-" $2}' | \
jq -R -s '. | split("\n") | .[0:-1] | . + ["scyllaridae"]')
jq -c -R -s '. | split("\n") | .[0:-1] | . + ["scyllaridae"]')
echo "images=$images" >> $GITHUB_OUTPUT
delete-docker-tags:
Expand All @@ -36,6 +35,7 @@ jobs:
matrix:
image: ${{ fromJson(needs.find-images.outputs.images )}}
max-parallel: 1 # go easy on the dockerhub API
fail-fast: false
steps:
- name: checkout
uses: actions/checkout@v4
Expand All @@ -44,7 +44,7 @@ jobs:
run: ./ci/delete-tags.sh
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REPOSITORY: "lehighlts"
DOCKER_IMAGE: ${{ matrix.image }}
TAG_PATTERN: "^${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag_pattern || github.ref_name }}.*"
1 change: 1 addition & 0 deletions .github/workflows/lint-test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
paths-ignore:
- '**/*.md'
- 'ci/**'
- '.github/workflows/delete.yml'
tags:
- '*'
branches:
Expand Down
4 changes: 2 additions & 2 deletions ci/delete-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi

echo "Deleting tags matching pattern '$TAG_PATTERN' in repository ${DOCKER_IMAGE}"

curl -s -o response.json -u "${DOCKER_USERNAME}:${DOCKER_ACCESS_TOKEN}" "https://hub.docker.com/v2/repositories/${DOCKER_REPOSITORY}/${DOCKER_IMAGE}/tags?page_size=100"
curl -s -o response.json -u "${DOCKER_USERNAME}:${DOCKER_PASSWORD}" "https://hub.docker.com/v2/repositories/${DOCKER_REPOSITORY}/${DOCKER_IMAGE}/tags?page_size=100"
TAGS=$(jq -r '.results[].name' response.json)
if [ -z "$TAGS" ] || [ "$TAGS" = "null" ]; then
echo "No tags found or failed to retrieve tags."
Expand All @@ -18,7 +18,7 @@ fi

curl -s -o token.json -XPOST \
-H "Content-Type: application/json" \
-d '{"username": "'"${DOCKER_USERNAME}"'", "password": "'"${DOCKER_ACCESS_TOKEN}"'"}' \
-d '{"username": "'"${DOCKER_USERNAME}"'", "password": "'"${DOCKER_PASSWORD}"'"}' \
"https://hub.docker.com/v2/users/login"

TOKEN=$(jq -r .token token.json)
Expand Down

0 comments on commit e4fd8d7

Please sign in to comment.