From cfbf5504847d76e57ad33ad0a7342ed6b370a1b4 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Mon, 5 Jun 2023 12:27:06 +0000 Subject: [PATCH] Squashed '.ci/' changes from a49cc0c..79eebe4 79eebe4 add ARCH support for tests aea1ccc Only add branch name to tags, if not part of actual tag a5875db Make EXTRA_TAGS work again 63421d1 fix: prevent branch_name equals tag 47140c2 feat: append branch into tags if not main 4b62ada chore: improve messaging git-subtree-dir: .ci git-subtree-split: 79eebe4d3de843d921994db20e20dda801272934 --- podman.mk | 30 ++++++++++++++++++++---------- vars/buildPodman.groovy | 4 ++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/podman.mk b/podman.mk index f3f7b48..3554fd3 100644 --- a/podman.mk +++ b/podman.mk @@ -1,12 +1,22 @@ # Parse version from latest git semver tag -BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) -GIT_TAG=$(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) -TAG ?= $(shell echo $(GIT_TAG) | awk -F '-' '{ print $$1 "-" $$2 }' | sed -e 's/-$$//') -# EXTRA_TAGS supposed to be set at the caller, eg. $(shell echo $(TAG) | awk -F '.' '{ print $$1 "." $$2 }') +GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) +GIT_TAG := $(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) + +TAG := $(GIT_TAG) +# append branch name to tag if NOT main nor master +ifeq (,$(filter main master, $(GIT_BRANCH))) + # If branch is substring of tag, omit branch name + ifeq ($(findstring $(GIT_BRANCH), $(GIT_TAG)),) + # only append branch name if not equal tag + ifneq ($(GIT_TAG), $(GIT_BRANCH)) + TAG = $(GIT_TAG)-$(GIT_BRANCH) + endif + endif +endif ARCH := amd64 ALL_ARCHS := amd64 arm64 -_ARCH = $(or $(filter ${ARCH},${ALL_ARCHS}),$(error $$ARCH [${ARCH}] must be exactly one of ${ALL_ARCHS})) +_ARCH = $(or $(filter $(ARCH),$(ALL_ARCHS)),$(error $$ARCH [$(ARCH)] must be exactly one of "$(ALL_ARCHS)")) ifneq ($(TRIVY_REMOTE),) TRIVY_OPTS := --server $(TRIVY_REMOTE) @@ -27,7 +37,7 @@ build: ## Build the app test: rm-test-image ## Execute Dockerfile.test test -f Dockerfile.test && \ - { buildah build --rm --layers -t $(REGISTRY)/$(IMAGE):$(TAG)-test --from=$(REGISTRY)/$(IMAGE):$(TAG) -f Dockerfile.test --platform linux/$(_ARCH) . && \ + { buildah build --rm --layers -t $(REGISTRY)/$(IMAGE):$(TAG)-$(_ARCH)-test --from=$(REGISTRY)/$(IMAGE):$(TAG) -f Dockerfile.test --platform linux/$(_ARCH) . && \ podman run --rm --env-host -t $(REGISTRY)/$(IMAGE):$(TAG)-$(_ARCH)-test; } || \ echo "No Dockerfile.test found, skipping test" @@ -61,13 +71,13 @@ rm-remote-untagged: ## delete all remote untagged images [ -n "$$IMAGE_IDS" ] && aws ecr-public batch-delete-image --repository-name $(IMAGE) --region $(REGION) --image-ids $$IMAGE_IDS || echo "No image to remove" rm-image: - test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || podman image rm -f $(IMAGE):$(TAG)-$(_ARCH) > /dev/null - test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || echo "Error: Removing image failed" + test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || podman image rm -f $(IMAGE):$(TAG)-$(_ARCH) > /dev/null + test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || echo "Error: Removing image failed" # Ensure we run the tests by removing any previous runs rm-test-image: - test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(_ARCH)-test)" || podman image rm -f $(IMAGE):$(TAG)-$(_ARCH)-test > /dev/null - test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(_ARCH)-test)" || echo "Error: Removing test image failed" + test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH)-test)" || podman image rm -f $(IMAGE):$(TAG)-$(_ARCH)-test > /dev/null + test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH)-test)" || echo "Error: Removing test image failed" ci-pull-upstream: ## pull latest shared .ci subtree git stash && git subtree pull --prefix .ci ssh://git@git.zero-downtime.net/ZeroDownTime/ci-tools-lib.git master --squash && git stash pop diff --git a/vars/buildPodman.groovy b/vars/buildPodman.groovy index 155cfa3..e5ecff9 100644 --- a/vars/buildPodman.groovy +++ b/vars/buildPodman.groovy @@ -10,6 +10,10 @@ def call(Map config=[:]) { stages { stage('Prepare') { steps { + // pull tags + withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) { + sh 'git fetch -q --tags ${GIT_URL}' + } sh 'make prepare || true' } }