ci: add deletion of untagged images #36
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: buildAndPushImage | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'dev' | |
pull_request: | |
branches: | |
- 'main' | |
env: | |
IMAGE_URL: ghcr.io/ust-demaf | |
IMAGE_NAME: terraform-mps-plugin | |
IMAGE_TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || 'testing' }} | |
jobs: | |
build-using-dockerfile-push-2-ghcr: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: linux/amd64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
platforms: linux/amd64 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Build and push the regular image | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ env.IMAGE_URL }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
provenance: false | |
# Build and push the slim image | |
- name: Build and push slim image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ env.IMAGE_URL }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}-slim | |
build-args: | # Set the SLIM env variable to 1 for the build | |
SLIM=1 | |
provenance: false | |
delete-untagged-images: | |
needs: | |
- build-using-dockerfile-push-2-ghcr | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/delete-package-versions@v5 | |
with: | |
owner: ${{ github.repository_owner }} | |
package-name: ${{ env.IMAGE_NAME }} | |
package-type: "container" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
min-versions-to-keep: 3 | |
delete-only-pre-release-versions: "true" | |
delete-only-untagged-versions: "true" |