-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
166 lines (121 loc) · 8.02 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
help: ## Display a help message detailing commands and their purpose
@echo "Commands:"
@grep -E '^([a-zA-Z_-]+:.*?## .*|#+ (.*))$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
## [Managing the project]
### Stopping the containers and dropping the databases
stop-sqlite: ## stops the sqlite dev project
docker compose down -t 60
drop-sqlite: ## drops the sqlite dev project
docker compose down -v -t 60
rm -rf ./backend/.db_sqlite
stop-psql: ## stops the psql dev project
docker compose -f docker-compose.psql.yml down -t 60
drop-psql: ## drops the psql dev project
docker compose -f docker-compose.psql.yml down -v -t 60
stop-prod: ## stops the prod project
docker compose -f docker-compose.prod.yml down -t 60
drop-prod: ## drops the prod project
docker compose -f docker-compose.prod.yml down -v -t 60
### Building & starting the containers
up-sqlite: ## run the project with sqlite
docker compose up --build
upd-sqlite: ## run the project with sqlite in detached mode
docker compose up -d --build
up-psql: ## run the project with psql
docker compose -f docker-compose.psql.yml up --build
upd-psql: ## run the project with psql in detached mode
docker compose -f docker-compose.psql.yml up -d --build
up-prod: ## run the project with psql in production
docker compose -f docker-compose.prod.yml up --build
upd-prod: ## run the project with psql in production in detached mode
docker compose -f docker-compose.prod.yml up -d --build
### Using the SQLite database
run-sqlite: stop-psql up-sqlite ## run the project with sqlite and stop the psql project beforehand
rund-sqlite: stop-psql upd-sqlite ## run the project with sqlite in detached mode and stop the psql project beforehand
redo-sqlite: drop-sqlite up-sqlite ## delete the db and rerun the project with sqlite
redod-sqlite: drop-sqlite upd-sqlite ## delete the db and rerun the project with sqlite in detached mode
### Using the PostgreSQL database
run-psql: stop-sqlite up-psql ## run the project with psql and stop the sqlite project beforehand
rund-psql: stop-sqlite upd-psql ## run the project with psql in detached mode and stop the project project beforehand
redo-psql: drop-psql up-psql ## delete the db and rerun the project with psql
redod-psql: drop-psql upd-psql ## delete the db and rerun the project with psql in detached mode
### Using the Production configuration
run-prod: up-prod ## run the project with prod
rund-prod: upd-prod ## run the project with prod in detached mode
redo-prod: drop-prod up-prod ## delete the db and rerun the project with prod
redod-prod: drop-prod upd-prod ## delete the db and rerun the project with prod in detached mode
### Other run options
run: run-sqlite ## set the default run command to sqlite
redo: redo-sqlite ## set the default redo command to sqlite
rund: rund-sqlite ## set the default run command to sqlite
redod: redod-sqlite ## set the default redo command to sqlite
stop: stop-sqlite stop-psql stop-prod ## stop all running projects
drop: drop-sqlite drop-psql drop-prod ## drop all databases
## [Monitoring the containers]
logs-dev: ## show the logs of the containers
docker logs -f redirect_dev
logs: logs-dev ## set the default logs command to dev
logs-prod: ## show the logs of the containers
docker logs -f redirect_prod
## [Django operations]
makemigrations: ## generate migrations in a clean container
docker exec redirect_dev sh -c "python3 -Wd ./backend/manage.py makemigrations $(apps)"
migrate: ## apply migrations in a clean container
docker exec redirect_dev sh -c "python3 -Wd ./backend/manage.py migrate $(apps)"
migrations: makemigrations migrate ## generate and apply migrations
makemessages: ## generate the strings marked for translation
docker exec redirect_dev sh -c "python3 -Wd ./backend/manage.py makemessages -a"
compilemessages: ## compile the translations
docker exec redirect_dev sh -c "python3 -Wd ./backend/manage.py compilemessages"
messages: makemessages compilemessages ## generate and compile the translations
collectstatic: ## collect the static files
docker exec redirect_dev sh -c "python3 -Wd ./backend/manage.py collectstatic --no-input"
format: ## format the code with black & ruff
docker exec redirect_dev sh -c "black ./backend && ruff check --fix ./backend"
pyshell: ## start a django shell
docker exec -it redirect_dev sh -c "python3 -Wd ./backend/manage.py shell"
sh: ## start a sh shell
docker exec -it redirect_dev sh -c "sh"
bash: ## start a bash shell
docker exec -it redirect_dev sh -c "bash"
## [Requirements management]
requirements-build: ## run pip compile and add requirements from the *.in files
docker exec redirect_dev sh -c " \
cd ./backend && \
pip-compile --strip-extras --resolver=backtracking -o requirements.txt requirements.in && \
pip-compile --strip-extras --resolver=backtracking -o requirements-dev.txt requirements-dev.in \
"
requirements-update: ## run pip compile and rebuild the requirements files
docker exec redirect_dev sh -c " \
cd ./backend && \
pip-compile --strip-extras --resolver=backtracking -r -U -o requirements.txt requirements.in && \
pip-compile --strip-extras --resolver=backtracking -r -U -o requirements-dev.txt requirements-dev.in && \
chmod a+r requirements.txt && \
chmod a+r requirements-dev.txt \
"
## [Clean-up]
clean-docker: ## stop docker containers and remove orphaned images and volumes
docker compose down -t 60
docker compose -f docker-compose.psql.yml down -t 60
docker compose -f docker-compose.prod.yml down -t 60
docker system prune -f
clean-extras: ## remove test, coverage, file artifacts, and compiled message files
find ./backend -name '*.mo' -delete
find ./backend -name '*.pyc' -delete
find ./backend -name '*.pyo' -delete
find ./backend -name '.coverage' -delete
find ./backend -name '.pytest_cache' -delete
find ./backend -name '.ruff_cache' -delete
find ./backend -name '__pycache__' -delete
find ./backend -name 'htmlcov' -delete
find ./backend -name '.bower_components' -delete
clean-db: ## remove the database files
rm -rf ./backend/media ./backend/static ./frontend/dist
clean: clean-docker clean-extras clean-db ## remove all build, test, coverage and Python artifacts
## [Project-specific operations]
mock-data: ## generate fake data
docker exec redirect_dev python3 -Wd ./backend/manage.py generate_orgs 20
docker exec redirect_dev python3 -Wd ./backend/manage.py generate_orgs 50 --valid
docker exec redirect_dev python3 -Wd ./backend/manage.py generate_partners 5
docker exec redirect_dev python3 -Wd ./backend/manage.py generate_donations 100