-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
94 lines (79 loc) · 3.41 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
# these will speed up builds, for docker-compose >= 1.25
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1
all: init down build up
build:
@echo "\e[93m>> Building the containers\e[0m"
docker-compose build
up:
@echo "\e[93m>> Running all of the containers\e[0m"
docker-compose up -d --scale cm-worker=3 --scale cm-updater=1 --scale cm-analyzer=1 --scale cm-dashboard=1
down:
@echo "\e[93m>> Shutting down the containers\e[0m"
ifneq ($(shell docker ps -f ancestor="captchamonitor-tor-container" -q),)
@echo "\e[93m>> Killing captchamonitor-tor-container instances\e[0m"
docker kill $$(sudo docker ps -f ancestor="captchamonitor-tor-container" -q)
endif
docker-compose down --remove-orphans
test: pretest
@echo "\e[93m>> Executing all tests\e[0m"
docker-compose run --rm --no-deps --entrypoint="pytest -v --reruns 3 --reruns-delay 3 --cov=/src/captchamonitor/ --cov-report term-missing" captchamonitor /tests
pretest: down
@echo "\e[93m>> Preparing the containers for testing\e[0m"
docker-compose up -d --scale cm-worker=0 --scale cm-updater=0 --scale cm-analyzer=0 --scale cm-dashboard=0
singletest:
ifndef TEST
@echo "\e[93m>> TEST is undefined. Please set TEST environment variable to the name of the TEST to execute\e[0m"
@echo "\e[93m>> Example usage: TEST=test_onionoo_init make singletest\e[0m"
exit 1
endif
@echo "\e[93m>> Executing test '$(TEST)'\e[0m"
docker-compose run --rm --no-deps --entrypoint="pytest --log-cli-level=INFO --full-trace -v -x -s -k $(TEST)" captchamonitor /tests
logs:
@echo "\e[93m>> Printing the logs\e[0m"
docker-compose logs --tail=100 captchamonitor cm-worker cm-updater cm-analyzer cm-dashboard
init: check_root
@echo "\e[93m>> Creating .env file\e[0m"
rm -f .env
cp .env.example .env
@echo "\n\e[93m>> Installing requirements\e[0m"
pip3 install -q --upgrade --force-reinstall -r requirements.txt
@echo "\n\e[93m>> Building Docker images\e[0m"
make build
@echo "\n\e[92m>> Done!\e[0m"
docs: check_non_root FORCE
@echo "\e[93m>> Installing the package\e[0m"
pip3 install -e src/
@echo "\n\e[93m>> Generating documentation from docstrings\e[0m"
sphinx-apidoc -f -o ./docs/sphinx/ ./src/captchamonitor/
@echo "\n\e[93m>> Building the documentation\e[0m"
sphinx-build -b html ./docs/sphinx/ public
@echo "\n\e[92m>> Done!\e[0m"
check: check_root
@echo "\e[93m>> Running isort\e[0m"
isort --profile black .
@echo "\n\e[93m>> Running black\e[0m"
black --line-length 88 $$(find * -name '*.py' 2>&1 | grep -v 'Permission denied')
@echo "\n\e[93m>> Running mypy\e[0m"
mypy ./src
@echo "\n\e[93m>> Running pylint\e[0m"
pylint -v ./src ./tests ./tests/unit ./tests/integration
@echo "\n\e[93m>> Running darglint\e[0m"
darglint -s sphinx -v 2 ./src
@echo "\n\e[93m>> Running jinja ninja\e[0m"
jinja-ninja src/captchamonitor/dashboard/templates
@echo "\n\e[92m>> Everything seems all right!\e[0m"
render_dashboard:
@echo "\e[93m>> Rendering the dashboard and checking for changes\e[0m"
find src/captchamonitor/dashboard/ -not -path "*www*" | entr -s 'echo -e "\e[92m" && echo -n `date +">> Detected a change at %a %d %b %Y %H:%M:%S %Z"` && echo -e " \e[0m" && docker-compose kill cm-dashboard && docker-compose up -d cm-dashboard && echo -e "\e[92m>> Done!\e[0m"'
check_non_root:
ifeq ($(shell id -u), 0)
@echo "\n\e[93m>> Please run this command without sudo\e[0m"
exit 1
endif
check_root:
ifneq ($(shell id -u), 0)
@echo "\n\e[93m>> Please run this command with sudo\e[0m"
exit 1
endif
FORCE: ;