-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
122 lines (97 loc) · 3.48 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
GUNICORN_CONF = example_conf/gunicorn.py
LOG_CONFIG = example_conf/logging.ini
CONF_FILE ?= example_conf/jarr.json
SERVER_PORT = 8000
SERVER_ADDR = 0.0.0.0
DB_VER = $(shell pipenv run flask db heads | tail -n1 | sed -e 's/ .*//g')
COMPOSE_FILE ?= Dockerfiles/dev-env.yml
RUN = FLASK_APP=wsgi PIPENV_IGNORE_VIRTUALENVS=1 pipenv run
COMPOSE = $(RUN) docker compose --project-name jarr --file $(COMPOSE_FILE)
TEST = tests/
DB_NAME ?= jarr
PUBLIC_URL ?=
REACT_APP_API_URL ?=
QUEUE ?= jarr,jarr-crawling,jarr-clustering
DB_CONTAINER_NAME = postgres
QU_CONTAINER_NAME = rabbitmq
install:
pipenv sync --dev
pep8:
$(RUN) pycodestyle --ignore=E126,E127,E128,W503 jarr/ --exclude=jarr/migrations
mypy:
$(RUN) mypy jarr --ignore-missing-imports --exclude=jarr/crawler/lib/__init__.py
lint: pep8 mypy
test: export JARR_CONFIG = example_conf/jarr.test.json
test:
$(RUN) pytest --cov=jarr $(TEST) -vv
build-base:
docker build --cache-from=jarr . \
--file Dockerfiles/pythonbase \
-t jarr-base
build-server:
docker build --cache-from=jarr . \
--file Dockerfiles/server \
-t jarr-server
build-worker:
docker build --cache-from=jarr . \
--file Dockerfiles/worker \
-t jarr-worker
build-front:
docker build --cache-from=jarr . \
--file Dockerfiles/front -t jarr-front \
--build-arg PUBLIC_URL=$(PUBLIC_URL) \
--build-arg REACT_APP_API_URL=$(REACT_APP_API_URL)
start-env:
$(COMPOSE) up -d
run-server: export JARR_CONFIG = $(CONF_FILE)
run-server:
$(RUN) gunicorn -c $(GUNICORN_CONF) -b $(SERVER_ADDR):$(SERVER_PORT) wsgi:application
run-worker: export JARR_CONFIG = $(CONF_FILE)
run-worker:
$(RUN) celery --app ep_celery.celery_app worker -Q $(QUEUE) --hostname "$(QUEUE)@%h"
run-front:
cd jsclient/; yarn start
db-bootstrap-user:
$(COMPOSE) exec $(DB_CONTAINER_NAME) su postgres -c \
"createuser $(DB_NAME) --superuser --createdb"
db-bootstrap-tables:
$(COMPOSE) exec $(DB_CONTAINER_NAME) su postgres -c "createdb $(DB_NAME) --no-password"
$(COMPOSE) exec $(DB_CONTAINER_NAME) psql -h 0.0.0.0 -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $(DB_NAME) to $(DB_NAME);"
db-import-dump:
docker cp $(DUMP) jarr_$(DB_CONTAINER_NAME)_1:/tmp/dump.pgsql
$(COMPOSE) exec $(DB_CONTAINER_NAME) su postgres -c "pg_restore -d $(DB_NAME) /tmp/dump.pgsql"
$(COMPOSE) exec $(DB_CONTAINER_NAME) rm /tmp/dump.pgsql
init-env: export JARR_CONFIG = $(CONF_FILE)
init-env:
$(RUN) flask bootstrap-database
$(RUN) flask db stamp $(DB_VER)
init-env-docker: export JARR_CONFIG = $(CONF_FILE)
init-env-docker:
$(COMPOSE) exec jarr-server pipenv run flask bootstrap-database
$(COMPOSE) exec jarr-server pipenv run flask db stamp $(DB_VER)
db: export JARR_CONFIG = $(CONF_FILE)
db:
$(RUN) flask db $(COMMAND)
stop-env:
$(COMPOSE) down --remove-orphans
clean-env: stop-env
$(COMPOSE) rm --force
status-env:
$(COMPOSE) ps
setup-testing: export DB_NAME=jarr_test
setup-testing: export JARR_CONFIG=example_conf/jarr.test.json
setup-testing: export CONF_FILE=example_conf/jarr.test.json
setup-testing:
make start-env
@echo "### waiting for database to be available"
sleep 2
make db-bootstrap-user
make db-bootstrap-tables
make init-env
init-rabbitmq:
$(COMPOSE) exec $(QU_CONTAINER_NAME) rabbitmqctl add_user jarr jarr
$(COMPOSE) exec $(QU_CONTAINER_NAME) rabbitmqctl add_vhost jarr
$(COMPOSE) exec $(QU_CONTAINER_NAME) rabbitmqctl set_user_tags jarr
$(COMPOSE) exec $(QU_CONTAINER_NAME) rabbitmqctl set_permissions -p jarr jarr ".*" ".*" ".*"
init-worker:
$(RUN) python -c "from jarr.crawler.main import scheduler;scheduler()"