-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
408 lines (372 loc) · 9.81 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
400
401
402
403
404
405
406
407
408
version: '3.8'
services:
# =================
# BRICK APPLICATION
# =================
app:
profiles:
- prod
build:
context: .
dockerfile: docker/Dockerfile.app
expose:
- "5173"
ports:
- "5173:5173"
security_opt:
- no-new-privileges:true
env_file: docker/brick.env
environment:
NODE_ENV: production
ORIGIN: http://localhost:5173
PRIVATE_DOCKER_API_URL: http://api:8080
depends_on:
- api
networks:
- internal
app-dev:
profiles:
- dev
build:
context: .
dockerfile: docker/Dockerfile.app.dev
volumes:
- ./app:/usr/src/app
- /usr/src/app/node_modules
expose:
- "5174"
ports:
- "5174:5174"
security_opt:
- no-new-privileges:true
env_file: docker/brick.env
environment:
NODE_ENV: development
ORIGIN: http://localhost:5174
PRIVATE_DOCKER_API_URL: http://api-dev:8080
depends_on:
- api-dev
networks:
- internal
# ========================
# BRICK API SERVER AND CLI
# ========================
api:
profiles:
- prod
build:
context: .
dockerfile: docker/Dockerfile.server
command: uvicorn brick.api.main:app --host 0.0.0.0 --port 8080
volumes:
- api:/data
- work:/tmp
- databases:/data
env_file: docker/brick.env
environment:
CORS_ORIGINS: http://app:5173
MONGODB_DATABASE: brick
MONGODB_USERNAME: /run/secrets/brick_db_user
MONGODB_PASSWORD: /run/secrets/brick_db_pwd
expose:
- "8080"
security_opt:
- no-new-privileges:true
depends_on:
- redis
- mongodb
- databases
secrets:
- brick_db_user
- brick_db_pwd
networks:
- internal
api-dev:
profiles:
- dev
build:
context: .
dockerfile: docker/Dockerfile.server
command: uvicorn brick.api.main:app --host 0.0.0.0 --port 8080
volumes:
- api_dev:/data
- work:/tmp
- databases:/data
env_file: docker/brick.env
environment:
CORS_ORIGINS: http://app-dev:5174
MONGODB_DATABASE: dev
MONGODB_USERNAME: /run/secrets/brick_db_user
MONGODB_PASSWORD: /run/secrets/brick_db_pwd
expose:
- "8080"
security_opt:
- no-new-privileges:true
depends_on:
- redis
- mongodb
- databases
secrets:
- brick_db_user
- brick_db_pwd
networks:
- internal
# ==================
# TASK QUEUE WORKERS
# ==================
# Celery workers have access to some API settings and update
# the session model in the database and therefore need access
# to the API config and secrets
# The environment variable CELERY_THREADS_PER_WORKER specifies
# concurrency of both the threads assigned to each worker and
# the maximum threads for all software in API (BLAST, GENOMAD)
worker:
profiles:
- prod
build:
context: .
dockerfile: docker/Dockerfile.server
# Concurrency is set at the application with CELERY_THREADS_PER_WORKER [default: all, fallback: 1]
command: celery -A brick.api.core.celery.celery_app worker --loglevel=INFO
volumes:
- work:/tmp
- databases:/data
env_file: docker/brick.env
environment:
CORS_ORIGINS: http://app:5173
MONGODB_DATABASE: brick
MONGODB_USERNAME: /run/secrets/brick_db_user
MONGODB_PASSWORD: /run/secrets/brick_db_pwd
security_opt:
- no-new-privileges:true
depends_on:
- api
- redis
- mongodb
- databases
secrets:
- brick_db_user
- brick_db_pwd
networks:
- internal
# Not necessary for local deployment, unless explicitly needed,
# resource limits in this deployment are meant to evaluate and
# test resource use for the web application. Variables do not
# seem to work, so values must be explicitly set
# deploy:
# resources:
# limits: # process is killed
# cpus: 8 # either number of cores or fraction
# memory: 42G
# reservations: # resources reserved for container
# cpus: 8
# memory: 20G # determined by the largest database
worker-dev:
profiles:
- dev
build:
context: .
dockerfile: docker/Dockerfile.server
# Concurrency is set at the application with CELERY_THREADS_PER_WORKER [default: all, fallback: 1]
command: celery -A brick.api.core.celery.celery_app worker --loglevel=INFO
volumes:
- work:/tmp
- databases:/data
env_file: docker/brick.env
environment:
CORS_ORIGINS: http://app-dev:5174
MONGODB_DATABASE: dev
MONGODB_USERNAME: /run/secrets/brick_db_user
MONGODB_PASSWORD: /run/secrets/brick_db_pwd
security_opt:
- no-new-privileges:true
depends_on:
- api-dev
- redis
- mongodb
- databases
secrets:
- brick_db_user
- brick_db_pwd
networks:
- internal
# Not necessary for local deployment, unless explicitly needed,
# resource limits in this deployment are meant to evaluate and
# test resource use for the web application. Variables do not
# seem to work, so values must be explicitly set
# deploy:
# resources:
# limits:
# cpus: 8 # either number of cores or fraction
# memory: 42G # process is killed
# reservations:
# cpus: 8
# memory: 20G # determined by the largest database
# =========
# DATABASES
# =========
# Currently using the same Redis (Celery) and MongoDB for
# dev and and prod (different collections) should probably
# have their own database stack to ensure non-interference
redis:
profiles:
- prod
- dev
- test
image: redis:7.0.12-alpine
expose:
- "6379"
volumes:
- redis_db:/data
security_opt:
- no-new-privileges:true
networks:
- internal
mongodb:
profiles:
- prod
- dev
- test
image: mongo:7.0.0-rc10
command: mongod --auth --quiet --logpath /dev/null
expose:
- "27017"
volumes:
- mongo_db:/data/db
- mongo_db_cfg:/data/configdb # will create anonymous volumes otherwise if not specified
- ./docker/mongodb/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro
environment:
MONGODB_INIT_ROOT_USER_FILE: /run/secrets/mongo_root_user
MONGODB_INIT_ROOT_PWD_FILE: /run/secrets/mongo_root_pwd
MONGODB_USERNAME_FILE: /run/secrets/brick_db_user
MONGODB_PASSWORD_FILE: /run/secrets/brick_db_pwd
security_opt:
- no-new-privileges:true
secrets:
- mongo_root_user
- mongo_root_pwd
- brick_db_user
- brick_db_pwd
networks:
- internal
# ================================================
# DELETES SESSIONS AND UPLOADED FILES PERIODICALLY
# ================================================
data-cleaner:
profiles:
- server
build:
context: .
dockerfile: docker/Dockerfile.server
command: brick utils clean --expire-days 1 --day-of-week "*" --time-of-day '04:00' --log /tmp/brick-cleaner.log
volumes:
- api:/data
- work:/tmp
# Set the container timezone by sharing the read-only localtime
- /etc/localtime:/etc/localtime:ro
env_file: docker/brick.env
environment:
BRICK_API_BASE_URL: http://api:8080
security_opt:
- no-new-privileges:true
depends_on:
- api
- redis
- mongodb
networks:
- internal
data-cleaner-dev:
profiles:
- server-dev
build:
context: .
dockerfile: docker/Dockerfile.server
command: brick utils clean --expire-days 1 --day-of-week '*' --time-of-day '04:00' --log /tmp/brick-cleaner.log
volumes:
- api:/data
- work:/tmp
# Set the container timezone by sharing the read-only localtime
- /etc/localtime:/etc/localtime:ro
env_file: docker/brick.env
environment:
BRICK_API_BASE_URL: http://api-dev:8080
security_opt:
- no-new-privileges:true
depends_on:
- api-dev
- redis
- mongodb
networks:
- internal
# ================
# DATABASE STORAGE
# ================
# Specification of the image tag will cause the
# image to not rebuild when using --build. This
# is intended as we want to update the storage
# volume with the database manually, rather than
# downloading on each --build
databases:
image: brick-database-storage:latest
profiles:
- prod
- dev
build:
context: .
dockerfile: docker/Dockerfile.dbs
tty: true
volumes:
- databases:/data # /data/genomad_db
networks:
- internal
# ============
# UNIT TESTING
# ============
tests:
profiles:
- test
build:
context: .
dockerfile: docker/Dockerfile.server
command: pytest
environment:
MONGODB_DATABASE: tests
MONGODB_USERNAME: /run/secrets/brick_db_user
MONGODB_PASSWORD: /run/secrets/brick_db_pwd
WORK_DISK_SPACE_GB: 0.01 # see if this works on runners
volumes:
- work:/tmp # test of disk space (test_utils.py) assumes /tmp
depends_on:
- redis
- mongodb
secrets:
- brick_db_user
- brick_db_pwd
networks:
- internal
volumes:
work:
driver: local
api:
driver: local
api_dev:
driver: local
redis_db:
driver: local
mongo_db:
driver: local
mongo_db_cfg:
driver: local
databases:
driver: local
secrets:
mongo_root_user:
file: ./docker/mongodb/mongo_root_user.txt
mongo_root_pwd:
file: ./docker/mongodb/mongo_root_pwd.txt
brick_db_user:
file: ./docker/mongodb/brick_db_user.txt
brick_db_pwd:
file: ./docker/mongodb/brick_db_pwd.txt
networks:
internal: