docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.11k stars 527 forks source link

Keep last n images option #1000

Closed paololazzari closed 5 months ago

paololazzari commented 7 months ago

Description

Imagine I had a repository which had 3 images in it.

When I push the fourth one, it would be useful to be able to delete the oldest one so that my repository only ever has 3 images in it.

Something like:

- name: Build and push
  uses: docker/build-push-action@v5
  with:
    context: .
    platforms: linux/amd64,linux/arm64
    push: true
    tags: |
      ...
    keep_releases = 3

Perhaps considering this is to an extent a destructive operation it could live in a separate action.

crazy-max commented 5 months ago

When I push the fourth one, it would be useful to be able to delete the oldest one so that my repository only ever has 3 images in it.

This is out of scope for this action and should be something handled on the registry itself. Check if you registry supports configuration of retention policy/garbage collection on images/tags like ACR does: https://learn.microsoft.com/en-us/azure/container-registry/container-registry-soft-delete-policy