-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
114 lines (88 loc) · 3.55 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
## for start mySQL container:
SHELL := /bin/bash
LOCAL_COMPOSE_FILE := infra/dev/docker-compose.local.yaml
COLOR_RESET = \033[0m
COLOR_GREEN = \033[32m
COLOR_YELLOW = \033[33m
COLOR_WHITE = \033[00m
.DEFAULT_GOAL := help
.PHONY: help
help: # Show help
@echo -e "$(COLOR_GREEN)Makefile help:"
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "$(COLOR_GREEN)-$$(echo $$l | cut -f 1 -d':'):$(COLOR_WHITE)$$(echo $$l | cut -f 2- -d'#')\n"; done
.PHONY: runbot-init
runbot-init: deletedb rundb migrate filldb collectstatic runbot-db # Build and run Database Docker-image
@echo -e "$(COLOR_YELLOW)Starting initialization...$(COLOR_RESET)"
@source $$(poetry env info -p)/bin/activate
.PHONY: rundb
rundb: # Build and run Database Docker-image
@echo -e "$(COLOR_YELLOW)Starting database...$(COLOR_RESET)"
@until docker compose -f $(LOCAL_COMPOSE_FILE) up -d; do \
echo -e "$(COLOR_YELLOW)Waiting database to be started...$(COLOR_RESET)"; \
sleep 5 ;\
done
@sleep 3 ;
@echo -e "$(COLOR_GREEN)Database started$(COLOR_RESET)"
.PHONY: stopdb
stopdb: # Stop mySQL Database Docker-image
@echo -e "$(COLOR_YELLOW)Stopping database...$(COLOR_RESET)"
@docker compose -f $(LOCAL_COMPOSE_FILE) down
@echo -e "$(COLOR_GREEN)Database stopped$(COLOR_RESET)"
.PHONY: deletedb
deletedb: # Stop and delete mySQL database Docker-image and volumes
@echo -e "$(COLOR_YELLOW)Deleting database...$(COLOR_RESET)"
@until docker compose -f $(LOCAL_COMPOSE_FILE) down --volumes; do \
echo -e "$(COLOR_YELLOW)Waiting database to be deleted...$(COLOR_RESET)"; \
sleep 5 ;\
done
@sleep 3 ;
@echo -e "$(COLOR_GREEN)Database deleted$(COLOR_RESET)"
.PHONY: runbot-db
runbot-db: # Run Telegram bot on Uvicorn
@echo -e "$(COLOR_YELLOW)Starting bot...$(COLOR_RESET)"
@cd src && poetry run uvicorn config.asgi:application --reload && cd .. && \
echo -e "$(COLOR_GREEN)Bot stopped$(COLOR_RESET)"
.PHONY: filldb
filldb: # Fill Docker-image Database with test data
@echo -e "$(COLOR_YELLOW)Filing database...$(COLOR_RESET)"
@until poetry run python src/manage.py filldb; do \
echo -e "$(COLOR_YELLOW)Waiting database to be filled...$(COLOR_RESET)"; \
sleep 5 ;\
done
@sleep 3 ;
@echo -e "$(COLOR_GREEN)Database filled$(COLOR_RESET)"
.PHONY: collectstatic
collectstatic: # Collect project static files
@echo -e "$(COLOR_YELLOW)Collecting static...$(COLOR_RESET)"
@until poetry run python src/manage.py collectstatic; do \
echo -e "$(COLOR_YELLOW)Waiting static to be collected...$(COLOR_RESET)"; \
sleep 5 ;\
done
@sleep 3;
@echo -e "$(COLOR_GREEN)Static collected$(COLOR_RESET)"
.PHONY: migrate
migrate: # Commit migrations to Database
@echo -e "$(COLOR_YELLOW)Migrating...$(COLOR_RESET)"
@until poetry run python src/manage.py migrate; do \
echo "Waiting for migrations..."; \
sleep 5; \
done
@sleep 3;
@echo -e "$(COLOR_GREEN)Migrated$(COLOR_RESET)"
.PHONY: createsuperuser
createsuperuser:
@echo -e "$(COLOR_YELLOW)Creating Django superuser...$(COLOR_RESET)"
@poetry run python src/manage.py createsuperuser
.PHONY: run_tests
run_tests: run_unit_tests # Run all tests
@echo -e "$(COLOR_GREEN)All tests passed$(COLOR_RESET)"
.PHONY: run_unit_tests
run_unit_tests: # Run unit tests
@echo -e "$(COLOR_YELLOW)Start unit tests...$(COLOR_RESET)"
@poetry run pytest src/tests/unit
@echo -e "$(COLOR_GREEN)Unit tests passed$(COLOR_RESET)"
.PHONY: create_superuser
create_superuser: # Run unit tests
@echo -e "$(COLOR_YELLOW)Creating superuser...$(COLOR_RESET)"
@poetry run python src/manage.py initadmin
@echo -e "$(COLOR_GREEN)Superuser created$(COLOR_RESET)"