-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Makefile
120 lines (93 loc) · 3.25 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
DOCKER := docker
DOCKER_COMPOSE := docker-compose
RESOURCES_CONTAINER := resources-api
RESOURCES_DB := resources-postgres
FLASK := flask
ARGS = $(filter-out $@,$(MAKECMDGOALS))
.PHONY: all
ifeq ($(OS),Windows_NT)
all: run_windows
else
all: run
endif
.PHONY: shell
shell:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} shell
.PHONY: nuke
nuke:
${DOCKER} system prune -a --volumes
.PHONY: minty-fresh
minty-fresh:
${DOCKER_COMPOSE} down --rmi all --volumes --remove-orphans
add remove:
@if [ -z $(shell echo ${ARGS} | cut -d' ' -f1) ]; then echo "Please provide a proper package name"; exit 1; fi
if [ ! "$$(${DOCKER} ps -q -f name=resources-api)" ]; then ${DOCKER_COMPOSE} up --build -d; fi
${DOCKER} exec ${RESOURCES_CONTAINER} /bin/bash -c "poetry $@ $(shell echo ${ARGS} | cut -d' ' -f1)"
%:
@:
.PHONY: rmi
rmi:
${DOCKER} images -q | xargs docker rmi -f
.PHONY: rmdi
rmdi:
${DOCKER} images -a --filter=dangling=true -q | xargs ${DOCKER} rmi
.PHONY: rm-exited-containers
rm-exited-containers:
${DOCKER} ps -a -q -f status=exited | xargs ${DOCKER} rm -v
.PHONY: fresh-restart
fresh-restart: minty-fresh test setup run
.PHONY: run-with-metrics
run-with-metrics: build
if [ "$$(${DOCKER} ps -q -f name=resources-api)" ]; then ${DOCKER_COMPOSE} down; fi
${DOCKER_COMPOSE} run -p 5000:5000 ${RESOURCES_CONTAINER}
.PHONY: run
run: build
if [ "$$(${DOCKER} ps -q -f name=resources-api)" ]; then ${DOCKER_COMPOSE} down; fi
${DOCKER_COMPOSE} run -p 5000:5000 ${RESOURCES_CONTAINER} ${FLASK} run -h 0.0.0.0
run_windows: build
@cmd /c (IF NOT "$(shell ${DOCKER} ps -q -f name=resources-api)" == "" ${DOCKER_COMPOSE} down)
${DOCKER_COMPOSE} run -p 5000:5000 ${RESOURCES_CONTAINER} ${FLASK} run -h 0.0.0.0
.PHONY: bg
bg:
${DOCKER_COMPOSE} up --build -d
.PHONY: routes
routes:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} routes
.PHONY: test
test: build
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} py.test --cov=app/ tests/
.PHONY: test-coverage
test-coverage:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} py.test --cov-report html --cov=app/ tests/
# Usage: make test-single tests/unit/test_api_key.py::test_get_api_key
.PHONY: test-single
test-single: build
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} /bin/bash -c "py.test --cov=app/ $(shell echo ${ARGS})"
.PHONY: lint
lint:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} flake8 . --exclude migrations --statistics --count
.PHONY: bandit
bandit:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} bandit -r .
.PHONY: help
help: build
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} --help
.PHONY: build
build:
${DOCKER_COMPOSE} build --pull ${RESOURCES_CONTAINER}
.PHONY: setup
setup: bg
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK}
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} db-migrate create-tables
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} db stamp head
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} db-migrate init
.PHONY: migrate
migrate: build
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} db migrate
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} db upgrade
.PHONY: reindex
reindex:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} algolia reindex
.PHONY: bad-urls
bad-urls:
${DOCKER_COMPOSE} run ${RESOURCES_CONTAINER} ${FLASK} check-bad-urls