Skip to content

Commit 9ca3203

Browse files
committed
ci: use ghcr-cleanup-action
1 parent 5abd0b3 commit 9ca3203

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

.github/workflows/build.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defaults:
3636
shell: bash
3737

3838
env:
39-
DOCKER_IMAGE_REPO: ${{ github.repository_owner }}/softhsm2-pkcs11-proxy
39+
DOCKER_REPO_NAME: softhsm2-pkcs11-proxy
4040
TRIVY_CACHE_DIR: ~/.trivy/cache
4141

4242
jobs:
@@ -85,14 +85,14 @@ jobs:
8585

8686
- name: Check Alpine Dockerfile
8787
uses: hadolint/hadolint-action@v3.1.0
88-
if: ${{ startsWith(matrix.DOCKER_BASE_IMAGE, 'alpine') }}
88+
if: ${{ contains(matrix.DOCKER_BASE_IMAGE, 'alpine') }}
8989
with:
9090
dockerfile: image/alpine.Dockerfile
9191

9292

9393
- name: Check Debian Dockerfile
9494
uses: hadolint/hadolint-action@v3.1.0
95-
if: ${{ startsWith(matrix.DOCKER_BASE_IMAGE, 'debian') }}
95+
if: ${{ contains(matrix.DOCKER_BASE_IMAGE, 'debian') }}
9696
with:
9797
dockerfile: image/debian.Dockerfile
9898

@@ -116,11 +116,13 @@ jobs:
116116

117117

118118
- name: "Determine if docker images shall be published"
119+
id: docker_push_actions
119120
run: |
120121
# ACT -> https://nektosact.com/usage/index.html#skipping-steps
121122
set -x
122123
if [[ $GITHUB_REF_NAME == 'main' && $GITHUB_EVENT_NAME != 'pull_request' && -z "$ACT" ]]; then
123124
echo "DOCKER_PUSH_GHCR=true" >> "$GITHUB_ENV"
125+
echo "DOCKER_PUSH_GHCR=true" >> $GITHUB_OUTPUT
124126
if [[ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]]; then
125127
echo "DOCKER_PUSH=true" >> "$GITHUB_ENV"
126128
fi
@@ -144,9 +146,40 @@ jobs:
144146
password: ${{ secrets.GITHUB_TOKEN }}
145147

146148

147-
- name: Build ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.SOFTHSM_VERSION }}
149+
- name: Build ${{ env.DOCKER_REPO_NAME }}:${{ matrix.SOFTHSM_VERSION }}
148150
env:
149151
DOCKER_BASE_IMAGE: ${{ matrix.DOCKER_BASE_IMAGE }}
152+
DOCKER_IMAGE_REPO: ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}
150153
SOFTHSM_VERSION: ${{ matrix.SOFTHSM_VERSION }}
151154
TRIVY_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152155
run: bash build-image.sh
156+
157+
outputs:
158+
DOCKER_PUSH_GHCR: ${{ steps.docker_push_actions.outputs.DOCKER_PUSH_GHCR }}
159+
160+
161+
###########################################################
162+
delete-untagged-images:
163+
###########################################################
164+
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
165+
timeout-minutes: 5
166+
needs: [build]
167+
if: ${{ needs.build.outputs.DOCKER_PUSH_GHCR }}
168+
169+
concurrency:
170+
group: ${{ github.workflow }}
171+
cancel-in-progress: false
172+
173+
permissions:
174+
packages: write
175+
176+
steps:
177+
- name: Delete untagged images
178+
uses: dataaxiom/ghcr-cleanup-action@v1
179+
with:
180+
package: ${{ env.DOCKER_REPO_NAME }}
181+
delete-untagged: true
182+
delete-partial-images: true
183+
delete-ghost-images: true
184+
delete-orphaned-images: true
185+
validate: true

0 commit comments

Comments
 (0)