-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-compose.dev.yml
279 lines (263 loc) · 8.78 KB
/
docker-compose.dev.yml
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
services:
db:
ports:
# postgres accessible on the host at 5433 for debugging
- "5433:5432"
rabbitmq:
environment:
- RABBITMQ_DEFAULT_USER=user
- RABBITMQ_DEFAULT_PASS=pass
ports:
# rabbitmq management port accessible on host for monitoring, debugging
- "15672:15672"
django:
image: laxy:latest
build:
context: .
dockerfile: ./docker/laxy/Dockerfile
environment:
# - LAXY_DEBUG=yes
- LAXY_ADMIN_EMAIL=admin@example.com
- LAXY_ADMIN_USERNAME=admin
# - LAXY_ADMIN_PASSWORD=adminpass
- LAXY_STATIC_ROOT=/usr/share/nginx/html/backend_static
- LAXY_STATIC_URL=${LAXY_FRONTEND_URL-//dev.laxy.io:8002}/backend_static/
# Number of gunicorn workers
- WEB_CONCURRENCY=${WEB_CONCURRENCY-4}
volumes:
- .:/app
- ./laxy_frontend/dist:/usr/share/nginx/html
# Django app is publicly accessible without reverse proxy
# ports:
# - "8001:8001"
# Debugger port
# - "21001:21001"
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "1"
command: bash -c "sleep 10 &&
python3 manage.py collectstatic --no-input &&
python3 manage.py makemigrations --no-input &&
python3 manage.py migrate --no-input &&
python3 manage.py loaddata --app laxy_backend /app/docker/fake-cluster/fixtures.json &&
python3 manage.py runserver 0.0.0.0:8001"
# gunicorn laxy.wsgi -b 0.0.0.0:8001 --forwarded-allow-ips='*' --worker-class gevent"
# Insecure: This leaks the admin password (eg via ps -ef).
# python manage.py shell -c \"from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.filter(username='${LAXY_ADMIN_USERNAME}').count() or User.objects.create_superuser('${LAXY_ADMIN_USERNAME}', '${LAXY_ADMIN_EMAIL}', '${LAXY_ADMIN_PASSWORD}');\";"
# Examine the logs to find the token to login to the Jupyter notebook
# (eg docker compose -f docker-compose.yml -f docker-compose.dev.yml logs shell-notebook )
shell-notebook:
build:
context: .
dockerfile: ./docker/laxy/Dockerfile
environment:
- LAXY_DEBUG=yes
- LAXY_ADMIN_EMAIL=admin@example.com
- LAXY_ADMIN_USERNAME=admin
- LAXY_SENTRY_DSN=
volumes:
- .:/app
- ./laxy_frontend/dist:/usr/share/nginx/html
ports:
- "8999:8999"
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "1"
depends_on:
- db
command: bash -c "sleep 10 &&
pip3 install jupyter ipython ipykernel django-extensions &&
python3 manage.py shell_plus --notebook"
# NOTE: You may need to change the default Docker container memory to 4Gb when using
# this container, since `conda create` often exceeds 2Gb of RAM
# Running with the docker-compose --compatibility flag should allow the
# 'deploy.resources.limits.memory' setting in this service to be honoured.
#
# We use port 2222 for OpenSSH so we can easily expose it to the host for debugging
# without a port clash with the host SSH server.
fake-cluster:
image: fake-cluster:latest
build:
context: ./docker/fake-cluster
volumes:
- ./.fake-cluster-scratch:/scratch
ports:
- "2222:2222"
logging:
driver: "json-file"
options:
max-size: "10k"
max-file: "1"
restart: "unless-stopped"
depends_on:
- django
deploy:
resources:
limits:
memory: "4000M"
# TODO: Use watchdog to make celery autoreload on *.py and *.sh changes
# https://www.distributedpython.com/2019/04/23/celery-reload/
queue-high:
build:
context: .
dockerfile: ./docker/laxy/Dockerfile
command: ["celery", "-A", "laxy", "worker", "-E", "-l", "info", "-Ofair",
"--broker=${LAXY_BROKER_URL}",
# "--pool=solo", # for use when remote debugging
]
# environment:
# - DEBUGGER_PORT=21002
stop_grace_period: 30s
stop_signal: SIGTERM
# ports:
# for use when remote debugging
# - "21002:21001"
volumes:
- .:/app
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "1"
queue-low:
build:
context: .
dockerfile: ./docker/laxy/Dockerfile
command: ["celery", "-A", "laxy", "worker", "-E", "-l", "info", "-Ofair",
"--broker=${LAXY_BROKER_URL}",
"-Q", "low-priority",
# "--pool=solo", # for use when remote debugging
]
# environment:
# - DEBUGGER_PORT=21002
stop_grace_period: 30s
stop_signal: SIGTERM
# ports:
# # for use when remote debugging
# - "21002:21002"
volumes:
- .:/app
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "1"
celery-beat:
build:
context: .
dockerfile: ./docker/laxy/Dockerfile
volumes:
- .:/app
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "1"
flower:
environment:
- FLOWER_BASIC_AUTH=user:pass
ports:
- "5556:5556"
volumes:
- .:/app
nginx:
image: laxy-static-nginx:latest
build:
context: .
dockerfile: ./docker/laxy-static-nginx/Dockerfile
# These are required to properly build and come from .env
args:
LAXY_FRONTEND_URL: "${LAXY_FRONTEND_URL:-http://localhost:8001}"
LAXY_FRONTEND_API_URL: "${LAXY_FRONTEND_API_URL:-http://localhost:8002}"
LAXY_FRONTEND_GOOGLE_OAUTH_CLIENT_ID: "${LAXY_FRONTEND_GOOGLE_OAUTH_CLIENT_ID:-}"
LAXY_ENV: "${LAXY_ENV:-dev}"
env_file:
- .env
command: >
sh -c "
until [ -f /certs/fullchain.pem ] && [ -f /certs/key.pem ]; do
echo `date`': Waiting for SSL certificates ..';
sleep 5;
done;
# Templating the nginx.conf in this way has proven fragile in practise, so disabled for the moment
# in favor of an nginx.conf external to to the container (via a host-bind volume)
# export LAXY_FRONTEND_HOST=`echo $LAXY_FRONTEND_URL | cut -f 2 -d ':' | sed 's/\/\///g'`
# export LAXY_API_HOST=`echo $LAXY_FRONTEND_API_URL | cut -f 2 -d ':' | sed 's/\/\///g'`
# if [ ! -f /etc/nginx/nginx.conf ] || [ -w /etc/nginx/nginx.conf ]; then
# # NOTE: Double dollar sign $$ prevents docker-compose interpolating
# envsubst '$${LAXY_FRONTEND_HOST} $${LAXY_API_HOST}' </etc/nginx/nginx.conf.template >/etc/nginx/nginx.conf
# fi
/usr/sbin/nginx -g 'daemon off;'
"
ports:
# dev ports
- "8002:8002"
- "8001:8001"
# Required for the Let's Encrypt http-01 challenge
- "80:80"
depends_on:
- ssl-certs-cron
volumes:
- ./laxy_frontend/dist:/usr/share/nginx/html
- ./certs:/certs
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ssl-certs-cron:
# image: ssl-certs:latest
build:
context: ./docker/ssl-certs/
environment:
# No quotes !
- ACME_SSL_DOMAINS=${ACME_SSL_DOMAINS-dev.laxy.io dev-api.laxy.io}
- LAXY_ADMIN_EMAIL=${LAXY_ADMIN_EMAIL-}
# Run certificate renewel/creation on startup if missing. Then run crond in foreground forever.
# command: >
# /bin/bash -c "
# [[ ! -f /certs/key.pem ]] && \
# cron && \
# anacron && \
# touch /var/log/ssl-certs-cron.log && \
# tail -f /var/log/ssl-certs-cron.log
# "
deploy:
restart_policy:
delay: 5s
#max_attempts: 3
window: 120s
volumes:
- ./laxy_frontend/dist:/usr/share/nginx/html
- ./certs:/certs
splash:
command: --disable-lua --disable-browser-caches --max-timeout 300
ports:
- "8050:8050"
# This method of 'cron-via-docker-restarts' will only work in Swarm mode, due to use of 'deploy'
# ssl-certs-restart-daily:
# image: alpine:3.8
# command: >
# sh -c '
# DOMAINS="dev.laxy.io dev-api.laxy.io"
# EXTRA_ARGS="" # -s = staging, -F = force renewal
#
# /sbin/apk upgrade
# /sbin/apk add --no-cache acme-client
#
# /usr/bin/acme-client -a https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf -f /certs/account.key \
# -C /usr/share/nginx/html/.well-known/acme-challenge/ \
# -c /certs \
# -k /certs/domain.key \
# -Nnmev \
# $$EXTRA_ARGS \
# $$DOMAINS
# '
# deploy:
# restart_policy:
# condition: any
# # Run every day
# delay: 1d
# volumes:
# - ./laxy_frontend/dist:/usr/share/nginx/html
# - ./certs:/certs