From 643f29dd5d37853c3466c2bc3760f8c54e338dde Mon Sep 17 00:00:00 2001 From: Des Holmes Date: Sun, 12 Mar 2023 12:29:37 +0000 Subject: [PATCH] Updates & fixes (#2) --- .dockerignore | 4 +++- .env-dist | 15 ++++++++++---- .vscode/settings.json | 6 ++++++ Makefile | 8 +++----- README.md | 46 +++++++++++++++++++++---------------------- untag.sh | 8 ++++---- version.properties | 1 + 7 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 version.properties diff --git a/.dockerignore b/.dockerignore index 6a72011..7168377 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ .DS_Store .git* .env* +LICENSE Makefile -README.md \ No newline at end of file +README.md +version.properties \ No newline at end of file diff --git a/.env-dist b/.env-dist index 5fb319f..cc53f9b 100644 --- a/.env-dist +++ b/.env-dist @@ -1,8 +1,15 @@ +# AZURE AZURE_TENANT=000-000-000-000 AZURE_SUBSCRIPTION=000-000-000-000 -VERSION=0.0.0 -REPO=tbc -REGISTRY_NAME=tbc + +# ACR REGISTRY_USERNAME=addme REGISTRY_PASSWORD=addme -DRY_RUN=1 \ No newline at end of file + +# TAGRET REPO +TAG=0.1.0 +REGISTRY_NAME=dholmes +REPO=acr-deleter + +# ARGS +DRY_RUN=1 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..35e7aa4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "deleter", + "desholmes" + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index ee755f8..ec01dd4 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ build push pull run run-clean -include .env +-include version.properties export REGISTRY=desholmes export REPOSITORY=acr-rc-deleter -export VERSION=0.1.0 clean-dangling-images: @docker rmi -f $$(docker images -f 'dangling=true' -q) @@ -19,8 +19,6 @@ build: --build-arg APP_VERSION="$(VERSION)" \ -t $(REGISTRY)/$(REPOSITORY):$(VERSION) . -docker build --build-arg APP_VERSION=0.1.0 -t desholmes/acr-rc-deleter:latest . - build-and-push: @make -s build @make -s push @@ -37,10 +35,10 @@ run: -e REGISTRY_USERNAME=$(REGISTRY_USERNAME) \ -e REGISTRY_PASSWORD=$(REGISTRY_PASSWORD) \ -e REPO=$(REPO) \ - -e VERSION=$(VERSION) \ + -e TAG=$(TAG) \ -e DRY_RUN=$(DRY_RUN) \ -v $(PWD)/untag.sh:/usr/src/untag.sh \ - $(REGISTRY)/$(REPOSITORY):$(VERSION) + $(REGISTRY)/$(REPOSITORY):$(VERSION) run-clean: @make -s delete-image & make build diff --git a/README.md b/README.md index 9e7f561..e82c9bc 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,39 @@ # Azure Container Registry Release Candidate Docker Image Deleter -A [dockerised](https://hub.docker.com/repository/docker/desholmes/acr-rc-deleter) bash script using the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/) to delete [Release Candidate (RC)](https://semver.org/spec/v2.0.0-rc.1.html) docker image tags from [Azure Container Registry (ACR)](https://docs.microsoft.com/en-us/azure/container-registry/). +A [dockerised](https://hub.docker.com/r/desholmes/acr-rc-deleter) bash script using the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/) to delete [Release Candidate (RC)](https://semver.org/spec/v2.0.0-rc.1.html) docker image tags from [Azure Container Registry (ACR)](https://docs.microsoft.com/en-us/azure/container-registry/). -Before using the docker container in your pipeline you'll need to create a[service principle with access to ACR](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-service-principal). +Before using the Docker container in your pipeline you'll need to create a [service principle with access to ACR](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-service-principal). ## Usage -See the [Environment Variables](#Environment-Variables) table below. +See the [Environment Variables](#environment-variables) table below. -### Command - -The following example would check the repo `regname/repo-name` for [RC](https://semver.org/spec/v2.0.0-rc.1.html) tags of `0.12.2`, but not delete them: +The following example would check the repo `dholmes/acr-tag-deleter` for [RC](https://semver.org/spec/v2.0.0-rc.1.html) tags of `0.1.0`, but not delete them: ```bash docker run -it \ -e AZURE_TENANT=000-000-000-000 \ -e AZURE_SUBSCRIPTION=000-000-000-000 \ - -e REGISTRY_NAME=regname \ + -e REGISTRY_NAME=dholmes \ -e REGISTRY_USERNAME=username \ -e REGISTRY_PASSWORD=password \ - -e REPO=repo-name \ - -e VERSION=0.12.2 \ + -e REPO=acr-tag-deleter \ + -e TAG=0.1.0 \ -e DRY_RUN=1 \ -desholmes/acr-rc-deleter:0.1.0 +desholmes/acr-rc-deleter:1.0.0 ``` ### Environment Variables | Environment Variable | Description | |---|---| -|`AZURE_TENANT`|[Locate your Azure Account Tenant ID](https://microsoft.github.io/AzureTipsAndTricks/blog/tip153.html).| -|`AZURE_SUBSCRIPTION`|[Locate your Azure Subscription ID](https://docs.bitnami.com/azure/faq/administration/find-subscription-id/).| -|`REGISTRY_NAME`|[Locate your ACR name](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal).| -|`REGISTRY_USERNAME`|The [service principle](https://open.spotify.com/track/2SkypU3flBcYuyyFqfcsTR) username.| -|`REGISTRY_PASSWORD`|The [service principle](https://open.spotify.com/track/2SkypU3flBcYuyyFqfcsTR) password.| +|`AZURE_TENANT`|[Locate your Azure Account Tenant ID](https://microsoft.github.io/AzureTipsAndTricks/blog/tip153.html)| +|`AZURE_SUBSCRIPTION`|[Locate your Azure Subscription ID](https://docs.bitnami.com/azure/faq/administration/find-subscription-id/)| +|`REGISTRY_NAME`|[Locate your ACR name](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal)| +|`REGISTRY_USERNAME`|The [service principle](https://azure.microsoft.com/en-gb/resources/cloud-computing-dictionary/what-is-a-cloud-provider/) username| +|`REGISTRY_PASSWORD`|The [service principle](https://azure.microsoft.com/en-gb/resources/cloud-computing-dictionary/what-is-a-cloud-provider/) password| |`REPO`|The docker repo you want to check/delete the tags from| -|`VERSION`|The stable version of your tag, ie `0.1.0` for release candidates `0.1.0-rc.15`, `0.1.0-rc.15`| +|`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 @@ -44,14 +42,14 @@ The docker image tag, registry and repo are tracked in the [Makefile](./Makefile ### Make Commands -Make commands are included in this repo to automate the repetitive tasks. Copy [.env-dist](.env-dist) to `.env` and populate the details before using the commands below. +Make commands are included in this repo to automate the repetitive tasks. Copy [.env-dist](./.env-dist) to `.env` and populate the details before using the commands below. | Command | Description | |---|---| -|`make build`|Builds the docker image.| -|`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`.| +|`make build`|Builds the Docker image using the version in [./version.properties](./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`| diff --git a/untag.sh b/untag.sh index 93e8f04..c118380 100644 --- a/untag.sh +++ b/untag.sh @@ -10,7 +10,7 @@ echoInfo "ACR RC Untagger (v$APP_VERSION)" # Check required environment variables are set for envVar in AZURE_TENANT \ AZURE_SUBSCRIPTION \ - VERSION \ + TAG \ REPO \ REGISTRY_NAME \ REGISTRY_USERNAME \ @@ -47,19 +47,19 @@ fi function remove_rc_tags { ## Fetch RC images - echoInfo "Attempting to fetch rc tags for repo: '$1', version: '$VERSION'" + echoInfo "Attempting to fetch rc tags for repo: '$1', tag: '$TAG'" # Note: Incorrect REGISTRY_NAME or REPO will display 'az acr' message and exit 1 allTags=$(az acr repository show-tags --subscription "$AZURE_SUBSCRIPTION" --name "$REGISTRY_NAME" --repository "$1") - rcTags=$(echo "$allTags" | jq -c '[.[] | select(contains ("'$VERSION'rc"))]') + rcTags=$(echo "$allTags" | jq -c '[.[] | select(contains ("'$TAG'-rc"))]') rcCount=$(echo "$rcTags" | jq -c '. | length') # Do we have rc tags? if [[ -z ${rcCount} || ${rcCount} == "0" ]]; then echoInfo "No rc tags found, exiting" - return + exit 0 fi echoInfo "Fetching rc tags successful. Found: '$rcCount'" diff --git a/version.properties b/version.properties new file mode 100644 index 0000000..624bade --- /dev/null +++ b/version.properties @@ -0,0 +1 @@ +VERSION=1.0.0