-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
257 lines (223 loc) · 10.4 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
PROJECT_ID := geosight
export COMPOSE_FILE=deployment/docker-compose.yml:deployment/docker-compose.override.yml
export ONEDRIVE_DATA_DIR=$(shell pwd)/deployment/onedrive/data
SHELL := /usr/bin/env 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 "------------------------------------------------------------------"
web:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in production mode"
@echo "------------------------------------------------------------------"
@docker compose up -d
frontend-dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Run frontend dev"
@echo "------------------------------------------------------------------"
@cd django_project/frontend; npm install --verbose; npm run dev;
dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in dev mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d dev
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
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
update: up
@echo
@echo "------------------------------------------------------------------"
@echo "Update production instance"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} restart django worker nginx
shell:
@echo
@echo "------------------------------------------------------------------"
@echo "Shelling in in production mode"
@echo "------------------------------------------------------------------"
@docker compose exec django /bin/bash
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...
# ----------------------------------------------------------------------------
db:
@echo
@echo "------------------------------------------------------------------"
@echo "Running db in production mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d db
wait-db:
@docker compose ${ARGS} exec -T db su - postgres -c "until pg_isready; do sleep 5; done"
devweb: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up --no-recreate --no-deps -d dev redis
devweb-entrypoint:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} exec -T dev "/home/web/django_project/entrypoint.sh"
sleep:
@echo
@echo "------------------------------------------------------------------"
@echo "Sleep for 50 seconds"
@echo "------------------------------------------------------------------"
@sleep 50
@echo "Done"
production-check:
@echo
@echo "------------------------------------------------------------------"
@echo "Run production check"
@echo "------------------------------------------------------------------"
@docker compose exec -T dev python production_prep_check.py
devweb-runserver:
@echo
@echo "------------------------------------------------------------------"
@echo "Start django runserver in dev container"
@echo "------------------------------------------------------------------"
@docker compose $(ARGS) exec -T dev bash -c "nohup python manage.py runserver 0.0.0.0:2000 &"
devweb-load-demo-data:
@echo
@echo "------------------------------------------------------------------"
@echo "Load demo data for devweb"
@echo "------------------------------------------------------------------"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/demo/1.core.json"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/demo/2.geosight_georepo.json"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/demo/3.geosight_data.json"
load-test-data:
@echo
@echo "------------------------------------------------------------------"
@echo "Load demo data for devweb"
@echo "------------------------------------------------------------------"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/test/1.core.json"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/test/2.user_group.json"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/test/3.geosight_georepo.json"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata core/fixtures/test/4.geosight_data.json"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py loaddata geosight/reference_dataset/fixtures/test/4.reference_dataset_levels.json"
devweb-test:
@echo
@echo "------------------------------------------------------------------"
@echo "Run tests"
@echo "------------------------------------------------------------------"
@docker compose exec -T dev python manage.py collectstatic --noinput
@docker compose exec -T dev python manage.py test --keepdb --noinput
devweb-shell:
@echo
@echo "------------------------------------------------------------------"
@echo "Run shell"
@echo "------------------------------------------------------------------"
@docker compose exec dev /bin/bash
# --------------- TESTS ---------------
run-flake8:
@echo
@echo "------------------------------------------------------------------"
@echo "Running flake8"
@echo "------------------------------------------------------------------"
@pip install flake8==6.0.0
@pip install flake8-docstrings
@python3 -m flake8