-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
337 lines (325 loc) · 11.8 KB
/
docker-compose.yml
File metadata and controls
337 lines (325 loc) · 11.8 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
# Phase-5 observability: labels + json-file logging anchors.
# HSH-HQ Alloy discovers this container by `com.barnardhq.*` and stamps
# project/service/tenant/env on every log stream. `docker-compose.demo.yml`
# (CHAD-HQ) overrides `com.barnardhq.env` to `demo`. Do NOT change label
# keys without updating `/opt/observability-agent/alloy/config.alloy`.
x-barnardhq-labels: &barnardhq-labels
com.barnardhq.project: "droneops"
com.barnardhq.env: "prod"
com.barnardhq.tenant: "shared"
com.barnardhq.stack: "droneops"
x-logging: &logging
driver: json-file
options:
max-size: "50m"
max-file: "5"
labels: "com.barnardhq.service,com.barnardhq.project,com.barnardhq.env,com.barnardhq.tenant,com.barnardhq.stack"
services:
db:
image: postgres:16-alpine
restart: unless-stopped
entrypoint: ["/scripts/primary-entrypoint.sh"]
command: ["postgres"]
environment:
POSTGRES_USER: ${POSTGRES_USER:-doc}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme_in_production}
POSTGRES_DB: ${POSTGRES_DB:-doc}
REPLICATION_PASSWORD: ${REPLICATION_PASSWORD:-SecureDroneRepl2026}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./scripts/primary-entrypoint.sh:/scripts/primary-entrypoint.sh:ro
- ./scripts/init-primary.sh:/docker-entrypoint-initdb.d/init-primary.sh:ro
ports:
- "127.0.0.1:5434:5432"
- "10.99.0.1:5434:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-doc}"]
interval: 5s
timeout: 5s
retries: 5
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-db"
logging: *logging
redis:
image: redis:7-alpine
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 5
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-redis"
logging: *logging
ollama:
image: ollama/ollama:latest
restart: unless-stopped
volumes:
- ollama_data:/root/.ollama
environment:
- OLLAMA_HOST=0.0.0.0
# Keep model loaded in RAM permanently
- OLLAMA_KEEP_ALIVE=-1
# Single-request mode — all CPU goes to one generation
- OLLAMA_NUM_PARALLEL=1
# Only keep one model loaded (saves RAM for the model itself)
- OLLAMA_MAX_LOADED_MODELS=1
# Enable flash attention for faster inference
- OLLAMA_FLASH_ATTENTION=1
cpuset: "0-5"
mem_reservation: 8g
healthcheck:
test: ["CMD-SHELL", "bash -c 'echo > /dev/tcp/localhost/11434' || exit 1"]
interval: 15s
timeout: 10s
retries: 5
start_period: 30s
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-ollama"
logging: *logging
ollama-setup:
image: curlimages/curl:latest
depends_on:
ollama:
condition: service_healthy
restart: "no"
entrypoint: >
sh -c "
echo 'Waiting for Ollama to be ready...' &&
until curl -s http://ollama:11434/api/tags > /dev/null 2>&1; do sleep 2; done &&
echo 'Pulling Llama 3.1 8B model...' &&
curl -s http://ollama:11434/api/pull -d '{\"name\": \"llama3.1:8b-instruct-q4_K_M\"}' &&
echo 'Model pulled. Will load into RAM on first use.'
"
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-ollama-setup"
logging: *logging
# ── Watchtower — Auto-update monitoring ────────────────────────
# Checks for new images daily and sends notifications.
# Set WATCHTOWER_NOTIFICATION_URL in .env for alerts.
watchtower:
image: containrrr/watchtower:latest
restart: unless-stopped
environment:
- WATCHTOWER_CLEANUP=true
- WATCHTOWER_LABEL_ENABLE=true
- WATCHTOWER_POLL_INTERVAL=86400
- WATCHTOWER_MONITOR_ONLY=${WATCHTOWER_MONITOR_ONLY:-false}
- WATCHTOWER_NOTIFICATION_URL=${WATCHTOWER_NOTIFICATION_URL:-}
- WATCHTOWER_NOTIFICATIONS_HOSTNAME=droneops-server
- DOCKER_API_VERSION=1.45
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-watchtower"
logging: *logging
backend:
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
# tini reaps orphan curl/subprocesses spawned by FastAPI handlers so
# they never accumulate as <defunct> (matches worker service; observed
# uvicorn zombies 2026-04-19 during HSH-HQ high-load incident).
init: true
dns:
- 1.1.1.1
- 8.8.8.8
environment:
- DATABASE_URL=${DATABASE_URL:-postgresql+asyncpg://doc:changeme_in_production@db:5432/doc}
- REDIS_URL=${REDIS_URL:-redis://redis:6379/0}
- OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://ollama:11434}
- OLLAMA_MODEL=${OLLAMA_MODEL:-llama3.1:8b-instruct-q4_K_M}
- OPENDRONELOG_URL=${OPENDRONELOG_URL:-}
- JWT_SECRET_KEY=${JWT_SECRET_KEY:-changeme_generate_a_random_secret}
- JWT_ALGORITHM=${JWT_ALGORITHM:-HS256}
- JWT_ACCESS_TOKEN_EXPIRE_MINUTES=${JWT_ACCESS_TOKEN_EXPIRE_MINUTES:-30}
- JWT_REFRESH_TOKEN_EXPIRE_DAYS=${JWT_REFRESH_TOKEN_EXPIRE_DAYS:-30}
- DEMO_ADMIN_USERNAME=${DEMO_ADMIN_USERNAME:-}
- DEMO_ADMIN_PASSWORD=${DEMO_ADMIN_PASSWORD:-}
- SMTP_HOST=${SMTP_HOST:-}
- SMTP_PORT=${SMTP_PORT:-587}
- SMTP_USER=${SMTP_USER:-}
- SMTP_PASSWORD=${SMTP_PASSWORD:-}
- SMTP_FROM_EMAIL=${SMTP_FROM_EMAIL:-}
- SMTP_FROM_NAME=${SMTP_FROM_NAME:-}
- SMTP_USE_TLS=${SMTP_USE_TLS:-true}
- UPLOAD_DIR=/data/uploads
- REPORTS_DIR=/data/reports
- FRONTEND_URL=${FRONTEND_URL:-http://localhost:3080}
# Phase-5 observability — all DSN/endpoint gated (unset = no-op).
- SENTRY_DSN=${SENTRY_DSN:-}
- SENTRY_TRACES_SAMPLE_RATE=${SENTRY_TRACES_SAMPLE_RATE:-0.05}
- SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT:-production}
- OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT:-}
- OTEL_SERVICE_NAME=droneops-api
- TENANT=${TENANT:-shared}
- ENV=${ENV:-prod}
- APP_VERSION=2.63.1
volumes:
- app_data:/data
ports:
- "8000:8000"
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
ollama:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:8000/api/health || exit 1"]
interval: 15s
timeout: 10s
retries: 5
start_period: 45s
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-api"
logging: *logging
worker:
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
# PID 1 init reaper — without this, celery prefork children that exit
# become zombies if the master loses a SIGCHLD reap. The 2026-04-19
# high-load incident found 33 defunct celery children of the worker
# master accumulating ~2/hr over 18h, contributing to the
# HostZombieProcesses alert. tini (docker init: true) reaps any orphan.
# See docs/incidents/2026-04-19-hsh-hq-high-load.md.
init: true
# --max-tasks-per-child=50 forces each prefork child to recycle after
# 50 tasks. Combined with init: true, this guarantees zombies cannot
# accumulate even if a child cleanup path raises. 50 is conservative —
# report+email tasks are short-lived, child startup cost is dominated
# by Sentry/OTEL init (~3-5s), so 50/child amortizes that fine.
command: celery -A app.tasks.celery_tasks worker --loglevel=info --max-tasks-per-child=50
healthcheck:
# Redis-backed worker heartbeat (replaces the old `celery inspect ping`
# subprocess which re-imported the full OTel chain every 60s — 3-5s of
# wasted CPU per check). The worker writes a unix-ts key to Redis on
# every `worker_heartbeat` Celery signal (~2s cadence). Healthcheck
# reads the key and verifies age < 60s.
# - Fresh key → Celery control loop is alive → worker healthy.
# - Stale/missing key → worker frozen/crashed → docker restarts.
# Fast path: no Python process spawn, just a Redis GET.
test:
- CMD-SHELL
- >
K=$$(redis-cli -h redis -p 6379 get droneops:worker:heartbeat 2>/dev/null);
if [ -z "$$K" ]; then exit 1; fi;
AGE=$$(( $$(date +%s) - $$K ));
if [ $$AGE -gt 60 ]; then exit 1; else exit 0; fi
interval: 30s
timeout: 5s
retries: 3
start_period: 30s
environment:
- DATABASE_URL=${DATABASE_URL:-postgresql+asyncpg://doc:changeme_in_production@db:5432/doc}
- REDIS_URL=${REDIS_URL:-redis://redis:6379/0}
- OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://ollama:11434}
- OLLAMA_MODEL=${OLLAMA_MODEL:-llama3.1:8b-instruct-q4_K_M}
- SMTP_HOST=${SMTP_HOST:-}
- SMTP_PORT=${SMTP_PORT:-587}
- SMTP_USER=${SMTP_USER:-}
- SMTP_PASSWORD=${SMTP_PASSWORD:-}
- SMTP_FROM_EMAIL=${SMTP_FROM_EMAIL:-}
- SMTP_FROM_NAME=${SMTP_FROM_NAME:-}
- SMTP_USE_TLS=${SMTP_USE_TLS:-true}
- UPLOAD_DIR=/data/uploads
- REPORTS_DIR=/data/reports
# Phase-5 observability — all DSN/endpoint gated (unset = no-op).
- SENTRY_DSN=${SENTRY_DSN:-}
- SENTRY_TRACES_SAMPLE_RATE=${SENTRY_TRACES_SAMPLE_RATE:-0.05}
- SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT:-production}
- OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT:-}
- OTEL_SERVICE_NAME=droneops-worker
- TENANT=${TENANT:-shared}
- ENV=${ENV:-prod}
- APP_VERSION=2.63.1
volumes:
- app_data:/data
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-worker"
logging: *logging
flight-parser:
build:
context: ./flight-parser
dockerfile: Dockerfile
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:8100/health || exit 1"]
interval: 15s
timeout: 10s
retries: 3
start_period: 15s
dns:
- 1.1.1.1
- 8.8.8.8
environment:
- DJI_API_KEY=${DJI_API_KEY:-}
- PARSER_PORT=8100
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-flight-parser"
logging: *logging
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
# Sentry DSN is bundled into the JS at build time — Vite inlines
# any `VITE_*` var that's in scope when `npm run build` runs.
VITE_SENTRY_DSN: ${VITE_SENTRY_DSN:-}
VITE_SENTRY_ENVIRONMENT: ${VITE_SENTRY_ENVIRONMENT:-production}
VITE_APP_VERSION: "2.63.1"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:8080/ || exit 1"]
interval: 15s
timeout: 10s
retries: 3
start_period: 10s
ports:
- "${FRONTEND_PORT:-3080}:8080"
depends_on:
backend:
condition: service_healthy
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-frontend"
logging: *logging
# ── Cloudflare Tunnel ─────────────────────────────────────────────
# Exposes the app securely without opening router ports.
# Set CLOUDFLARE_TUNNEL_TOKEN in .env — service is a no-op without it.
cloudflared:
image: cloudflare/cloudflared:latest
restart: unless-stopped
command: tunnel run
environment:
- TUNNEL_TOKEN=${CLOUDFLARE_TUNNEL_TOKEN:-}
depends_on:
frontend:
condition: service_healthy
backend:
condition: service_healthy
labels:
<<: *barnardhq-labels
com.barnardhq.service: "droneops-cloudflared"
logging: *logging
volumes:
postgres_data:
ollama_data:
app_data: