diff --git a/podman.mk b/podman.mk index 3554fd3..cca0986 100644 --- a/podman.mk +++ b/podman.mk @@ -1,5 +1,5 @@ # Parse version from latest git semver tag -GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) +GIT_BRANCH ?= $(shell git name-rev --name-only HEAD 2>/dev/null | sed -e 's,remotes/origin/,,' -e 's/[^a-zA-Z0-9]/-/g') GIT_TAG := $(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) TAG := $(GIT_TAG) @@ -68,7 +68,7 @@ clean: rm-test-image rm-image ## delete local built container and test images rm-remote-untagged: ## delete all remote untagged images echo "Removing all untagged images from $(IMAGE) in $(REGION)" IMAGE_IDS=$$(for image in $$(aws ecr-public describe-images --repository-name $(IMAGE) --region $(REGION) --output json | jq -r '.imageDetails[] | select(.imageTags | not ).imageDigest'); do echo -n "imageDigest=$$image "; done) ; \ - [ -n "$$IMAGE_IDS" ] && aws ecr-public batch-delete-image --repository-name $(IMAGE) --region $(REGION) --image-ids $$IMAGE_IDS || echo "No image to remove" + [ -n "$$IMAGE_IDS" ] && aws ecr-public batch-delete-image --repository-name $(IMAGE) --region $(REGION) --image-ids $$IMAGE_IDS | jq -r '.imageIds[]' || echo "No image to remove" rm-image: test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || podman image rm -f $(IMAGE):$(TAG)-$(_ARCH) > /dev/null diff --git a/vars/buildPodman.groovy b/vars/buildPodman.groovy index e5ecff9..6e2aab2 100644 --- a/vars/buildPodman.groovy +++ b/vars/buildPodman.groovy @@ -68,6 +68,13 @@ def call(Map config=[:]) { } } + // Basic registry retention removing untagged images + stage('cleanup') { + when { not { changeRequest() } } + steps { + sh 'make rm-remote-untagged' + } + } } } }