-
Notifications
You must be signed in to change notification settings - Fork 78
/
Makefile
164 lines (128 loc) · 4.1 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
#!/usr/bin/make
# WARN: gmake syntax
########################################################
# Makefile for $(NAME)
#
# useful targets:
# make clean -- clean distutils
# make coverage -- code coverage report
# make test -- run lint + unit tests
# make lint -- run lint tests separately
# make unit -- runs unit tests separately
# make integration -- runs 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.py | cut -d\ -f3)
FLAKE8_IGNORE = E302,E203,E261
########################################################
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:
$(PIP) install -e .
install: clean
$(PIP) install -e ."[api, datadog, prometheus, elasticsearch, pubsub, cloud_monitoring, bigquery, dev]"
uninstall: clean
$(PIP) freeze --exclude-editable | xargs $(PIP) uninstall -y
test: install unit lint
unit: clean
pytest --cov=$(NAME) tests -p no:warnings
coverage:
$(COVERAGE) report --rcfile=".coveragerc"
lint: flake8 pylint pytype
flake8:
flake8 --ignore=$(FLAKE8_IGNORE) $(NAME)/ --max-line-length=80
flake8 --ignore=$(FLAKE8_IGNORE),E402 tests/ --max-line-length=80
pylint:
find ./$(NAME) ./tests -name \*.py | xargs pylint --rcfile .pylintrc --ignore-patterns=test_.*?py
pytype:
pytype
integration: int_cm int_csm int_custom int_dd int_dt int_es int_prom
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
# Run API locally
run_api:
slo-generator api --target=run_compute --signature-type=http -c samples/config.yaml
# Local Docker build / push
docker_build:
DOCKER_BUILDKIT=1
docker build -t slo-generator:latest .
docker_test: docker_build
docker run --entrypoint "make" \
-e GOOGLE_APPLICATION_CREDENTIALS=tests/unit/fixtures/fake_credentials.json \
slo-generator test
# Cloudbuild
cloudbuild: gcloud_alpha
gcloud alpha builds submit \
--config=cloudbuild.yaml \
--project=${CLOUDBUILD_PROJECT_ID} \
--substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION}
# Cloudrun
cloudrun:
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
# Cloudrun - export mode only
cloudrun_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
gcloud_alpha:
gcloud components install alpha --quiet