Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
254 lines (246 loc) · 9.04 KB
/
Copy pathdocker-compose.yml
File metadata and controls
254 lines (246 loc) · 9.04 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
version: '3.7'
services:
node-server:
# Explicit immutable application reference (release tag or digest).
image: ${AUDNEXUS_IMAGE:?Set AUDNEXUS_IMAGE to an immutable release tag or digest}
restart: always
environment:
ADP_TOKEN: ${ADP_TOKEN}
AUDIBLE_BATCH_SIZE: ${AUDIBLE_BATCH_SIZE:-1}
BOOK_HISTORY_ENABLED: ${BOOK_HISTORY_ENABLED:-false}
DB_INDEX_BUILD_WAIT_MS: ${DB_INDEX_BUILD_WAIT_MS:-1800000}
DB_INDEX_MODE: ${DB_INDEX_MODE:-auto}
MAX_REQUESTS: ${MAX_REQUESTS:-300}
MONGODB_URI: ${MONGODB_URI:-mongodb://mongo:27017/audnexus}
PRIVATE_KEY: ${PRIVATE_KEY}
REDIS_CACHE_URL: ${REDIS_CACHE_URL:-redis://redis-cache:6379}
REDIS_CACHE_TTL_SECONDS: ${REDIS_CACHE_TTL_SECONDS:-432000}
REDIS_URL: ${REDIS_URL:-redis://redis:6379}
UPDATE_INTERVAL: ${UPDATE_INTERVAL:-30}
UPDATE_INTERVAL_CHAPTERS: ${UPDATE_INTERVAL_CHAPTERS:-30}
UPDATE_THRESHOLD: ${UPDATE_THRESHOLD:-7}
ports:
- '3000:3000'
# List form (no conditions): the mapping form with `condition` is
# invalid under Swarm's legacy v3 schema and fails `docker stack deploy`.
# Swarm starts services in parallel; readiness is covered by the
# healthchecks, the app's bounded startup attempts, and the container
# restart policies:
# node-server: @fastify/redis registers the shared cache client and
# re-tries it in place (ioredis capped reconnection) until it is
# ready; if it is still not ready within Fastify's 10s plugin
# timeout, the container exits and `restart: always` retries boot.
# node-worker: the BullMQ readiness probe polls for up to 5s, then the
# process exits and `restart: unless-stopped` retries the container
# until Redis answers.
# Neither service depends on a hard Redis-first boot order.
depends_on:
- mongo
- redis
- redis-cache
networks:
- traefik-overlay
- internal
logging:
driver: json-file
options:
max-size: ${CONTAINER_LOG_MAX_SIZE:-10m}
max-file: ${CONTAINER_LOG_MAX_FILES:-3}
deploy:
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=traefik-overlay'
- 'traefik.http.routers.node-server.rule=Host(`${TRAEFIK_DOMAIN}`)'
- 'traefik.http.routers.node-server.entrypoints=websecure'
- 'traefik.http.routers.redirs.entrypoints=websecure'
- 'traefik.http.services.node-server.loadbalancer.server.port=3000'
replicas: 15
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
interval: 30s
timeout: 6s
retries: 3
start_period: ${STARTUP_GRACE_PERIOD:-30m}
# BullMQ and rate limiting use durable control Redis; document responses use
# the separately bounded disposable cache service.
node-worker:
image: ${AUDNEXUS_IMAGE:?Set AUDNEXUS_IMAGE to an immutable release tag or digest}
restart: unless-stopped
command: ['bun', 'run', 'worker']
environment:
ADP_TOKEN: ${ADP_TOKEN}
AUDIBLE_BATCH_SIZE: ${AUDIBLE_BATCH_SIZE:-1}
BOOK_HISTORY_ENABLED: ${BOOK_HISTORY_ENABLED:-false}
DB_INDEX_BUILD_WAIT_MS: ${DB_INDEX_BUILD_WAIT_MS:-1800000}
DB_INDEX_MODE: ${DB_INDEX_MODE:-auto}
MONGODB_URI: ${MONGODB_URI:-mongodb://mongo:27017/audnexus}
PRIVATE_KEY: ${PRIVATE_KEY}
REDIS_CACHE_URL: ${REDIS_CACHE_URL:-redis://redis-cache:6379}
REDIS_CACHE_TTL_SECONDS: ${REDIS_CACHE_TTL_SECONDS:-432000}
REDIS_URL: ${REDIS_URL:-redis://redis:6379}
UPDATE_INTERVAL: ${UPDATE_INTERVAL:-30}
UPDATE_INTERVAL_CHAPTERS: ${UPDATE_INTERVAL_CHAPTERS:-30}
UPDATE_THRESHOLD: ${UPDATE_THRESHOLD:-7}
SCHEDULER_CONCURRENCY: ${SCHEDULER_CONCURRENCY:-5}
SCHEDULER_BATCH_SIZE: ${SCHEDULER_BATCH_SIZE:-1000}
SCHEDULER_ITEM_TIMEOUT_MS: ${SCHEDULER_ITEM_TIMEOUT_MS:-120000}
SCHEDULER_MAX_ITEMS: ${SCHEDULER_MAX_ITEMS:-0}
RATE_LIMIT_COOLDOWN_BASE_MS: ${RATE_LIMIT_COOLDOWN_BASE_MS:-120000}
RATE_LIMIT_COOLDOWN_MAX_MS: ${RATE_LIMIT_COOLDOWN_MAX_MS:-7200000}
JITTER_MS: ${JITTER_MS:-0-5000}
# List form (no conditions): valid under both Compose and Swarm legacy v3;
# see the node-server note for why `condition` is not used.
depends_on:
- mongo
- redis
- redis-cache
networks:
- internal
logging:
driver: json-file
options:
max-size: ${CONTAINER_LOG_MAX_SIZE:-10m}
max-file: ${CONTAINER_LOG_MAX_FILES:-3}
healthcheck:
test:
- 'CMD-SHELL'
- >-
bun -e '(async () => { const { Redis } = await import("ioredis"); for (const url of [process.env.REDIS_URL, process.env.REDIS_CACHE_URL]) { if (!url) process.exit(1); const r = new Redis(url, { lazyConnect: true, connectTimeout: 3000, maxRetriesPerRequest: 1, retryStrategy: () => null }); r.on("error", () => process.exit(1)); await r.ping(); r.disconnect(); } process.exit(0) })().catch(() => process.exit(1))'
interval: 30s
timeout: 6s
retries: 3
start_period: ${STARTUP_GRACE_PERIOD:-30m}
mongo:
image: ${MONGO_IMAGE:-mongo:7.0.45@sha256:8bb4442761a63a8dda452744082cdac9644b429807eb977b42324a63cef59ca4}
restart: always
command: ['mongod', '--wiredTigerCacheSizeGB', '${MONGO_WIREDTIGER_CACHE_GB:-1.0}']
volumes:
- /mnt/docker/mongo/data:/data/db
networks:
- internal
ports:
- '27017:27017'
logging:
driver: json-file
options:
max-size: ${CONTAINER_LOG_MAX_SIZE:-10m}
max-file: ${CONTAINER_LOG_MAX_FILES:-3}
healthcheck:
test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
redis:
image: ${REDIS_IMAGE:-redis:8.6-alpine@sha256:91c71f9ea78fa3fe268ff832a985c48e592244f707993773f8b3e1b244ac1137}
restart: always
# Durable queue/rate-limit state lives in the node-local `redis-data`
# volume, which only exists on the node that first ran redis. Constrain
# the service to the node that hosts it: a Swarm reschedule onto a node
# without the volume would start empty and lose that state.
# Operator precondition: EXACTLY ONE node carries the
# `audnexus-redis=true` label, for example
# docker node update --label-add audnexus-redis=true <node>
# If no node carries the label, the service stays pending: add the label
# to a node, then deploy. Labeling a second node is NOT safe: Swarm may
# reschedule redis there, where the node-local volume is empty, losing
# queue/rate-limit state. Moving the label to another node requires
# restoring/migrating the existing `redis-data` volume first.
deploy:
placement:
constraints:
- node.labels.audnexus-redis == true
command:
- redis-server
- --appendonly
- 'yes'
- --appendfsync
- everysec
- --save
- '900'
- '1'
- --save
- '300'
- '10'
- --save
- '60'
- '10000'
- --maxmemory
- ${REDIS_CONTROL_MAXMEMORY:-128mb}
- --maxmemory-policy
- noeviction
- --dir
- /data
volumes:
- redis-data:/data
networks:
- internal
ports:
- '6379:6379'
logging:
driver: json-file
options:
max-size: ${CONTAINER_LOG_MAX_SIZE:-10m}
max-file: ${CONTAINER_LOG_MAX_FILES:-3}
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 30s
timeout: 3s
retries: 3
start_period: 10s
redis-cache:
image: ${REDIS_CACHE_IMAGE:-redis:8.6-alpine@sha256:91c71f9ea78fa3fe268ff832a985c48e592244f707993773f8b3e1b244ac1137}
restart: always
command:
- redis-server
- --save
- ''
- --appendonly
- 'no'
- --maxmemory
- ${REDIS_CACHE_MAXMEMORY:-512mb}
- --maxmemory-policy
- allkeys-lfu
networks:
- internal
logging:
driver: json-file
options:
max-size: ${CONTAINER_LOG_MAX_SIZE:-10m}
max-file: ${CONTAINER_LOG_MAX_FILES:-3}
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 30s
timeout: 3s
retries: 3
start_period: 10s
traefik:
image: traefik:v3.7.8@sha256:4299bbed850421258fc5448c2e0e6ad350981d4d335a68de11b92448aedbefe5
restart: always
command:
- '--providers.docker=true'
- '--entryPoints.websecure.address=:443'
- '--providers.docker.exposedbydefault=false'
- '--entrypoints.websecure.http.tls=true'
- '--certificatesresolvers.myresolver.acme.tlschallenge=true'
- '--certificatesresolvers.myresolver.acme.email=${TRAEFIK_EMAIL}'
- '--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json'
ports:
- '443:443'
logging:
driver: json-file
options:
max-size: ${CONTAINER_LOG_MAX_SIZE:-10m}
max-file: ${CONTAINER_LOG_MAX_FILES:-3}
volumes:
- /mnt/docker/letsencrypt:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- traefik-overlay
deploy:
replicas: 1
volumes:
redis-data:
networks:
traefik-overlay:
internal: