-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (76 loc) · 2.74 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/make -f
TOPDIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
SELF := $(abspath $(lastword $(MAKEFILE_LIST)))
GITHUB_RUN_ID ?= 0
DATE := $(shell date +"%Y%m%d")
VERSION := $(shell git describe --tags --always --match='v[0-9]*' | cut -d '-' -f 1 | tr -d 'v')
RELEASE := $(shell git describe --tags --always --match='v[0-9]*' --long | cut -d '-' -f 2)
BUILD := $(shell git describe --tags --long --always --dirty)-$(DATE)-$(GITHUB_RUN_ID)
IMAGE_TAG := zont_prom_exporter
IMAGE_PATH := defanator
IMAGE_REGISTRY := ghcr.io
define __VERSION_CONTENT__
"""
Dynamic version info
Generated by $(SELF)
on $(shell hostname)
at $(shell date +"%Y-%m-%d %H:%M:%S %Z")
"""
__version__ = '$(VERSION)'
__release__ = '$(RELEASE)'
__build__ = '$(BUILD)'
endef
export __VERSION_CONTENT__
SHOW_ENV_VARS = \
VERSION \
RELEASE \
GITHUB_RUN_ID \
BUILD
help: ## Show help message (list targets)
@awk 'BEGIN {FS = ":.*##"; printf "\nTargets:\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ {printf " \033[36m%-10s\033[0m %s\n", $$1, $$2}' $(SELF)
show-var-%:
@{ \
escaped_v="$(subst ",\",$($*))" ; \
if [ -n "$$escaped_v" ]; then v="$$escaped_v"; else v="(undefined)"; fi; \
printf "%-13s %s\n" "$*" "$$v"; \
}
show-env: $(addprefix show-var-, $(SHOW_ENV_VARS)) ## Show environment details
src/zont_api/version.py:
@printf "%s\n" "$${__VERSION_CONTENT__}" >$@
VERSION: src/zont_api/version.py
@printf "%s\n" "$(VERSION)" >$@
$(TOPDIR)/dist/zont_api-$(VERSION)-py3-none-any.whl: VERSION
tox run -e build
build: $(TOPDIR)/dist/zont_api-$(VERSION)-py3-none-any.whl ## Build a module with python -m build
test: VERSION ## Run tests
tox run
lint: VERSION ## Run linters
tox run -e lint
fmt: VERSION ## Run formatters
tox run -e fmt
venv: VERSION ## Create virtualenv
tox devenv --list-dependencies .venv
image: build ## Build container image with zont_prom_exporter
docker build \
-f $(TOPDIR)/examples/zont_prom_exporter/Dockerfile \
--build-arg ZONT_API_VERSION=$(VERSION) \
-t zont_prom_exporter:$(VERSION) \
$(TOPDIR)
images: build ## Build multi-arch container images with zont_prom_exporter
docker buildx build --push \
--platform linux/arm64,linux/amd64 \
-f $(TOPDIR)/examples/zont_prom_exporter/Dockerfile \
--build-arg ZONT_API_VERSION=$(VERSION) \
-t $(IMAGE_REGISTRY)/$(IMAGE_PATH)/$(IMAGE_TAG):$(VERSION) \
$(TOPDIR)
clean: ## Clean up
find $(TOPDIR)/ -type f -name "*.pyc" -delete
find $(TOPDIR)/ -type f -name "*.pyo" -delete
find $(TOPDIR)/ -type d -name "__pycache__" -delete
for dir in .pytest_cache .tox build dist htmlcov src/zont_api.egg-info; do \
rm -rf $(TOPDIR)/$${dir} ; \
done
rm -f $(TOPDIR)/.coverage
rm -rf $(TOPDIR)/htmlcov-py*
rm -f $(TOPDIR)/src/zont_api/version.py $(TOPDIR)/VERSION
.PHONY: test lint fmt venv clean