-
Notifications
You must be signed in to change notification settings - Fork 78
/
Makefile
177 lines (138 loc) · 4.38 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
#!/usr/bin/make
# WARN: gmake syntax
########################################################
# Makefile for $(NAME)
#
# useful targets:
# make clean -- clean distutils
# make coverage -- code coverage report
# make test -- run linting + unit tests + audit CVEs
# make lint -- run linting separately
# make unit -- run unit tests separately
# make audit -- run CVE scan separately
# make integration -- run integration tests
########################################################
# variable section
NAME = slo_generator
PIP = pip3
PYTHON = python3
TWINE = twine
COVERAGE = coverage
SITELIB = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
VERSION ?= $(shell grep "version = " setup.cfg | cut -d ' ' -f 3)
########################################################
all: clean install test
info:
@echo "slo-generator version: ${VERSION}"
clean:
@echo "Cleaning up distutils stuff"
rm -rf build
rm -rf dist
rm -rf MANIFEST
rm -rf *.egg-info
@echo "Cleaning up byte compiled python stuff"
find . -type f -regex ".*\.py[co]$$" -delete
@echo "Cleaning up doc builds"
rm -rf docs/_build
rm -rf docs/api_modules
rm -rf docs/client_modules
@echo "Cleaning up test reports"
rm -rf report/*
build: clean
$(PYTHON) setup.py sdist bdist_wheel
deploy: clean install_twine build
$(TWINE) upload dist/*
install_twine:
$(PIP) install twine
develop: install
pre-commit install
install: clean
$(PIP) install -e ."[api, datadog, prometheus, elasticsearch, opensearch, splunk, pubsub, cloud_monitoring, bigquery, dev]"
uninstall: clean
$(PIP) freeze --exclude-editable | xargs $(PIP) uninstall -y
test: install unit lint audit
unit: clean
pytest --cov=$(NAME) tests -p no:warnings
coverage:
$(COVERAGE) report --rcfile=".coveragerc"
format:
ruff format
lint: ruff pytype mypy
ruff:
ruff format --check
ruff check
pytype:
pytype
mypy:
mypy --show-error-codes $(NAME)
audit: bandit safety
bandit:
bandit -r $(NAME)
safety:
# Ignore:
# - CVE-2018-20225 with Vulnerability ID 67599, as we do not use the `--extra-index-url` option, and the behavior is intended anyway.
# - CVE-2019-8341 with vulnerability ID 70612, as we do not use untrusted templates without sandboxing.
safety check --ignore 67599 --ignore 70612
integration: int_cm int_csm int_custom int_dd int_dt int_es int_prom int_sp int_os
int_cm:
slo-generator compute -f samples/cloud_monitoring -c samples/config.yaml
int_csm:
slo-generator compute -f samples/cloud_service_monitoring -c samples/config.yaml
int_custom:
slo-generator compute -f samples/custom -c samples/config.yaml
int_dd:
slo-generator compute -f samples/datadog -c samples/config.yaml
int_dt:
slo-generator compute -f samples/dynatrace -c samples/config.yaml
int_es:
slo-generator compute -f samples/elasticsearch -c samples/config.yaml
int_prom:
slo-generator compute -f samples/prometheus -c samples/config.yaml
int_sp:
slo-generator compute -f samples/splunk -c samples/config.yaml
int_os:
slo-generator compute -f samples/opensearch -c samples/config.yaml
# Run API locally
run_api:
slo-generator api --target=run_compute --signature-type=http -c samples/config.yaml
# Build Docker image locally
docker_build:
DOCKER_BUILDKIT=1
docker build \
-t slo-generator:latest \
.
# Build Docker image with Cloud Build
cloud_build:
gcloud builds submit \
--config=cloudbuild.yaml \
--project=${CLOUDBUILD_PROJECT_ID} \
--substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION},_PYTHON_VERSION=${PYTHON_VERSION}
# Cloud Run
cloud_run:
gcloud run deploy slo-generator \
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="${SIGNATURE_TYPE}" \
--min-instances 1 \
--allow-unauthenticated
# Cloud Run - Export Mode Only
cloud_run_export_only:
gcloud run deploy slo-generator-export \
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="cloudevent" \
--args=--target="run_export" \
--min-instances 1 \
--allow-unauthenticated