Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
315 lines (303 loc) · 9.99 KB
/
Copy pathdocker-compose.yml
File metadata and controls
315 lines (303 loc) · 9.99 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
# Docker counts the active file in max-file; approximately 30 MiB per container.
x-container-logging: &container-logging
driver: json-file
options:
max-size: "10m"
max-file: "3"
x-backend-build: &backend-build
context: ./backend
dockerfile: Dockerfile
target: production
services:
# PostgreSQL Database
postgres:
image: postgres:15-alpine
logging: *container-logging
restart: unless-stopped
deploy:
resources:
limits:
memory: 512m
cpus: '1.0'
reservations:
memory: 256m
cpus: '0.25'
security_opt:
- no-new-privileges:true
environment:
POSTGRES_USER: ${POSTGRES_USER:-owlculus}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-}
POSTGRES_DB: ${POSTGRES_DB:-owlculus}
volumes:
- postgres_data:/var/lib/postgresql/data
# Database port not exposed to host for security
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-owlculus} -d ${POSTGRES_DB:-owlculus}"]
interval: 10s
timeout: 5s
retries: 5
networks:
- backend-network
# Execution broker and event storage (retain the existing volume)
redis:
image: redis:7-alpine
logging: *container-logging
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes", "--maxmemory", "${REDIS_MAXMEMORY:-256mb}", "--maxmemory-policy", "noeviction"]
mem_limit: 384m
volumes:
- redis_data:/data
healthcheck:
test: ["CMD-SHELL", "redis-cli --raw EVAL \"redis.call('LPUSH', KEYS[1], 'probe'); redis.call('EXPIRE', KEYS[1], 5); redis.call('DEL', KEYS[1]); return 1\" 1 owlculus:health:container | grep -qx 1"]
interval: 10s
timeout: 5s
retries: 5
networks:
- backend-network
auth-redis:
image: redis:7-alpine
logging: *container-logging
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes", "--maxmemory", "${AUTH_REDIS_MAXMEMORY:-32mb}", "--maxmemory-policy", "noeviction"]
mem_limit: 128m
volumes:
- auth_redis_data:/data
healthcheck:
test: ["CMD-SHELL", "redis-cli --raw EVAL \"redis.call('ZADD', KEYS[1], 1, 'probe'); redis.call('EXPIRE', KEYS[1], 5); redis.call('DEL', KEYS[1]); return 1\" 1 owlculus:health:container | grep -qx 1"]
interval: 10s
timeout: 5s
retries: 5
networks:
- auth-network
# Backend API
backend:
build: *backend-build
logging: *container-logging
restart: unless-stopped
deploy:
resources:
limits:
memory: 1g
cpus: '2.0'
reservations:
memory: 512m
cpus: '0.5'
security_opt:
- no-new-privileges:true
environment:
POSTGRES_USER: ${RUNTIME_POSTGRES_USER:-owlculus_runtime}
POSTGRES_PASSWORD: ${RUNTIME_POSTGRES_PASSWORD:-}
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_DB: ${POSTGRES_DB:-owlculus}
OWLCULUS_ENV: production
SECRET_KEY: ${SECRET_KEY:-}
AUTH_REDIS_URL: ${AUTH_REDIS_URL:-redis://auth-redis:6379/0}
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
EXECUTION_BROKER_URL: ${EXECUTION_BROKER_URL:-${REDIS_URL:-redis://redis:6379/0}}
EXECUTION_EVENT_REDIS_URL: ${EXECUTION_EVENT_REDIS_URL:-${REDIS_URL:-redis://redis:6379/0}}
WEB_CONCURRENCY: ${API_WORKERS:-1}
API_DATABASE_CONCURRENCY: ${API_DATABASE_CONCURRENCY:-8}
DATABASE_POOL_SIZE: ${API_DATABASE_POOL_SIZE:-5}
DATABASE_MAX_OVERFLOW: ${API_DATABASE_MAX_OVERFLOW:-5}
EXECUTION_LIMIT_GLOBAL: ${EXECUTION_LIMIT_GLOBAL:-1000}
EXECUTION_LIMIT_CASE: ${EXECUTION_LIMIT_CASE:-100}
EXECUTION_LIMIT_USER: ${EXECUTION_LIMIT_USER:-25}
LOGIN_IP_MAX_ATTEMPTS: ${LOGIN_IP_MAX_ATTEMPTS:-30}
LOGIN_ACCOUNT_MAX_ATTEMPTS: ${LOGIN_ACCOUNT_MAX_ATTEMPTS:-10}
LOGIN_LIMIT_WINDOW_SECONDS: ${LOGIN_LIMIT_WINDOW_SECONDS:-300}
FORWARDED_ALLOW_IPS: ${FORWARDED_ALLOW_IPS:-172.29.0.254}
volumes:
- uploads_data:/app/uploads
- setup_data:/app/data/setup
expose:
- "8000"
depends_on:
db-init:
condition: service_completed_successfully
auth-redis:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health/ready"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- frontend-network
- backend-network
- auth-network
plugin-worker:
mem_limit: ${PLUGIN_WORKER_MEMORY:-1g}
stop_grace_period: 75s
build: *backend-build
logging: *container-logging
restart: unless-stopped
command: ["celery", "-A", "app.executions.celery_app:app", "worker", "--pool=prefork", "--concurrency=${PLUGIN_CONCURRENCY:-2}", "--prefetch-multiplier=1", "--queues=owlculus.plugins", "--hostname=plugins@%h", "--loglevel=WARNING"]
environment: &execution-environment
DATABASE_POOL_SIZE: ${WORKER_DATABASE_POOL_SIZE:-2}
DATABASE_MAX_OVERFLOW: ${WORKER_DATABASE_MAX_OVERFLOW:-0}
WORKER_MAX_TASKS_PER_CHILD: ${WORKER_MAX_TASKS_PER_CHILD:-100}
WORKER_MAX_MEMORY_KB: ${WORKER_MAX_MEMORY_KB:-262144}
PLUGIN_EXECUTION_SECONDS: ${PLUGIN_EXECUTION_SECONDS:-900}
HUNT_STEP_SECONDS: ${HUNT_STEP_SECONDS:-900}
HUNT_EXECUTION_SECONDS: ${HUNT_EXECUTION_SECONDS:-7200}
EXECUTION_EVENT_LIMIT_BYTES: ${EXECUTION_EVENT_LIMIT_BYTES:-1048576}
EXECUTION_RESULT_LIMIT_BYTES: ${EXECUTION_RESULT_LIMIT_BYTES:-26214400}
EXECUTION_DISPATCH_POLL_SECONDS: ${EXECUTION_DISPATCH_POLL_SECONDS:-0.2}
EXECUTION_REDISPATCH_SECONDS: ${EXECUTION_REDISPATCH_SECONDS:-30}
POSTGRES_USER: ${RUNTIME_POSTGRES_USER:-owlculus_runtime}
POSTGRES_PASSWORD: ${RUNTIME_POSTGRES_PASSWORD:-}
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_DB: ${POSTGRES_DB:-owlculus}
OWLCULUS_ENV: production
SECRET_KEY: ${SECRET_KEY:-}
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
EXECUTION_BROKER_URL: ${EXECUTION_BROKER_URL:-${REDIS_URL:-redis://redis:6379/0}}
EXECUTION_EVENT_REDIS_URL: ${EXECUTION_EVENT_REDIS_URL:-${REDIS_URL:-redis://redis:6379/0}}
volumes:
- uploads_data:/app/uploads
depends_on:
db-init:
condition: service_completed_successfully
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "celery -A app.executions.celery_app:app inspect ping --destination plugins@$$HOSTNAME --timeout 5"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
networks:
- backend-network
- worker-egress
hunt-worker:
mem_limit: ${HUNT_WORKER_MEMORY:-1g}
stop_grace_period: 75s
build: *backend-build
logging: *container-logging
restart: unless-stopped
command: ["celery", "-A", "app.executions.celery_app:app", "worker", "--pool=prefork", "--concurrency=${HUNT_CONCURRENCY:-2}", "--prefetch-multiplier=1", "--queues=owlculus.hunts", "--hostname=hunts@%h", "--loglevel=WARNING"]
environment: *execution-environment
volumes:
- uploads_data:/app/uploads
depends_on:
db-init:
condition: service_completed_successfully
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "celery -A app.executions.celery_app:app inspect ping --destination hunts@$$HOSTNAME --timeout 5"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
networks:
- backend-network
- worker-egress
execution-dispatcher:
build: *backend-build
logging: *container-logging
restart: unless-stopped
command: ["python", "-m", "app.executions.dispatcher"]
environment: *execution-environment
depends_on:
db-init:
condition: service_completed_successfully
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import os,time; assert time.time()-os.stat('/tmp/owlculus-dispatcher-heartbeat').st_mtime < 30"]
interval: 15s
timeout: 5s
retries: 3
networks:
- backend-network
# Database Initialization
db-init:
build: *backend-build
environment:
POSTGRES_USER: ${POSTGRES_USER:-owlculus}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-}
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_DB: ${POSTGRES_DB:-owlculus}
RUNTIME_POSTGRES_USER: ${RUNTIME_POSTGRES_USER:-owlculus_runtime}
RUNTIME_POSTGRES_PASSWORD: ${RUNTIME_POSTGRES_PASSWORD:-}
OWLCULUS_ENV: production
SECRET_KEY: ${SECRET_KEY:-}
command: python3 -m app.database.init_db
depends_on:
postgres:
condition: service_healthy
networks:
- backend-network
logging: *container-logging
restart: "no"
# Browser-facing Caddy gateway and compiled SPA
frontend:
build:
context: .
dockerfile: frontend/Dockerfile
target: production
logging: *container-logging
restart: unless-stopped
deploy:
resources:
limits:
memory: 256m
cpus: '0.5'
reservations:
memory: 128m
cpus: '0.1'
security_opt:
- no-new-privileges:true
environment:
DOMAIN: ${DOMAIN:-:80}
ports:
- "${FRONTEND_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443"
volumes:
- caddy_data:/data
- caddy_config:/config
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:8080/health/ready"]
interval: 30s
timeout: 10s
retries: 3
networks:
frontend-network:
ipv4_address: 172.29.0.254
volumes:
postgres_data:
driver: local
uploads_data:
driver: local
setup_data:
driver: local
auth_redis_data:
driver: local
redis_data:
driver: local
caddy_data:
driver: local
caddy_config:
driver: local
networks:
auth-network:
driver: bridge
internal: true
worker-egress:
driver: bridge
frontend-network:
driver: bridge
ipam:
config:
- subnet: 172.29.0.0/24
backend-network:
driver: bridge
internal: true