Skip to content

Delete Release Candidate (RC) docker image tags from Azure Container Registry (ACR)

License

Notifications You must be signed in to change notification settings

desholmes/acr-tag-deleter

Repository files navigation

Azure Container Registry Release Candidate Docker Image Deleter

A dockerised bash script using the Azure CLI to delete Release Candidate (RC) docker image tags from Azure Container Registry (ACR).

Before using the Docker container in your pipeline you'll need to create a service principle with access to ACR.

Usage

See the Environment Variables table below.

The following example would check the repo dholmes/acr-tag-deleter for RC tags of 0.1.0, but not delete them:

docker run -it \
  -e AZURE_TENANT=000-000-000-000 \
  -e AZURE_SUBSCRIPTION=000-000-000-000 \
  -e REGISTRY_NAME=dholmes \
  -e REGISTRY_USERNAME=username \
  -e REGISTRY_PASSWORD=password \
  -e REPO=acr-tag-deleter \
  -e TAG=0.1.0 \
  -e DRY_RUN=1 \
desholmes/acr-rc-deleter:1.0.0

Environment Variables

Environment Variable Description
AZURE_TENANT Locate your Azure Account Tenant ID
AZURE_SUBSCRIPTION Locate your Azure Subscription ID
REGISTRY_NAME Locate your ACR name
REGISTRY_USERNAME The service principle username
REGISTRY_PASSWORD The service principle password
REPO The docker repo you want to check/delete the tags from
TAG The stable version of your tag, ie 0.1.0 for release candidates 0.1.0-rc.15, 0.1.0-rc.16
DRY_RUN Boolean 1 to output the number of tags, 0 to delete the tags

Development

The docker image tag, registry and repo are tracked in the Makefile.

Make Commands

Make commands are included in this repo to automate the repetitive tasks. Copy .env-dist to .env and populate the details before using the commands below.

Command Description
make build Builds the Docker image using the version in ./version.properties as the tag
make build-push Runs make build and make push
make clean-dangling-images Removes intermediate Docker images
make delete-image Removes the Docker image based
make push Pushes the Docker image into the registry
make run Runs the built Docker image as a container bind mounts the ./app/ folder into the container for live reloading
make run-clean Runs make delete-image, make build and make run