Skip to content

ci: add deletion of untagged images #12

ci: add deletion of untagged images

ci: add deletion of untagged images #12

name: buildAndPushImage
on:
push:
branches:
- 'main'
- 'dev'
pull_request:
branches:
- 'main'
env:
IMAGE_URL: ghcr.io/ust-demaf
IMAGE_NAME: models-service
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
- name: Login to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u well5a --password-stdin
- name: Build the Docker image
run: docker build . --file Dockerfile --tag $IMAGE_URL/$IMAGE_NAME:$IMAGE_TAG
- name: Push the Docker image
run: docker push $IMAGE_URL/$IMAGE_NAME:$IMAGE_TAG
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"