From 5a1db73f3365a155c9b3123afb531f66e828b15f Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Wed, 9 Aug 2023 11:59:00 +0000 Subject: [PATCH] Squashed '.ci/' changes from 79eebe4..5d4e4ad 5d4e4ad Make rm-remote-untagged less noisy f00e541 Add cleanup step to remove untagged images by default 0821e91 Ensure tag names are valid for remote branches like PRs git-subtree-dir: .ci git-subtree-split: 5d4e4adce020398a515b5edf73cede0e0f81087b --- podman.mk | 4 ++-- vars/buildPodman.groovy | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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' + } + } } } }