-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
304 lines (243 loc) · 9.7 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
.PHONY: clean-pyc clean-build docs clean
.SUFFIXES:
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
export STATSD_DSN=udp://localhost:8125
VENV_PATH = env
VENV = $(VENV_PATH)/ready
BIN = $(VENV_PATH)/bin
PY3 = $(shell which python3)
PYTHON ?= $(shell readlink -f $(PY3))
TALISKER_EXTRAS=gunicorn,raven,flask,django,celery,prometheus,pg,dev,asyncio
LIMBO_REQUIREMENTS=tests/requirements.limbo.txt
REQUIREMENTS=$(shell ls requirements.*.txt)
PIP_REQUIREMENTS=
default: test
$(VENV_PATH):
virtualenv $(VENV_PATH) -p $(PYTHON)
setup.py: setup.cfg scripts/build_setup.py | $(VENV_PATH)
env/bin/python scripts/build_setup.py > setup.py
$(LIMBO_REQUIREMENTS) limbo: setup.cfg requirements.*.txt scripts/limbo.py | $(VENV_PATH)
env/bin/python scripts/limbo.py requirements.tests.txt --extras=$(TALISKER_EXTRAS) > $(LIMBO_REQUIREMENTS)
# workaround to allow tox to build limbo requirements on demand
limbo-env: $(LIMBO_REQUIREMENTS)
pip install $(TOX_OPTS) -r requirements.limbo.text $(TOX_PACKAGES)
$(VENV): setup.py $(REQUIREMENTS) | $(VENV_PATH)
$(BIN)/pip install -U pip
$(BIN)/pip install -e .[$(TALISKER_EXTRAS)]
$(BIN)/pip install $(subst requirements,-r requirements,$(REQUIREMENTS))
ln -sf $(VENV_PATH)/lib/$(shell basename $(PYTHON))/site-packages lib
touch $(VENV)
lint: $(VENV)
$(BIN)/flake8 talisker tests
_test: $(VENV)
. $(BIN)/activate && $(BIN)/pytest --timeout=15 --no-success-flaky-report $(ARGS)
TEST_FILES = $(shell find tests -maxdepth 1 -name test_\*.py | cut -c 7- | cut -d. -f1)
$(TEST_FILES): $(VENV)
. $(BIN)/activate && pytest -k $@ $(ARGS)
export DEBUGLOG=log
export DEVEL=1
WORKER ?= sync
PORT ?= 8000
TALISKER = $(BIN)/talisker.gunicorn --bind 0.0.0.0:$(PORT) --reload --worker-class $(WORKER) $(ARGS)
APP ?= application
run wsgi:
$(TALISKER) tests.wsgi_app:$(APP)
run_multiprocess: ARGS=-w4
run_multiprocess: run
lib/sqlalchemy:
$(BIN)/pip install sqlalchemy
flask: | lib/sqlalchemy
$(TALISKER) tests.flask_app:app
lib/redis:
$(BIN)/pip install redis
db-setup:
psql -U postgres -c "create user django_app with password 'django_app';"
psql -U postgres -c "create database django_app owner django_app;"
migrate:
$(BIN)/python tests/django_app/manage.py migrate
celery-worker: lib/redis
$(BIN)/talisker.celery -q -A tests.celery_app worker
celery-client: lib/redis
$(BIN)/python tests/celery_app.py
django: lib/redis
PYTHONPATH=tests/django_app/ $(TALISKER) tests.django_app.django_app.wsgi:application
django-celery: lib/redis
PYTHONPATH=tests/django_app/ $(BIN)/talisker.celery worker -q -A django_app
statsd:
$(BIN)/python tests/udpecho.py
test: _test lint
@echo "Remember to run 'make tox' to test change against more Python versions"
debug-test:
. $(BIN)/activate && $(BIN)/pytest -s --pdb $(ARGS)
tox: $(VENV) $(LIMBO_REQUIREMENTS)
$(BIN)/tox $(ARGS)
# use requirements as constraints files
travis: $(VENV_PATH)
env/bin/pip install tox setuptools $(subst requirements,-c requirements,$(REQUIREMENTS))
$(MAKE) $(LIMBO_REQUIREMENTS)
env/bin/tox
github-tox: $(VENV)
. $(BIN)/activate && pip install tox setuptools $(subst requirements,-c requirements,$(REQUIREMENTS))
$(MAKE) $(LIMBO_REQUIREMENTS)
tox
coverage: $(VENV)
$(BIN)/pytest --cov=talisker --cov-report html:htmlcov --cov-report term
$(BROWSER) htmlcov/index.html
docs: $(VENV)
$(MAKE) -C docs clean SPHINXBUILD=../$(BIN)/sphinx-build
$(MAKE) -C docs html SPHINXBUILD=../$(BIN)/sphinx-build SPHINXOPTS=-W
view:
$(BROWSER) docs/_build/html/index.html
clean: clean-build clean-pyc clean-test
rm $(VENV_PATH) lib -rf
clean-build:
rm build/ dist/ .eggs/ -rf
find . -name '*.egg-info' | xargs rm -rf
find . -name '*.egg' | xargs rm -f
clean-pyc:
find . -name '*.pyc' | xargs rm -f
find . -name '*.pyo' | xargs rm -f
find . -name '*~' | xargs rm -f
find . -name '__pycache__' | xargs rm -rf
clean-test:
rm .tox/ .pytest_cache .coverage* htmlcov/ results logstash-test-results tests/requirements.limbo.txt -rf
# publishing
RELEASE_TOOLS = $(BIN)/twine $(BIN)/bumpversion
PY2ENV_PATH = .py2env
PY2ENV = $(PY2ENV_PATH)/.done
PACKAGE_NAME = $(shell $(BIN)/python setup.py --name)
PACKAGE_FULLNAME = $(shell $(BIN)/python setup.py --fullname)
PACKAGE_VERSION = $(shell $(BIN)/python setup.py --version)
RELEASE ?= patch
NEXT_VERSION = $(shell $(BIN)/bumpversion --allow-dirty --dry-run --list $(RELEASE) | grep new_version | cut -d'=' -f2)
CURRENT_VERSION = $(shell $(BIN)/python setup.py --version)
CHANGELOG ?= HISTORY.rst
$(RELEASE_TOOLS): $(VENV)
echo $(RELEASE_TOOLS)
$(BIN)/pip install twine bumpversion
# minimal python2 env to build p2 wheel
$(PY2ENV):
virtualenv $(PY2ENV_PATH) -p /usr/bin/python2.7
$(PY2ENV_PATH)/bin/pip install wheel
touch $@
# force build every time, it's not slow
_build: $(VENV) $(PY2ENV)
rm -rf dist/*
$(BIN)/python setup.py sdist
$(BIN)/python setup.py bdist_wheel
$(PY2ENV_PATH)/bin/python setup.py bdist_wheel
release-check: $(RELEASE_TOOLS)
git checkout master
git pull
@grep $(NEXT_VERSION) $(CHANGELOG) || $(MAKE) changelog RELEASE=$(RELEASE)
if test -n "$$(git tag -l v$(NEXT_VERSION))"; then echo "Tag v$(NEXT_VERSION) already exists!"; exit 1; fi
#test -z "$(SKIP_TOX)" && $(MAKE) tox
release-build: TAG=v$(NEXT_VERSION)
release-build: release-check
@read -p "About to bump $(PACKAGE_NAME) to $(NEXT_VERSION) and build $(PACKAGE_NAME) $(NEXT_VERSION), are you sure? [yn] " REPLY ; test "$$REPLY" = "y"
$(BIN)/bumpversion $(RELEASE)
$(MAKE) setup.py
$(MAKE) _build
$(MAKE) release-test PY=3
release-tag: VERSION=$(shell $(BIN)/python setup.py --version)
release-tag:
git add HISTORY.rst setup.py setup.cfg talisker/__init__.py docs/conf.py .bumpversion.cfg
git commit -m "bumping to version $(VERSION)"
git tag v$(VERSION)
git push origin master
.PHONY: releast-test
release-test: WHEELENV=/tmp/talisker-test-wheel-py$(PY)
release-test: SDISTENV=/tmp/talisker-test-sdist-py$(PY)
release-test:
rm -rf $(WHEELENV) $(SDISTENV)
virtualenv -p python$(PY) $(WHEELENV)
$(WHEELENV)/bin/pip install dist/talisker-$(CURRENT_VERSION)-py$(PY)-none-any.whl
virtualenv -p python$(PY) $(SDISTENV)
$(SDISTENV)/bin/pip install dist/talisker-$(CURRENT_VERSION).tar.gz
rm -rf $(WHEELENV) $(SDISTENV)
release-pypi: $(RELEASE_TOOLS)
$(BIN)/twine upload dist/talisker*$$($(BIN)/python setup.py --version)*
register: tox
@read -p "About to register/update $(PACKAGE_NAME), are you sure? [yn] " REPLY ; test "$$REPLY" = "y"
$(MAKE) _build
$(BIN)/twine register dist/$(PACKAGE_NAME)-*
changelog: HEADER = $(NEXT_VERSION) ($(shell date +'%Y-%m-%d'))
changelog: LENGTH = $(shell echo -n "$(HEADER)" | wc -c)
changelog: UNDERLINE = $(shell head -c $(LENGTH) < /dev/zero | tr '\0' '-')
changelog: ENTRY := $(shell mktemp -u)
changelog: GUARD := $(shell mktemp -u)
changelog: $(RELEASE_TOOLS)
@echo "$(HEADER)\n$(UNDERLINE)\n\n* ...\n" >> $(ENTRY)
@echo "## add your change log above, these lines will be stripped" >> $(ENTRY)
@echo "## here are the commit messages since the last release:\n##" >> $(ENTRY)
@git log v$(PACKAGE_VERSION)... --no-merges --decorate --format="## %s" >> $(ENTRY)
@touch $(GUARD)
@$${EDITOR:-vi} $(ENTRY)
@test $(ENTRY) -nt $(GUARD) && { grep -hv '^##' $(ENTRY) $(CHANGELOG) > $(GUARD) && mv -f $(GUARD) $(CHANGELOG) && echo "Updated $(CHANGELOG)"; } || echo "No changes, not updating $(CHANGELOG)"
# logstash testing
LOGSTASH_URL = https://download.elastic.co/logstash/logstash/logstash-2.0.0.tar.gz
LOGSTASH_CACHE = /tmp/$(shell basename $(LOGSTASH_URL))
LXC_NAME = logstash
LOGSTASH_DIR = /opt/logstash
LOGSTASH_CONFIG= talisker/logstash/test-config
LOGSTASH_CONFIG_LXC=$(LOGSTASH_DIR)/patterns/$(shell basename $(LOGSTASH_CONFIG))
LOGSTASH_PATTERNS_LXC=$(LOGSTASH_DIR)/patterns
LOGSTASH_RESULTS=test-results
LOGSTASH=lxc exec $(LXC_NAME) -- $(LOGSTASH_DIR)/bin/logstash -f $(LOGSTASH_CONFIG_LXC)
$(LOGSTASH_CACHE):
curl -o $(LOGSTASH_CACHE) $(LOGSTASH_URL)
logstash-setup: $(LOGSTASH_CACHE)
-@lxc delete -f $(LXC_NAME)
lxc launch ubuntu:trusty $(LXC_NAME) -c security.privileged=true
sleep 10
lxc file push $(LOGSTASH_CACHE) $(LXC_NAME)$(LOGSTASH_CACHE)
lxc exec $(LXC_NAME) -- mkdir -p $(LOGSTASH_DIR)
lxc exec $(LXC_NAME) -- apt update
lxc exec $(LXC_NAME) -- apt install openjdk-7-jre-headless -y --no-install-recommends
lxc exec $(LXC_NAME) -- tar xzf $(LOGSTASH_CACHE) -C $(LOGSTASH_DIR) --strip 1
lxc config device add $(LXC_NAME) talisker disk source=$(PWD)/talisker/logstash path=$(LOGSTASH_PATTERNS_LXC)
define REPORT_PY
import sys, json
for line in sys.stdin:
r = json.loads(line)
if 'tags' in r:
if '_grokparsefailure' in r['tags'] or '_rubyexception' in r['tags']:
print(json.dumps(r, sort_keys=True, indent=4, separators=(',', ': ')))
endef
export REPORT_PY
define CONFIG
input { stdin { type => talisker }}
output {
file {
path => "$(LOGSTASH_PATTERNS_LXC)/$(LOGSTASH_RESULTS)"
codec => json_lines
}
}
endef
export CONFIG
$(LOGSTASH_CONFIG): talisker/logstash/talisker.filter
echo "$$CONFIG" > $(LOGSTASH_CONFIG)
cat talisker/logstash/talisker.filter >> $(LOGSTASH_CONFIG)
logstash-check: $(LOGSTASH_CONFIG)
$(LOGSTASH) -t
logstash-test: $(LOGSTASH_CONFIG)
rm talisker/logstash/$(LOGSTASH_RESULTS) -f
cat tests/test.log | grep -v '^#' | $(LOGSTASH) --quiet
cat talisker/logstash/$(LOGSTASH_RESULTS) | python -c "$$REPORT_PY"
logstash-test-truncate: $(LOGSTASH_CONFIG)
sed -i 's/20000/100/' $(LOGSTASH_CONFIG)
rm talisker/logstash/$(LOGSTASH_RESULTS) -f
cat tests/test_truncate.log | grep -v '^#' | $(LOGSTASH) --quiet
cat talisker/logstash/$(LOGSTASH_RESULTS) | jq
rm $(LOGSTASH_CONFIG)
logstash-show:
cat talisker/logstash/$(LOGSTASH_RESULTS) | jq