Skip to content

Commit

Permalink
Updates & fixes (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
desholmes authored Mar 12, 2023
1 parent 7a3b8cc commit 643f29d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
.git*
.env*
LICENSE
Makefile
README.md
README.md
version.properties
15 changes: 11 additions & 4 deletions .env-dist
Original file line number Diff line number Diff line change
@@ -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

# TAGRET REPO
TAG=0.1.0
REGISTRY_NAME=dholmes
REPO=acr-deleter

# ARGS
DRY_RUN=1
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cSpell.words": [
"deleter",
"desholmes"
]
}
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
46 changes: 22 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`|
8 changes: 4 additions & 4 deletions untag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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'"
Expand Down
1 change: 1 addition & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=1.0.0

0 comments on commit 643f29d

Please sign in to comment.