-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
359 lines (337 loc) · 9.59 KB
/
Copy pathdocker-compose.yml
File metadata and controls
359 lines (337 loc) · 9.59 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
version: '3.8'
# ============================================
# SERVICES
# ============================================
services:
# ============================================
# REDIS - Rate Limiting & Caching
# ============================================
redis:
image: redis:7-alpine
container_name: spam_redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --appendonly yes
networks:
- spam_network
- internal
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
deploy:
resources:
limits:
memory: 256M
reservations:
memory: 128M
# ============================================
# ML API - Flask Prediction Service
# ============================================
ml-api:
image: rudra2006/spam-ml-api:latest
build:
context: ./backend
dockerfile: Dockerfile.api
container_name: spam_ml_api
ports:
- "5000:5000"
environment:
- FLASK_PORT=5000
- FLASK_HOST=0.0.0.0
- FLASK_DEBUG=false
- MODEL_PATH=linear_svm_model.pkl
- VECTORIZER_PATH=tfidf_vectorizer.pkl
- LABEL_ENCODER_PATH=label_encoder.pkl
- URL_MODEL_PATH=url_detector.pkl
- URL_VECTORIZER_PATH=url_vectorizer.pkl
# Zero Trust Configuration
- INTERNAL_SECRET=${INTERNAL_SECRET}
- SERVICE_IP_ALLOWLIST=172.20.0.0/16,127.0.0.1,::1
- NODE_ENV=production
- ENABLE_ZERO_TRUST=true
- REDIS_URL=redis://redis:6379
- LOG_LEVEL=INFO
depends_on:
redis:
condition: service_healthy
networks:
- spam_network
- internal
restart: unless-stopped
volumes:
- ./backend/imap_connections.db:/app/imap_connections.db
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:5000/health')\" || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# ============================================
# NODE BACKEND - API Gateway
# ============================================
node-backend:
image: rudra2006/spam-node-backend:latest
build:
context: ./backend
dockerfile: Dockerfile.node
container_name: spam_node_backend
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- PORT=3000
- API_URL=http://ml-api:5000/predict
- ML_API_URL=http://ml-api:5000
- MONGODB_URI=${MONGODB_URI}
- JWT_SECRET=${JWT_SECRET}
- JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-7d}
# Zero Trust Configuration
- INTERNAL_SECRET=${INTERNAL_SECRET}
- SERVICE_IP_ALLOWLIST=172.20.0.0/16,127.0.0.1,::1
- ENABLE_ZERO_TRUST=true
- REDIS_URL=redis://redis:6379
# Rate Limiting Configuration
- PREDICT_RATE_LIMIT_WINDOW_MS=60000
- PREDICT_RATE_LIMIT_MAX=30
- LOGIN_RATE_LIMIT_MAX=5
- REGISTER_RATE_LIMIT_MAX=5
- RESET_RATE_LIMIT_MAX=3
- API_RATE_LIMIT_MAX=100
- CHAT_RATE_LIMIT_MAX=15
- OTP_RATE_LIMIT_MAX=3
- VERIFICATION_RATE_LIMIT_MAX=5
- BULK_PREDICT_RATE_LIMIT_MAX=10
- EXPORT_RATE_LIMIT_MAX=5
- FEEDBACK_RATE_LIMIT_MAX=10
# OAuth Configuration
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
- MICROSOFT_CLIENT_ID=${MICROSOFT_CLIENT_ID}
- MICROSOFT_CLIENT_SECRET=${MICROSOFT_CLIENT_SECRET}
# Email Configuration
- EMAIL_FROM=${EMAIL_FROM:-noreply@spamdetection.com}
- PASSWORD_RESET_TOKEN_EXPIRES=${PASSWORD_RESET_TOKEN_EXPIRES:-15m}
# Frontend URLs
- FRONTEND_URL=${FRONTEND_URL:-http://localhost}
- FRONTEND_DEV_URL=${FRONTEND_DEV_URL:-http://localhost:5173}
# Admin Configuration
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123}
- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
# IMAP Configuration
- IMAP_ENCRYPTION_KEY=${IMAP_ENCRYPTION_KEY}
- IMAP_DB_PATH=${IMAP_DB_PATH:-./imap_connections.db}
# Logging
- LOG_LEVEL=info
depends_on:
ml-api:
condition: service_healthy
redis:
condition: service_healthy
networks:
- spam_network
- internal
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
volumes:
- ./backend/uploads:/app/uploads
- ./backend/logs:/app/logs
- ./backend/imap_connections.db:/app/imap_connections.db
# ============================================
# FRONTEND - React Application
# ============================================
frontend:
image: rudra2006/spam-frontend:latest
build:
context: ./frontend
dockerfile: Dockerfile
args:
- VITE_API_URI=${VITE_API_URI:-http://localhost:3000/api}
- VITE_PYTHON_URI=${VITE_PYTHON_URI:-http://localhost:5000}
- VITE_GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
container_name: spam_frontend
ports:
- "80:80"
- "443:443"
depends_on:
node-backend:
condition: service_healthy
networks:
- spam_network
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:80"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
deploy:
resources:
limits:
memory: 256M
reservations:
memory: 128M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# ============================================
# NGINX - Reverse Proxy with Zero Trust
# ============================================
nginx:
image: nginx:alpine
container_name: spam_nginx
ports:
- "8080:80"
- "8443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./ssl:/etc/nginx/ssl:ro
- ./nginx/rate-limit.conf:/etc/nginx/rate-limit.conf:ro
depends_on:
- frontend
- node-backend
- ml-api
networks:
- spam_network
- internal
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:80/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
deploy:
resources:
limits:
memory: 128M
reservations:
memory: 64M
# ============================================
# MONGODB - Database
# ============================================
mongodb:
image: mongo:6-jammy
container_name: spam_mongodb
ports:
- "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME:-admin}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD:-password}
- MONGO_INITDB_DATABASE=spamdetection
volumes:
- mongodb-data:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
networks:
- internal
restart: unless-stopped
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# ============================================
# MONGODB EXPRESS - Database GUI
# ============================================
mongo-express:
image: mongo-express:latest
container_name: spam_mongo_express
ports:
- "8081:8081"
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_USERNAME:-admin}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_PASSWORD:-password}
- ME_CONFIG_MONGODB_SERVER=mongodb
- ME_CONFIG_BASICAUTH_USERNAME=${ME_USERNAME:-admin}
- ME_CONFIG_BASICAUTH_PASSWORD=${ME_PASSWORD:-admin123}
depends_on:
mongodb:
condition: service_healthy
networks:
- internal
restart: unless-stopped
deploy:
resources:
limits:
memory: 128M
reservations:
memory: 64M
# ============================================
# VOLUMES
# ============================================
volumes:
redis-data:
driver: local
mongodb-data:
driver: local
backend-uploads:
driver: local
backend-logs:
driver: local
# ============================================
# NETWORKS
# ============================================
networks:
# Public network for frontend and external access
spam_network:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
gateway: 172.20.0.1
# Internal network for service-to-service communication (Zero Trust)
internal:
driver: bridge
internal: true # No external access
ipam:
config:
- subnet: 172.21.0.0/16
gateway: 172.21.0.1