2022-10-05 16:57:48 +00:00
|
|
|
# Parse version from latest git semver tag
|
2023-08-18 15:19:17 +00:00
|
|
|
GIT_TAG ?= $(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
|
2023-05-05 12:25:37 +00:00
|
|
|
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
TAG ::= $(GIT_TAG)
|
2023-05-05 12:25:37 +00:00
|
|
|
# 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))
|
2023-08-18 15:19:17 +00:00
|
|
|
# Sanitize GIT_BRANCH to allowed Docker tag character set
|
|
|
|
TAG = $(GIT_TAG)-$(shell echo $$GIT_BRANCH | sed -e 's/[^a-zA-Z0-9]/-/g')
|
2023-05-05 12:25:37 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
2022-11-19 12:57:30 +00:00
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
ARCH ::= amd64
|
|
|
|
ALL_ARCHS ::= amd64 arm64
|
2023-05-05 12:25:37 +00:00
|
|
|
_ARCH = $(or $(filter $(ARCH),$(ALL_ARCHS)),$(error $$ARCH [$(ARCH)] must be exactly one of "$(ALL_ARCHS)"))
|
2022-10-05 16:57:48 +00:00
|
|
|
|
|
|
|
ifneq ($(TRIVY_REMOTE),)
|
2023-08-18 15:19:17 +00:00
|
|
|
TRIVY_OPTS ::= --server $(TRIVY_REMOTE)
|
2022-10-05 16:57:48 +00:00
|
|
|
endif
|
|
|
|
|
2022-10-18 12:16:24 +00:00
|
|
|
.SILENT: ; # no need for @
|
|
|
|
.ONESHELL: ; # recipes execute in same shell
|
|
|
|
.NOTPARALLEL: ; # wait for this target to finish
|
|
|
|
.EXPORT_ALL_VARIABLES: ; # send all vars to shell
|
|
|
|
.PHONY: all # All targets are accessible for user
|
|
|
|
.DEFAULT: help # Running Make will run the help target
|
2022-10-05 16:57:48 +00:00
|
|
|
|
2022-10-18 12:16:24 +00:00
|
|
|
help: ## Show Help
|
|
|
|
grep -E '^[a-zA-Z_-]+:.*?## .*$$' .ci/podman.mk | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
2022-10-05 16:57:48 +00:00
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
prepare:: ## custom step on the build agent before building
|
|
|
|
|
|
|
|
fmt:: ## auto format source
|
|
|
|
|
|
|
|
lint:: ## Lint source
|
|
|
|
|
2022-10-18 12:16:24 +00:00
|
|
|
build: ## Build the app
|
2022-11-19 12:57:30 +00:00
|
|
|
buildah build --rm --layers -t $(IMAGE):$(TAG)-$(_ARCH) --build-arg TAG=$(TAG) --build-arg ARCH=$(_ARCH) --platform linux/$(_ARCH) .
|
2022-10-05 16:57:48 +00:00
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
test:: ## test built artificats
|
2022-10-05 16:57:48 +00:00
|
|
|
|
2022-10-18 12:16:24 +00:00
|
|
|
scan: ## Scan image using trivy
|
2022-11-19 12:57:30 +00:00
|
|
|
echo "Scanning $(IMAGE):$(TAG)-$(_ARCH) using Trivy $(TRIVY_REMOTE)"
|
2024-09-10 21:32:08 +00:00
|
|
|
trivy image $(TRIVY_OPTS) --quiet --no-progress --ignorefile ./.trivyignore.yaml localhost/$(IMAGE):$(TAG)-$(_ARCH)
|
2022-10-18 12:16:24 +00:00
|
|
|
|
2022-11-19 11:09:48 +00:00
|
|
|
# first tag and push all actual images
|
|
|
|
# create new manifest for each tag and add all available TAG-ARCH before pushing
|
|
|
|
push: ecr-login ## push images to registry
|
|
|
|
for t in $(TAG) latest $(EXTRA_TAGS); do \
|
2023-05-05 12:25:37 +00:00
|
|
|
echo "Tagging image with $(REGISTRY)/$(IMAGE):$${t}-$(ARCH)"
|
2022-11-19 12:57:30 +00:00
|
|
|
buildah tag $(IMAGE):$(TAG)-$(_ARCH) $(REGISTRY)/$(IMAGE):$${t}-$(_ARCH); \
|
2022-11-19 11:09:48 +00:00
|
|
|
buildah manifest rm $(IMAGE):$$t || true; \
|
|
|
|
buildah manifest create $(IMAGE):$$t; \
|
|
|
|
for a in $(ALL_ARCHS); do \
|
|
|
|
buildah manifest add $(IMAGE):$$t $(REGISTRY)/$(IMAGE):$(TAG)-$$a; \
|
|
|
|
done; \
|
2023-05-05 12:25:37 +00:00
|
|
|
echo "Pushing manifest $(IMAGE):$$t"
|
2022-11-19 11:09:48 +00:00
|
|
|
buildah manifest push --all $(IMAGE):$$t docker://$(REGISTRY)/$(IMAGE):$$t; \
|
2022-10-18 12:16:24 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
ecr-login: ## log into AWS ECR public
|
2022-11-19 11:09:48 +00:00
|
|
|
aws ecr-public get-login-password --region $(REGION) | podman login --username AWS --password-stdin $(REGISTRY)
|
2022-10-18 12:16:24 +00:00
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
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
|
2022-10-18 12:16:24 +00:00
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
clean:: ## clean up source folder
|
2022-10-05 16:57:48 +00:00
|
|
|
|
|
|
|
rm-image:
|
2023-05-05 12:25:37 +00:00
|
|
|
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"
|
2022-10-05 16:57:48 +00:00
|
|
|
|
2023-08-18 15:19:17 +00:00
|
|
|
## some useful tasks during development
|
2022-10-18 12:16:24 +00:00
|
|
|
ci-pull-upstream: ## pull latest shared .ci subtree
|
2023-09-26 18:06:16 +00:00
|
|
|
git subtree pull --prefix .ci ssh://git@git.zero-downtime.net/ZeroDownTime/ci-tools-lib.git master --squash -m "Merge latest ci-tools-lib"
|
2022-10-05 16:57:48 +00:00
|
|
|
|
2022-10-18 12:16:24 +00:00
|
|
|
create-repo: ## create new AWS ECR public repository
|
2022-10-05 16:57:48 +00:00
|
|
|
aws ecr-public create-repository --repository-name $(IMAGE) --region $(REGION)
|