-
Notifications
You must be signed in to change notification settings - Fork 45
/
docker-compose.yml
399 lines (377 loc) · 12.4 KB
/
docker-compose.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# Bring up all the pieces necessary to run the workbench
# Data persists in Docker volumes and in local dir
# This file passes through all necessary env variables to requisite
# Docker containers and makes them available when running commands via
# `docker exec`.
version: '3.4'
services:
database:
image: postgres:10.10
environment:
POSTGRES_USER: cjworkbench
POSTGRES_PASSWORD: cjworkbench
POSTGRES_DB: cjworkbench
PGDATA: /var/lib/postgresql/data/10.4
networks: [ 'dev' ]
volumes:
- dbdata:/var/lib/postgresql/data
rabbitmq:
image: rabbitmq:3.8.11-management
ports: [ '15672' ] # open management port, for debugging
networks: [ 'dev' ]
environment:
# Use just one CPU
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: '+S 1:1'
minio:
image: minio/minio:RELEASE.2021-07-08T01-15-01Z
networks: [ 'dev' ]
ports: [ '8001:9000' ]
environment:
MINIO_ACCESS_KEY: minio_access
MINIO_SECRET_KEY: minio_secret
volumes:
- minio_data:/data
entrypoint: ''
command:
- sh
- '-c'
- |
PREFIX=dev
for bucket in user-files static stored-objects external-modules cached-render-results upload; do
mkdir -p /data/$$PREFIX-$$bucket
done
rm -rf /data/.minio.sys
mkdir -p /data/.minio.sys/buckets/$$PREFIX-static/
cat > /data/.minio.sys/buckets/$$PREFIX-static/policy.json <<EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$$PREFIX-static"]
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::$$PREFIX-static/*"]
}
]
}
EOT
minio server /data
webpack:
build:
context: .
target: jsbase
volumes:
# Migrate
- type: bind
source: ./
target: /app/
consistency: cached
- node_modules:/app/node_modules:rw
- jest_cache:/tmp/jest_0:rw
networks: [ 'dev' ]
command: [ 'node_modules/.bin/webpack', '--mode', 'development', '--watch' ]
frontend:
build:
context: .
target: pydev
volumes:
- type: bind
source: ./
target: /app/
consistency: cached
security_opt:
- seccomp=docker/pyspawner-seccomp-profile.json
privileged: true
cap_add: [ SYS_ADMIN ] # for setup-sandboxes.sh to overlay-mount chroots (on k8s we use an init container instead)
environment: &django-env
PYTHONUNBUFFERED: '1'
PYTHONPYCACHEPREFIX: /tmp/pycache
ASGI_THREADS: '3'
CJW_HELP_EMAIL: root@localhost
CJW_HOME_URL: 'http://localhost:8000'
CJW_DB_HOST: database
CJW_RABBITMQ_HOST: amqp://guest:guest@rabbitmq
CJW_DB_PASSWORD: cjworkbench
CJW_SECRET_KEY: cjw-secret-key
CJW_INTERCOM_APP_ID: fs80154z
CJW_INTERCOM_IDENTITY_VERIFICATION_SECRET: sfrVVkJJhMHyLrecJDxLrJAefmV_1COh2NJbjP3G
TUS_CREATE_UPLOAD_URL: http://tusd/files/
TUS_EXTERNAL_URL_PREFIX_OVERRIDE: http://localhost:8002/files/
AWS_ACCESS_KEY_ID: minio_access
AWS_SECRET_ACCESS_KEY: minio_secret
AWS_S3_ENDPOINT: http://minio:9000
S3_BUCKET_NAME_PATTERN: "dev-%s"
ports: [ '8000:8080' ]
networks: [ 'dev' ]
depends_on: [ 'database', 'rabbitmq', 'minio', 'tusd' ]
command: [
'sh',
'-c',
'cjwkernel/setup-sandboxes.sh only-readonly && /opt/venv/django/bin/python bin/watch-and-restart --exclude "**/*.pyc" "**/tests/**/*" --pattern "{intercom_secret,twitter_secret,client_secret}.json" "stripe.env" "cjwkernel/**/*.py" "cjwstate/**/*.py" "cjwstate/**/*.yaml" "server/**/*.py" "templates/**/*.html" "templates/**/*.txt" "server/**/*.yaml" "server/lessons/**/*.html" "server/courses/**/*.html" "cjworkbench/**/*.py" "assets/locale/*/messages.po" --exec bin/frontend-prod'
]
staticfiles:
build:
context: .
target: pydev
volumes:
- type: bind
source: ./
target: /app/
consistency: cached
ports: [ '8003:8003' ]
networks: [ 'dev' ]
environment:
DJANGO_SETTINGS_MODULE: staticfilesdev.settings
command: [
'/opt/venv/django/bin/python',
'-m',
'uvicorn',
'--host',
'0.0.0.0',
'--port',
'8003',
'--use-colors',
'staticfilesdev.asgi:application'
]
renderer:
# It'd be nice to use YAML anchors to copy these parameters ... but
# PyCharm's YAML parser seems to die when we use YAML anchors.
build:
context: .
target: pydev
volumes:
- type: bind
source: ./
target: /app/
consistency: cached
security_opt:
- seccomp=docker/pyspawner-seccomp-profile.json
privileged: true
cap_add:
- SYS_ADMIN # for setup-sandboxes.sh to overlay-mount chroots (on k8s we use an init container instead)
- NET_ADMIN # for pyspawner to create new network namespace without access to private network
environment:
<<: *django-env
depends_on: [ 'database', 'rabbitmq', 'minio' ]
networks: [ 'dev' ]
command: [
'sh',
'-c',
# Use watch-and-restart, not Django autoreload. autoreload crashes when there's a
# syntax error.
'cjwkernel/setup-sandboxes.sh all && /opt/venv/django/bin/python bin/watch-and-restart --exclude "**/tests/**/*" --pattern "cjworkbench/**/*.py" "cjwkernel/**/*.py" "cjwstate/**/*.py" "renderer/**/*.py" --exec bin/renderer-prod'
]
fetcher:
# It'd be nice to use YAML anchors to copy these parameters ... but
# PyCharm's YAML parser seems to die when we use YAML anchors.
build:
context: .
target: pydev
volumes:
- type: bind
source: ./
target: /app/
consistency: cached
security_opt:
- seccomp=docker/pyspawner-seccomp-profile.json
privileged: true
cap_add:
- SYS_ADMIN # for setup-sandboxes.sh to overlay-mount chroots (on k8s we use an init container instead)
- NET_ADMIN # for pyspawner to create new network namespace without access to private network
environment:
<<: *django-env
depends_on: [ 'database', 'rabbitmq', 'minio' ]
networks: [ 'dev' ]
command: [
'sh', '-c',
'cjwkernel/setup-sandboxes.sh all && /opt/venv/django/bin/python bin/watch-and-restart --exclude "**/*.pyc" "**/tests/**/*" --pattern "{intercom_secret,twitter_secret,client_secret}.json" "cjworkbench/**/*.py" "cjwkernel/**/*.py" "cjwstate/**/*.py" "fetcher/**/*.py" --exec bin/fetcher-prod'
]
cron: &cron
build:
context: .
target: pydev
volumes:
- type: bind
source: ./
target: /app/
consistency: cached
environment:
<<: *django-env
depends_on: [ 'database', 'rabbitmq', 'minio' ]
networks: [ 'dev' ]
command: [
'/opt/venv/django/bin/python',
'bin/watch-and-restart',
'--exclude', '**/*.pyc', '**/tests/**/*',
'--pattern', 'cjworkbench/**/*.py', 'cron/**/*.py', 'cjwstate/models/**/*.*',
'--exec', 'bin/cron-prod'
]
cron-expired-session-deleter:
<<: *cron
depends_on: [ 'database', 'minio' ]
command: [
'/opt/venv/django/bin/python',
'bin/watch-and-restart',
'--exclude', '**/*.pyc', '**/tests/**/*',
'--pattern', 'cjworkbench/**/*.py', 'cron/**/*.py', 'cjwstate/models/**/*.*',
'--exec', 'bin/cron-expired-session-deleter'
]
cron-lesson-workflow-deleter:
<<: *cron
depends_on: [ 'database' ]
command: [
'/opt/venv/django/bin/python',
'bin/watch-and-restart',
'--exclude', '**/*.pyc', '**/tests/**/*',
'--pattern', 'cjworkbench/**/*.py', 'cron/**/*.py', 'cjwstate/models/**/*.*',
'--exec', 'bin/cron-lesson-workflow-deleter'
]
cron-delta-deleter:
<<: *cron
depends_on: [ 'database' ]
command: [
'/opt/venv/django/bin/python',
'bin/watch-and-restart',
'--exclude', '**/*.pyc', '**/tests/**/*',
'--pattern', 'cjworkbench/**/*.py', 'cron/**/*.py', 'cjwstate/models/**/*.*',
'--exec', 'bin/cron-delta-deleter'
]
tusd-hooks:
build:
context: .
target: pydev
volumes:
- type: bind
source: ./
target: /app/
consistency: cached
environment: *django-env
networks: [ 'dev' ]
depends_on: [ 'database', 'rabbitmq', 'minio' ]
# we need all this sandboxing stuff just to invoke migrate_params(). Rrgh.
security_opt:
- seccomp=docker/pyspawner-seccomp-profile.json
privileged: true
cap_add: [ SYS_ADMIN ] # for setup-sandboxes.sh to overlay-mount chroots (on k8s we use an init container instead)
command: [
'sh',
'-c',
'cjwkernel/setup-sandboxes.sh only-readonly && /opt/venv/django/bin/python bin/watch-and-restart --exclude "**/*.pyc" "**/tests/**/*" --pattern "cjwstate/**/*.py" "cjworkbench/**/*.py" "tusdhooks/**/*.py" --exec bin/tusd-hooks-prod'
]
tusd:
image: tusproject/tusd:v1.6.0
networks: [ 'dev' ]
depends_on: [ 'minio', 'tusd-hooks' ]
ports: [ '8002:80' ]
environment:
AWS_ACCESS_KEY_ID: minio_access
AWS_SECRET_ACCESS_KEY: minio_secret
AWS_REGION: us-east-1
# No volumes: we don't save data between restarts. (Uploads are temporary.)
command: [
'-port=80',
# Use frontend:8080 -- the Django app, not the proxy. The proxy tries to
# keep connections alive and clients can sometimes notice.
'-hooks-http=http://tusd-hooks:8080/tusd-hooks',
'-hooks-enabled-events=pre-finish',
'-s3-endpoint=http://minio:9000',
'-s3-bucket=dev-upload',
]
testdatabase:
image: postgres:12
environment:
POSTGRES_USER: cjworkbench
POSTGRES_PASSWORD: cjworkbench
POSTGRES_DB: cjworkbench
PGDATA: /var/lib/postgresql/data/12
networks: [ 'test' ]
volumes:
- type: tmpfs
target: /var/lib/postgresql/data
command: [
'-c', 'wal_level=minimal',
'-c', 'max_wal_senders=0',
'-c', 'fsync=off',
'-c', 'synchronous_commit=off',
'-c', 'full_page_writes=off'
]
testrabbitmq:
image: rabbitmq:3.8.11-management
networks: [ 'test' ]
environment:
# Use just one CPU
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: '+S 1:1'
testminio:
image: minio/minio:RELEASE.2021-07-08T01-15-01Z
networks: [ 'test' ]
volumes:
- type: tmpfs
target: /data
environment:
MINIO_ACCESS_KEY: minio_access
MINIO_SECRET_KEY: minio_secret
entrypoint: ''
command:
- sh
- '-c'
- |
for bucket in user-files static stored-objects external-modules cached-render-results upload; do
mkdir -p /data/$$bucket
done
rm -rf /data/.minio.sys
mkdir -p /data/.minio.sys/buckets/static/
cat > /data/.minio.sys/buckets/static/policy.json <<EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::static"]
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::static/*"]
}
]
}
EOT
minio server /data
testtusd:
image: tusproject/tusd:v1.6.0
networks: [ 'test' ]
depends_on: [ 'testminio' ]
environment:
AWS_ACCESS_KEY_ID: minio_access
AWS_SECRET_ACCESS_KEY: minio_secret
AWS_REGION: us-east-1
command: [
'-port=8080', # no permission to bind port 80 on google-cloud-build won't bind port 80
# no hooks in unit tests
'-s3-endpoint=http://testminio:9000',
'-s3-bucket=upload',
]
networks:
dev: {}
test: {}
volumes:
dbdata: {}
minio_data: {}
# Let's not make node_modules a bind mount: Windows bind mounts seem
# to behave a bit differently from Linux bind mounts. Use a Docker volume
# instead.
node_modules: {}
jest_cache: {}