-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
338 lines (307 loc) · 10.3 KB
/
Copy pathdocker-compose.yml
File metadata and controls
338 lines (307 loc) · 10.3 KB
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
###############################################################################
# ____ __ _ _ _ #
# | _ \ _ __ __ _ / _| |_ __ _| |__ | | ___ #
# | | | | '__/ _` | |_| __/ _` | '_ \| |/ _ \ #
# | |_| | | | (_| | _| || (_| | |_) | | __/ #
# |____/|_| \__,_|_| \__\__,_|_.__/|_|\___| #
# #
# _ ____ ___ ____ _ __ _ _ _ #
# / \ | _ \_ _| / ___| ___| |/ _| | |__ ___ ___| |_ ___ __| | #
# / _ \ | |_) | | \___ \ / _ \ | |_ _____| '_ \ / _ \/ __| __/ _ \/ _` | #
# / ___ \| __/| | ___) | __/ | _|_____| | | | (_) \__ \ || __/ (_| | #
# /_/ \_\_| |___| |____/ \___|_|_| |_| |_|\___/|___/\__\___|\__,_| #
# #
###############################################################################
###############################################################################
### Configuration values ###
###############################################################################
x-config-variables:
# Draftable
django-secret: &django-secret ${DJANGO_SECRET_KEY:-DjangoSecretKey}
compare-workers-count: &compare-workers-count ${COMPARE_WORKERS_COUNT:-1}
draftable-product-key: &draftable-product-key ${DRAFTABLE_PRODUCT_KEY:-}
# Load balancer
server-dns: &server-dns ${SERVER_DNS:-}
tls-cert: &tls-cert ${TLS_CERT:-}
tls-key: &tls-key ${TLS_KEY:-}
tls-ca-chain: &tls-ca-chain ${TLS_CA_CHAIN:-}
# AMQP (RabbitMQ)
amqp-user: &amqp-user ${AMQP_USER:-draftable}
amqp-pass: &amqp-pass ${AMQP_PASSWORD:-draftable}
# Database (PostgreSQL)
db-name: &db-name ${DB_NAME:-draftable}
db-user: &db-user ${DB_USER:-postgres}
db-pass: &db-pass ${DB_PASS:-password}
# Redis (optional)
redis-pass: &redis-pass ${REDIS_PASSWORD:-}
app-base-url: &app-base-url ${APP_BASE_URL:-https://${SERVER_DNS:-localhost}}
###############################################################################
### Configuration sections ###
###############################################################################
# These configuration sections are defined using YAML anchors for easy re-use
# across containers. If you've added a new configuration value above, you'll
# need to add it to the relevant configuration section unless you've directly
# added it to the environment dictionary of the relevant container(s).
x-config-sections:
web-common: &web-common-config
ENV: prod
APP_BASE_URL: *app-base-url
DJANGO_SECRET_KEY: *django-secret
ALLOWED_HOSTS: ${ALLOWED_HOSTS:-localhost,${SERVER_DNS:-}}
CSRF_TRUSTED_ORIGINS: ${CSRF_TRUSTED_ORIGINS:-https://${SERVER_DNS:-localhost}}
DRAFTABLE_PRODUCT_KEY: *draftable-product-key
REQUIRE_HTTPS: ${REQUIRE_HTTPS:-true}
RUNNING_ON_AWS: ${RUNNING_ON_AWS:-false}
FILE_STORAGE_TYPE: ${FILE_STORAGE_TYPE:-local}
aws: &aws-config
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN:-}
AWS_S3_REGION_NAME: ${AWS_S3_REGION_NAME:-${AWS_REGION:-}}
AWS_REGION: ${AWS_REGION:-}
S3_STORAGE_BUCKET: ${S3_STORAGE_BUCKET:-}
COMPARE_API_CLOUDFRONT_URL: ${COMPARE_API_CLOUDFRONT_URL:-}
compare: &compare-config
COMPARE_WORKERS_COUNT: *compare-workers-count
APP_BASE_URL: *app-base-url
amqp: &amqp-config
AMQP_HOST: ${AMQP_HOST:-rabbitmq}
AMQP_USER: *amqp-user
AMQP_PASSWORD: *amqp-pass
db: &db-config
DB_HOST: ${DB_HOST:-pgsql}
DB_USER: *db-user
DB_PASS: *db-pass
DB_NAME: *db-name
redis: &redis-config
REDIS_HOST: ${REDIS_HOST:-redis}
REDIS_PASSWORD: *redis-pass
###############################################################################
### Docker volumes ###
###############################################################################
volumes:
app_data:
pgsql_data:
rabbitmq_data:
name: draftable_rabbitmq_data_v4
redis_data:
###############################################################################
### Docker containers ###
###############################################################################
services:
#########################
### Draftable ingress ###
#########################
server:
image: draftable/apish-load-balancer:latest
ports:
- ${HTTP_PORT:-80}:80 # HTTP
- ${HTTPS_PORT:-443}:443 # HTTPS
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
environment:
SERVER_DNS: *server-dns
TLS_CERT: *tls-cert
TLS_KEY: *tls-key
TLS_CA_CHAIN: *tls-ca-chain
restart: always
healthcheck:
test: wget --no-verbose --tries=1 --spider http://127.0.0.1/nginx-health || exit 1
interval: 5s
timeout: 3s
retries: 3
start_period: 60s
depends_on:
web:
condition: service_healthy
#####################
### Draftable web ###
#####################
web_init:
image: draftable/apish-web:latest
volumes:
- app_data:/srv/draftable
environment:
APP_MODE: web_init
<<: [*web-common-config, *amqp-config, *db-config, *redis-config, *aws-config]
restart: 'no'
depends_on:
pgsql:
condition: service_healthy
redis:
condition: service_healthy
web:
image: draftable/apish-web:latest
deploy:
replicas: 2
volumes:
- app_data:/srv/draftable
environment:
APP_MODE: web
<<: [*web-common-config, *amqp-config, *db-config, *redis-config, *aws-config]
restart: always
healthcheck:
test: curl --fail http://localhost:8000/api/?healthcheck || exit 1
interval: 5s
timeout: 3s
retries: 2
start_period: 60s
depends_on:
pgsql:
condition: service_healthy
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
celery_worker:
image: draftable/apish-web:latest
volumes:
- app_data:/srv/draftable
environment:
APP_MODE: celery_worker
<<: [*web-common-config, *amqp-config, *db-config, *redis-config, *aws-config]
restart: always
healthcheck:
test: celery --app web.apps.base.draftacelery inspect ping || exit 1
interval: 15s
timeout: 5s
retries: 1
start_period: 30s
depends_on:
pgsql:
condition: service_healthy
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
celery_beat:
image: draftable/apish-web:latest
volumes:
- app_data:/srv/draftable
environment:
APP_MODE: celery_beat
<<: [*web-common-config, *amqp-config, *db-config, *redis-config, *aws-config]
restart: always
healthcheck:
test: celery --app web.apps.base.draftacelery inspect ping || exit 1
interval: 15s
timeout: 5s
retries: 1
start_period: 30s
depends_on:
pgsql:
condition: service_healthy
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
#########################
### Draftable compare ###
#########################
compare:
image: draftable/apish-compare:latest
volumes:
- app_data:/srv/draftable
restart: always
environment:
<<: [*compare-config, *amqp-config, *redis-config, *aws-config]
JODCONVERTER_URL: ${JODCONVERTER_URL:-http://converter:8080/lool/convert-to/pdf}
healthcheck:
test: ps aux |grep [C]ompareService || exit 1
interval: 10s
timeout: 3s
retries: 2
start_period: 30s
depends_on:
converter:
condition: service_started
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
#########################
### Draftable convert ###
#########################
converter:
image: draftable/apish-converter:latest
ports:
- 8080:8080
environment:
<<: [*redis-config]
depends_on:
redis:
condition: service_healthy
restart: always
###########################
### Dependency services ###
###########################
pgsql:
image: postgres:16.8-alpine
user: postgres
volumes:
- pgsql_data:/var/lib/postgresql/data
ports:
- 5432:5432
environment:
POSTGRES_DB: *db-name
POSTGRES_USER: *db-user
POSTGRES_PASSWORD: *db-pass
restart: always
healthcheck:
test: pg_isready -q -d ${DB_NAME:-draftable} -U ${DB_USER:-postgres}
interval: 5s
timeout: 4s
retries: 10
start_period: 30s
rabbitmq:
image: rabbitmq:4.2-management-alpine
user: rabbitmq
volumes:
- rabbitmq_data:/var/lib/rabbitmq
ports:
- 5672:5672 # AMQP
environment:
RABBITMQ_DEFAULT_USER: *amqp-user
RABBITMQ_DEFAULT_PASS: *amqp-pass
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 5s
timeout: 4s
retries: 10
start_period: 30s
redis:
image: redis:8.2-alpine
user: redis
# Critical data persistence configuration:
# - AOF (Append Only File) enabled for maximum durability
# - Multiple RDB snapshot points for backup persistence
# - Fsync every second for balance between performance and durability
command: >
sh -c 'redis-server
--dir /data
--appendonly yes
--appendfsync everysec
--auto-aof-rewrite-percentage 100
--auto-aof-rewrite-min-size 64mb
--aof-load-truncated yes
--no-appendfsync-on-rewrite no
--save 900 1
--save 300 10
--save 60 10000
--stop-writes-on-bgsave-error yes
--rdbcompression yes
--rdbchecksum yes
--maxmemory-policy noeviction
$${REDIS_PASSWORD:+--requirepass "$$REDIS_PASSWORD"}'
volumes:
- redis_data:/data
ports:
- 6379:6379
environment:
REDIS_PASSWORD: *redis-pass
restart: always
healthcheck:
test: sh -c 'redis-cli $${REDIS_PASSWORD:+-a "$$REDIS_PASSWORD"} ping'
interval: 5s
timeout: 4s
retries: 10