-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
97 lines (65 loc) · 2.3 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
ifeq ($(shell test -e '.env' && echo -n yes),yes)
include .env
endif
# Manually define main variables
ifndef APP_PORT
override APP_PORT = 8080
endif
ifndef APP_HOST
override APP_HOST = 127.0.0.1
endif
args := $(wordlist 2, 100, $(MAKECMDGOALS))
ifndef args
MESSAGE = "No such command (or you pass two or many targets to ). List of possible commands: make help"
else
MESSAGE = "Done"
endif
APPLICATION_NAME=detector
ROOT=`echo $(PWD)`
TEST = poetry run python3 -m pytest --verbosity=2 --showlocals --log-level=DEBUG
CODE = $(APPLICATION_NAME) tests
DOCKER_RUN = docker run -p 8000:8000 -it --env-file .env $(APPLICATION_NAME)
HELP_FUN = \
%help; while(<>){push@{$$help{$$2//'options'}},[$$1,$$3] \
if/^([\w-_]+)\s*:.*\#\#(?:@(\w+))?\s(.*)$$/}; \
print"$$_:\n", map" $$_->[0]".(" "x(20-length($$_->[0])))."$$_->[1]\n",\
@{$$help{$$_}},"\n" for keys %help; \
# Commands
env: ##@Environment Create .env file with variables
@$(eval SHELL:=/bin/bash)
@cp .env.example .env
@echo "SECRET_KEY=$$(openssl rand -hex 32)" >> .env
args := $(wordlist 2, 100, $(MAKECMDGOALS))
# Code style
fmt:
cd backend && poetry run python3 -m isort $(APPLICATION_NAME)
cd backend && poetry run python3 -m black $(APPLICATION_NAME)
lint:
cd backend && poetry run pylint ${APPLICATION_NAME}
# Docker
db:
docker compose --env-file ./.env -f deploy/docker-compose.yml up db -d
open_db: ##@Database Open database inside docker-image
docker exec -it db psql -d $(POSTGRES_DB) -U $(POSTGRES_USER)
# Docker building
docker-build:
docker compose --env-file ./.env -f deploy/docker-compose.yml build $(args)
docker-run:
docker compose --env-file ./.env -f deploy/docker-compose.yml up -d --remove-orphans
# Application cmds
run:
cd backend && uvicorn ${APPLICATION_NAME}.__main__:app --reload --port 8080
celery:
cd backend && celery -A backend.tasks.app_worker worker
# Migrations
revision:
cd ${APPLICATION_NAME}/db && alembic revision --autogenerate -m $(args)
migrate:
cd ${APPLICATION_NAME}/db && alembic upgrade $(args)
migrate-downgrade:
cd ${APPLICATION_NAME}/db && alembic downgrade -1
# Tests
test: ##@Testing Test application with pytest
make db && $(TEST)
test-cov: ##@Testing Test application with pytest and create coverage report
make db && $(TEST) --cov=$(APPLICATION_NAME) --cov-report html --cov-fail-under=70