-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
339 lines (280 loc) · 6.86 KB
/
docker-compose.prod.yml
File metadata and controls
339 lines (280 loc) · 6.86 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
339
# ============================================
# DeeperSensor API - Production Compose
# ============================================
# Optimized for production deployment with:
# - Resource limits
# - Health checks
# - Security hardening
# - Proper restart policies
# - Network isolation
version: "3.9"
networks:
frontend:
driver: bridge
backend:
driver: bridge
internal: true
volumes:
postgres_data:
driver: local
redis_data:
driver: local
ollama_models:
driver: local
services:
# ===========================================
# API Service
# ===========================================
api:
build:
context: .
dockerfile: crates/api/Dockerfile
args:
RUST_VERSION: "1.82"
image: deepersensor/api:${IMAGE_TAG:-latest}
container_name: deepersensor-api
env_file:
- .env
environment:
- APP_ENV=production
- DATABASE_URL=postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-deepersensor}
- REDIS_URL=redis://:${REDIS_PASSWORD:-changeme}@redis:6379/0
- OLLAMA_BASE_URL=http://ollama:11434
expose:
- "8080"
networks:
- frontend
- backend
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ollama:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:8080/health || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 40s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp:size=100M,mode=1777
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
labels: "service=api"
# ===========================================
# PostgreSQL Database
# ===========================================
postgres:
image: postgres:16-alpine
container_name: deepersensor-postgres
environment:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
- POSTGRES_DB=${POSTGRES_DB:-deepersensor}
- PGDATA=/var/lib/postgresql/data/pgdata
expose:
- "5432"
networks:
- backend
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
security_opt:
- no-new-privileges:true
command:
- "postgres"
- "-c"
- "max_connections=100"
- "-c"
- "shared_buffers=256MB"
- "-c"
- "effective_cache_size=1GB"
- "-c"
- "maintenance_work_mem=64MB"
- "-c"
- "checkpoint_completion_target=0.9"
- "-c"
- "wal_buffers=16MB"
- "-c"
- "default_statistics_target=100"
- "-c"
- "random_page_cost=1.1"
- "-c"
- "effective_io_concurrency=200"
- "-c"
- "work_mem=2621kB"
- "-c"
- "min_wal_size=1GB"
- "-c"
- "max_wal_size=4GB"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
labels: "service=postgres"
# ===========================================
# Redis Cache
# ===========================================
redis:
image: redis:7-alpine
container_name: deepersensor-redis
command:
- "redis-server"
- "--requirepass"
- "${REDIS_PASSWORD:-changeme}"
- "--maxmemory"
- "256mb"
- "--maxmemory-policy"
- "allkeys-lru"
- "--save"
- ""
- "--appendonly"
- "no"
expose:
- "6379"
networks:
- backend
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.1'
memory: 128M
security_opt:
- no-new-privileges:true
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "2"
labels: "service=redis"
# ===========================================
# Ollama Model Server
# ===========================================
ollama:
image: ollama/ollama:latest
container_name: deepersensor-ollama
expose:
- "11434"
networks:
- backend
volumes:
- ollama_models:/root/.ollama
restart: unless-stopped
deploy:
resources:
limits:
cpus: '4.0'
memory: 8G
reservations:
cpus: '1.0'
memory: 2G
security_opt:
- no-new-privileges:true
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "2"
labels: "service=ollama"
# ===========================================
# Nginx Reverse Proxy
# ===========================================
nginx:
build:
context: .
dockerfile: nginx/Dockerfile
image: deepersensor/nginx:${IMAGE_TAG:-latest}
container_name: deepersensor-nginx
depends_on:
api:
condition: service_healthy
ports:
- "${NGINX_HTTP_PORT:-80}:80"
# Uncomment for TLS
# - "${NGINX_HTTPS_PORT:-443}:443"
networks:
- frontend
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE
- CHOWN
- SETUID
- SETGID
read_only: true
tmpfs:
- /var/cache/nginx:size=50M,mode=0755
- /var/run:size=10M,mode=0755
- /tmp:size=10M,mode=1777
# For TLS certificates
# volumes:
# - ./certs:/etc/nginx/certs:ro
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "5"
labels: "service=nginx"