forked from 0xEDU/ft_transcendence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
169 lines (117 loc) · 5.9 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
## VARS
PYTHON_VERSION = python3.10
# Services names
DB_SERVICE_NAME = postgres-transcendence
APP_SERVICE_NAME = django-transcendence
GANACHE_SERVICE_NAME = ganache-transcendence
CONTRACT_DEPLOYER_SERVICE_NAME = contract-deployer-transcendence
SERVICES = $(DB_SERVICE_NAME) $(APP_SERVICE_NAME) $(GANACHE_SERVICE_NAME) $(CONTRACT_DEPLOYER_SERVICE_NAME)
# Scripts
DOCKER_SCRIPTS = $(addprefix _compose_scripts/,conditional-delete-container.sh conditional-delete-image.sh conditional-delete-volume.sh conditional-stop-container.sh)
# Virtual environment
VENV_DIR = ../ft_transcendence-venv
# Colours
BOLD_YELLOW = \e[1;33m
BOLD_RED = \033[1;91m
RESET = \e[0m
## RULES
# ALL ------------------------------------------------------------------------ #
start: .env volumes docker-compose.yml
docker-compose up --build --detach --force-recreate
stop:
docker-compose down
restart: stop start
run:
$(PYTHON_VERSION) manage.py runserver
migrate:
$(PYTHON_VERSION) manage.py migrate
load_fixtures: migrate
$(PYTHON_VERSION) manage.py loaddata users achievements userstats pong_score pong_match
clean: clean-db clean-app
fclean: fclean-db fclean-app fclean-ganache fclean-contract-deployer
@printf "⚠️ $(BOLD_YELLOW)[WARNING]$(RESET) If you're $(BOLD_YELLOW)SURE$(RESET) you want to delete the volumes, do it manually!\n"
frestart: fclean start
# DATABASE ------------------------------------------------------------------- #
start-db: .env volumes docker-compose.yml
docker-compose up --build --detach $(DB_SERVICE_NAME)
stop-db: docker-compose.yml
@./_compose_scripts/conditional-stop-container.sh $(DB_SERVICE_NAME)
restart-db: volumes docker-compose.yml
docker-compose up --build --detach --force-recreate $(DB_SERVICE_NAME)
clean-db: chmod-scripts
@./_compose_scripts/conditional-stop-container.sh $(DB_SERVICE_NAME)
@./_compose_scripts/conditional-delete-container.sh $(DB_SERVICE_NAME)
fclean-db: clean-db
@./_compose_scripts/conditional-delete-image.sh postgres
frestart-db: fclean-db start-db
# DJANGO --------------------------------------------------------------------- #
start-app: .env docker-compose.yml
docker-compose up --build --detach $(APP_SERVICE_NAME)
stop-app: docker-compose.yml
@./_compose_scripts/conditional-stop-container.sh $(APP_SERVICE_NAME)
restart-app: docker-compose.yml
docker-compose up --build --detach --force-recreate $(APP_SERVICE_NAME)
clean-app: chmod-scripts
@./_compose_scripts/conditional-stop-container.sh $(APP_SERVICE_NAME)
@./_compose_scripts/conditional-delete-container.sh $(APP_SERVICE_NAME)
fclean-app: clean-app
@./_compose_scripts/conditional-delete-image.sh django
frestart-app: fclean-app start-app
# BLOCKCHAIN ----------------------------------------------------------------- #
start-ganache: .env docker-compose.yml
docker-compose up --build --detach $(GANACHE_SERVICE_NAME)
stop-ganache: docker-compose.yml
@./_compose_scripts/conditional-stop-container.sh $(GANACHE_SERVICE_NAME)
restart-ganache: docker-compose.yml
docker-compose up --build --detach --force-recreate $(GANACHE_SERVICE_NAME)
clean-ganache: chmod-scripts
@./_compose_scripts/conditional-stop-container.sh $(GANACHE_SERVICE_NAME)
@./_compose_scripts/conditional-delete-container.sh $(GANACHE_SERVICE_NAME)
fclean-ganache: clean-ganache
@./_compose_scripts/conditional-delete-image.sh $(GANACHE_SERVICE_NAME)
frestart-ganache: fclean-ganache start-ganache
# EVEN MORE BLOCKCHAIN ------------------------------------------------------- #
start-contract-deployer: .env docker-compose.yml
docker-compose up --build --detach $(CONTRACT_DEPLOYER_SERVICE_NAME)
stop-contract-deployer: docker-compose.yml
@./_compose_scripts/conditional-stop-container.sh $(CONTRACT_DEPLOYER_SERVICE_NAME)
restart-contract-deployer: docker-compose.yml
docker-compose up --build --detach --force-recreate $(CONTRACT_DEPLOYER_SERVICE_NAME)
clean-contract-deployer: chmod-scripts
@./_compose_scripts/conditional-stop-container.sh $(CONTRACT_DEPLOYER_SERVICE_NAME)
@./_compose_scripts/conditional-delete-container.sh $(CONTRACT_DEPLOYER_SERVICE_NAME)
fclean-contract-deployer: clean-contract-deployer
@./_compose_scripts/conditional-delete-image.sh $(CONTRACT_DEPLOYER_SERVICE_NAME)
frestart-contract-deployer: fclean-contract-deployer start-contract-deployer
# AUXILIAR ------------------------------------------------------------------- #
chmod-scripts: $(DOCKER_SCRIPTS)
chmod +x $(DOCKER_SCRIPTS)
volumes:
mkdir -p ~/goinfre/ft_transcendence/django \
~/goinfre/ft_transcendence/ganache \
~/goinfre/ft_transcendence/postgres
fetch-translation-hooks:
django-admin makemessages -a
compile-translations:
django-admin compilemessages
check-python:
@command -v $(PYTHON_VERSION) >/dev/null 2>&1 || { echo >&2 "❌ $(BOLD_RED)[ERROR]$(RESET) $(BOLD_YELLOW)$(PYTHON_VERSION)$(RESET) is required but not installed. $(BOLD_RED)Aborting.$(RESET)"; exit 1; }
create-venv: check-python
$(PYTHON_VERSION) -m venv $(VENV_DIR)
delete-venv:
rm -rf $(VENV_DIR)
install_dependencies:
@read -p "Have you already activated the virtual environment? (y/n): " choice; \
if [ "$$choice" = "y" ] || [ "$$choice" = "Y" ]; then \
pip install -r requirements.txt; \
else \
printf "\nPlease activate the virtual environment first.\n"; \
printf "To create the virtual environment, run $(BOLD_YELLOW)'make create-venv'$(RESET).\n"; \
fi
# ---------------------------------------------------------------------------- #
.PHONY: start stop restart run migrate seed clean fclean frestart \
db-start db-stop db-restart db-clean db-fclean db-frestart \
app-start app-stop app-restart app-clean app-fclean app-frestart \
ganache-start ganache-stop ganache-restart ganache-clean ganache-fclean ganache-frestart \
contract-deployer-start contract-deployer-stop contract-deployer-restart contract-deployer-clean contract-deployer-fclean contract-deployer-frestart \
chmod-scripts volumes fetch-translation-hooks compile-translations check-python create-venv delete-venv install