From 748a4bde2f5ab332b34acb356183e43948531609 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Mon, 14 Aug 2023 10:20:31 +0000 Subject: [PATCH] Migrate to :: to allow custom make steps, add generic stubs --- podman.mk | 22 ++++++++++------------ vars/buildPodman.groovy | 10 +++++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/podman.mk b/podman.mk index 760b720..1d6213d 100644 --- a/podman.mk +++ b/podman.mk @@ -32,14 +32,16 @@ endif help: ## Show Help grep -E '^[a-zA-Z_-]+:.*?## .*$$' .ci/podman.mk | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +prepare:: ## custom step on the build agent before building + +fmt:: ## auto format source + +lint:: ## Lint source + build: ## Build the app buildah build --rm --layers -t $(IMAGE):$(TAG)-$(_ARCH) --build-arg TAG=$(TAG) --build-arg ARCH=$(_ARCH) --platform linux/$(_ARCH) . -test: rm-test-image ## Execute Dockerfile.test - test -f Dockerfile.test && \ - { 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" +test:: ## test built artificats scan: ## Scan image using trivy echo "Scanning $(IMAGE):$(TAG)-$(_ARCH) using Trivy $(TRIVY_REMOTE)" @@ -63,21 +65,17 @@ push: ecr-login ## push images to registry ecr-login: ## log into AWS ECR public aws ecr-public get-login-password --region $(REGION) | podman login --username AWS --password-stdin $(REGISTRY) -clean: rm-test-image rm-image ## delete local built container and test images - rm-remote-untagged: ## delete all remote untagged and in-dev images, keep 10 tagged echo "Removing all untagged and in-dev images from $(IMAGE) in $(REGION)" .ci/ecr_public_lifecycle.py --repo $(IMAGE) --dev +clean:: ## clean up source folder + rm-image: 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 "$$(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" - +## some useful tasks during development 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 6e2aab2..70d7620 100644 --- a/vars/buildPodman.groovy +++ b/vars/buildPodman.groovy @@ -14,7 +14,8 @@ def call(Map config=[:]) { withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) { sh 'git fetch -q --tags ${GIT_URL}' } - sh 'make prepare || true' + // Optional project specific preparations + sh 'make prepare' } } @@ -60,7 +61,7 @@ def call(Map config=[:]) { } } - // Push to container registry, skip if PR + // Push to container registry if not PR stage('Push') { when { not { changeRequest() } } steps { @@ -68,8 +69,11 @@ def call(Map config=[:]) { } } - // Basic registry retention removing untagged images + // generic clean stage('cleanup') { + sh 'make clean' + + // Basic registry retention removing untagged images if not PR only when { not { changeRequest() } } steps { sh 'make rm-remote-untagged'