-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
183 lines (160 loc) · 3.83 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Default variables
# Dynamic
REGION := europe-north1
REPO := $(REGION)-docker.pkg.dev/verifa-metrics/docker
TAG := $(shell git describe --tags --always --dirty=-dev)
IMAGE := $(REPO)/metrics-dashboard
DOCKER := docker
PIP := pip3
PIP_INSTALL := $(PIP) install --upgrade
# Static
CLOUDRUN_SERVICE=metrics-dashboard
MAKEFLAGS += -j2
SHELL = /bin/bash
##
## Makefile targets
## ----------------
##
## default:
## build: is the default target
##
default: build
## help:
## prints this help
##
.PHONY : help
help : Makefile
@sed -n 's/^##//p' $<
## vars:
## prints the variables used in this Makefile
##
.PHONY: vars
vars:
@echo ""
$(foreach v, $(.VARIABLES), $(if $(filter file,$(origin $(v))), $(info $(v)=$($(v)))))
## check_notion:
## uses the environment variable to fetch data from notion dB's
.PHONY: check_notion
check_notion:
@scripts/test-notion-keys.sh
## install:
## installs the dependencies with potry
##
install:
poetry install
## tests:
## runs all python files in the tests folder
##
.PHONY: tests
tests: install
poetry run python -m unittest discover
## black-check:
## checks if black would reformat any file
##
.PHONY: black-check
black-check:
$(PIP_INSTALL) black > black-install.log
black --check --diff .
## black:
## uses black to reformat the python files, if needed
##
.PHONY: black
black:
$(PIP_INSTALL) black > black-install.log
black .
## isort
## uses isort to check the import declarations
.PHONY: isort
isort:
$(PIP_INSTALL) isort > isort-install.log
isort . -c --diff
## mypy
## uses mypy to check the project
.PHONY: mypy
ifeq (, $(strip $(VIRTUAL_ENV)))
MYPY_TYPES :=
else
MYPY_TYPES := mypy --install-types --non-interactive
endif
mypy:
$(PIP_INSTALL) mypy > mypy-install.log
$(MYPY_TYPES)
mypy .
## pylint
## uses pylint to lint the files
##
.PHONY: pylint
LINT_DISABLE := --disable=fixme,no-name-in-module,use-dict-literal
ifeq (true, $(CI))
EXIT_ZERO := --exit-zero
else
EXIT_ZERO :=
endif
pylint:
$(PIP_INSTALL) pylint > pylint-install.log
pylint --recursive=y $(EXIT_ZERO) $(LINT_DISABLE) .
## lint:
## a PHONY rule to run all linters
##
.PHONY: lint
lint: black-check pylint mypy isort
## dev:
## runs app.py locally using poetry
##
## dependes on install: and black-check:
##
dev: install lint tests
TEMPO_DEVELOPMENT=True poetry run python app.py
## run:
## uses $(DOCKER) to run the metrics-dashboard image in a local container
##
## if $(TEMPO_CONFIG_PATH) is set, this is mounted as /tempo in the container
##
## depends on build:
## uses $(DOCKER), $(TEMPO_KEY), $(IMAGE) and $(TAG)
##
ifneq ($(TEMPO_CONFIG_PATH),)
vmounts=-v $(TEMPO_CONFIG_PATH):/tempo
else
vmounts=
endif
run: build
$(info Additional docker mounts: $(vmounts))
$(DOCKER) run --rm -ti -e TEMPO_KEY=${TEMPO_KEY} -e JIRA_USER=${JIRA_USER} -e JIRA_API_TOKEN=${JIRA_API_TOKEN} $(vmounts) --name metrics-dashboard -p 8000:8000 $(IMAGE):$(TAG)
## bare:
## uses $(DOCKER) to run the metrics-dashboard image in a local container
## without any optional config files
##
## depends on build:
## uses $(DOCKER), $(TEMPO_KEY), $(IMAGE) and $(TAG)
##
bare: build
$(DOCKER) run --rm -ti -e TEMPO_KEY=${TEMPO_KEY} -e JIRA_USER=${JIRA_USER} -e JIRA_API_TOKEN=${JIRA_API_TOKEN} --name metrics-dashboard -p 8000:8000 $(IMAGE):$(TAG)
## build:
## builds the metrics-dashboard image
##
## uses $(DOCKER), $(IMAGE) and $(TAG)
##
build:
$(DOCKER) build -t $(IMAGE):$(TAG) .
## push:
## pushes the image
##
## depends on build:
## uses $(DOCKER), $(IMAGE) and $(TAG)
##
push: build
$(DOCKER) push $(IMAGE):$(TAG)
$(DOCKER) tag $(IMAGE):$(TAG) $(IMAGE):latest
$(DOCKER) push $(IMAGE):latest
## deploy:
## deploys the built image to google cloud
##
deploy:
gcloud run deploy $(CLOUDRUN_SERVICE) \
--image $(IMAGE):$(TAG) \
--region $(REGION) \
--labels=version=$(TAG)
docs: install
poetry run sphinx-apidoc -o docs/ metrics/
cd docs && poetry run make html