-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
298 lines (253 loc) · 11.7 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
PROJECT_ID := georepo
export COMPOSE_FILE=deployment/docker-compose.yml:deployment/docker-compose.override.yml
SHELL := /bin/bash
# ----------------------------------------------------------------------------
# P R O D U C T I O N C O M M A N D S
# ----------------------------------------------------------------------------
default: web
run: build web collectstatic
deploy: run
@echo
@echo "------------------------------------------------------------------"
@echo "Bringing up fresh instance "
@echo "You can access it on http://localhost"
@echo "------------------------------------------------------------------"
update:
@echo
@echo "------------------------------------------------------------------"
@echo "Update production instance"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d django auth worker celery_beat nginx
# use .azure.env in docker-compose.override.yml
test-azure:
@echo
@echo "------------------------------------------------------------------"
@echo "Run Azure production instance"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d azurite django auth worker celery_beat nginx logrotate
# below commands are executed already from django entrypoint+initialize.py
# @docker compose ${ARGS} exec -T django python manage.py migrate
# @docker compose ${ARGS} exec -T django npm --prefix /home/web/django_project/dashboard install /home/web/django_project/dashboard --legacy-peer-deps
# @docker compose ${ARGS} exec -T django npm run build-react --prefix /home/web/django_project/dashboard
# @docker compose ${ARGS} exec -T django python manage.py collectstatic --noinput
# @docker compose ${ARGS} restart django auth worker celery_beat nginx
kill-django:
@echo
@echo "------------------------------------------------------------------"
@echo "Killing in production mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} stop django auth worker nginx
down-django: kill-django
@echo
@echo "------------------------------------------------------------------"
@echo "Removing production instance!!! "
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} rm -f django nginx auth worker
web:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in production mode"
@echo "------------------------------------------------------------------"
@docker compose up -d django
frontend-dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Run frontend dev"
@echo "------------------------------------------------------------------"
@cd django_project/dashboard; npm install; npm run dev;
frontend-test:
@echo
@echo "------------------------------------------------------------------"
@echo "Run frontend test"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} exec -T dev npm run test --prefix /home/web/django_project/dashboard
frontend-serve:
@echo
@echo "------------------------------------------------------------------"
@echo "Serve frontend"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} exec -T dev npm run serve --prefix /home/web/django_project/dashboard
dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in dev mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d dev webpack-watcher worker celery_beat
@docker compose ${ARGS} up --no-recreate --no-deps -d
# use .azure.env in docker-compose.override.yml
dev-azure:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in dev mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d dev webpack-watcher worker celery_beat azurite
@docker compose ${ARGS} up --no-recreate --no-deps -d
dev-kill:
@echo
@echo "------------------------------------------------------------------"
@echo "Kill dev"
@echo "------------------------------------------------------------------"
@docker kill $(PROJECT_ID)_dev
dev-reload: dev-kill dev
@echo
@echo "------------------------------------------------------------------"
@echo "Reload DEV"
@echo "------------------------------------------------------------------"
build:
@echo
@echo "------------------------------------------------------------------"
@echo "Building in production mode"
@echo "------------------------------------------------------------------"
@docker compose build
build-no-cache:
@echo
@echo "------------------------------------------------------------------"
@echo "Building in production mode without cache"
@echo "------------------------------------------------------------------"
@docker compose build --no-cache
nginx:
@echo
@echo "------------------------------------------------------------------"
@echo "Running nginx in production mode"
@echo "Normally you should use this only for testing"
@echo "In a production environment you will typically use nginx running"
@echo "on the host rather if you have a multi-site host."
@echo "------------------------------------------------------------------"
@docker compose up -d nginx
@echo "Site should now be available at http://localhost"
up: web
status:
@echo
@echo "------------------------------------------------------------------"
@echo "Show status for all containers"
@echo "------------------------------------------------------------------"
@docker compose ps
kill:
@echo
@echo "------------------------------------------------------------------"
@echo "Killing in production mode"
@echo "------------------------------------------------------------------"
@docker compose stop
down: kill
@echo
@echo "------------------------------------------------------------------"
@echo "Removing production instance!!! "
@echo "------------------------------------------------------------------"
@docker compose down
shell:
@echo
@echo "------------------------------------------------------------------"
@echo "Shelling in in production mode"
@echo "------------------------------------------------------------------"
@docker compose exec django /bin/bash
devweb-shell:
@echo
@echo "------------------------------------------------------------------"
@echo "Shelling in in development mode"
@echo "------------------------------------------------------------------"
@docker compose exec dev /bin/bash
run-local:
@echo
@echo "------------------------------------------------------------------"
@echo "Running Django in development mode"
@echo "------------------------------------------------------------------"
@docker compose exec dev python manage.py runserver 0.0.0.0:8080 --settings=core.settings.dev
db-bash:
@echo
@echo "------------------------------------------------------------------"
@echo "Entering DB Bash in production mode"
@echo "------------------------------------------------------------------"
@docker compose exec db sh
db-shell:
@echo
@echo "------------------------------------------------------------------"
@echo "Entering PostgreSQL Shell in production mode"
@echo "------------------------------------------------------------------"
docker-compose exec db su - postgres -c "psql"
collectstatic:
@echo
@echo "------------------------------------------------------------------"
@echo "Collecting static in production mode"
@echo "------------------------------------------------------------------"
#@docker compose run django python manage.py collectstatic --noinput
#We need to run collect static in the same context as the running
# django container it seems so I use docker exec here
# no -it flag so we can run over remote shell
@docker exec $(PROJECT_ID)_django python manage.py collectstatic --noinput
reload:
@echo
@echo "------------------------------------------------------------------"
@echo "Reload django project in production mode"
@echo "------------------------------------------------------------------"
# no -it flag so we can run over remote shell
@docker exec $(PROJECT_ID)_django django --reload /tmp/django.pid
migrate:
@echo
@echo "------------------------------------------------------------------"
@echo "Running migrate static in production mode"
@echo "------------------------------------------------------------------"
@docker compose exec django python manage.py migrate
# --------------- help --------------------------------
help:
@echo "* **build** - builds all required containers."
@echo "* **up** - runs all required containers."
@echo "* **kill** - kills all running containers. Does not remove them."
@echo "* **logs** - view the logs of all running containers. Note that you can also view individual logs in the deployment/logs directory."
@echo "* **nginx** - builds and runs the nginx container."
@echo "* **permissions** - Update the permissions of shared volumes. Note this will destroy any existing permissions you have in place."
@echo "* **rm** - remove all containers."
@echo "* **shell-frontend-mapstore** - open a bash shell in the frontend mapstore (where django runs) container."
# ----------------------------------------------------------------------------
# DEVELOPMENT C O M M A N D S
# --no-deps will attach to prod deps if running
# after running you will have ssh and web ports open (see dockerfile for no's)
# and you can set your pycharm to use the python in the container
# Note that pycharm will copy in resources to the /root/ user folder
# for pydevd etc. If they dont get copied, restart pycharm...
# ----------------------------------------------------------------------------
tegola:
@echo
@echo "------------------------------------------------------------------"
@echo "Running tegola in production mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d tegola
db:
@echo
@echo "------------------------------------------------------------------"
@echo "Running db in production mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d db dbbackups
wait-db:
@docker compose ${ARGS} exec -T db su - postgres -c "until pg_isready; do sleep 5; done"
create-test-db:
@docker compose ${ARGS} exec -T db su - postgres -c "psql -c 'create database test_db;'"
devweb: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up --no-recreate --no-deps -d dev
sleep:
@echo
@echo "------------------------------------------------------------------"
@echo "Sleep for 50 seconds"
@echo "------------------------------------------------------------------"
@sleep 50
@echo "Done"
devweb-test:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker compose exec -T dev python manage.py test --keepdb --noinput
coverage-test:
@docker compose exec -T dev bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput --verbosity 0 && coverage run manage.py test && coverage xml"
# --------------- TESTS ---------------
run-flake8:
@echo
@echo "------------------------------------------------------------------"
@echo "Running flake8"
@echo "------------------------------------------------------------------"
@pip install flake8
@pip install flake8-docstrings
@flake8