-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
108 lines (82 loc) · 2.17 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
SHELL := /bin/bash
ACTIVATE_VENV := source venv/bin/activate
ins := $(wildcard requirements/*.in)
reqs := $(ins:requirements/%.in=requirements/%.txt) requirements.txt
docker_image := unfair-coin-bayes
docker_container := app
.PHONY: all
all: clean deploy-prod
# Deployment
.PHONY: deploy-dev
deploy-dev: .make.dev
$(ACTIVATE_VENV) && bin/run dev
.PHONY: deploy-prod
deploy-prod: .make.prod
$(ACTIVATE_VENV) && bin/run prod
.PHONY: docker-image
docker-image:
docker build -t $(docker_image) .
.PHONY: docker-run
docker-run: docker-image
docker run \
--init \
--rm \
-d \
--publish 127.0.0.1:8000:8000 \
--env SECRET_KEY=$$(bin/set-secret-key --) \
--name $(docker_container) \
$(docker_image)
.PHONY: docker-stop
docker-stop:
docker container stop $(docker_container)
# Virtual Environments
venv:
python3 -m venv $@
.PHONY: venv-base
venv-base: .make.base
.make.base: requirements/base.txt | venv
$(ACTIVATE_VENV) && pip install pip==20.3.0
$(ACTIVATE_VENV) && pip install -r $<
touch $@
.PHONY: venv-prod
venv-prod: .make.prod
.make.prod: requirements/prod.txt | .make.base
$(ACTIVATE_VENV) && pip-sync $<
rm -rf .make.dev
touch $@
.PHONY: venv-dev
venv-dev: .make.dev
.make.dev: requirements/prod.txt requirements/dev.txt | .make.base
$(ACTIVATE_VENV) && pip-sync $^
rm -rf .make.prod
touch $@
# Requirements
.PHONY: requirements
requirements: $(reqs)
requirements/%.txt: requirements/%.in requirements/constraints.txt | .make.base
$(ACTIVATE_VENV) && pip-compile $<
requirements/dev.txt: requirements/prod.txt
requirements/base.txt:
# Avoid circular reference caused by venv rule
:
requirements.txt: requirements/prod.txt | .make.prod
$(ACTIVATE_VENV) && pip freeze > $@
# Utility
.PHONY: tests
tests: test-unit test-lint test-docker
.PHONY: test-unit
test-unit: .make.dev
$(ACTIVATE_VENV) && pytest -s --cov=app --cov-report=term --cov-report=xml
.PHONY: test-lint
test-lint: .make.dev
$(ACTIVATE_VENV) && flake8 app tests
.PHONY: test-docker
test-docker:
tests/test-docker
.PHONY: tox
tox: .make.dev
$(ACTIVATE_VENV) && tox
.PHONY: clean
clean:
rm -rf venv .pytest_cache .coverage coverage.xml .make.* .tox
find . | grep __pycache__ | xargs rm -rf