-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
405 lines (366 loc) · 12.5 KB
/
Copy pathdocker-compose.yml
File metadata and controls
405 lines (366 loc) · 12.5 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# ===================================
# Code Keeper Bot - Docker Compose
# בוט שומר קבצי קוד - הרכב מלא
# ===================================
version: '3.8'
services:
# ===================================
# MongoDB Database
# ===================================
mongodb:
image: mongo:6.0
container_name: code-keeper-mongodb
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME:-admin}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-password123}
MONGO_INITDB_DATABASE: ${DATABASE_NAME:-code_keeper_bot}
ports:
- "${MONGO_PORT:-27017}:27017"
volumes:
- mongodb_data:/data/db
- mongodb_config:/data/configdb
- ./docker/mongodb/init-scripts:/docker-entrypoint-initdb.d:ro
networks:
- code-keeper-network
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
command: mongod --auth
# ===================================
# Redis Cache (אופציונלי)
# ===================================
redis:
image: redis:7-alpine
container_name: code-keeper-redis
restart: unless-stopped
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
- redis_data:/data
networks:
- code-keeper-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
command: redis-server --requirepass ${REDIS_PASSWORD:-redis123}
# ===================================
# Code Keeper Bot - Production
# ===================================
code-keeper-bot:
build:
context: .
dockerfile: Dockerfile
target: production
container_name: code-keeper-bot
restart: unless-stopped
environment:
# Bot settings
BOT_TOKEN: ${BOT_TOKEN}
# Enable internal share web + base URL for public links
ENABLE_INTERNAL_SHARE_WEB: ${ENABLE_INTERNAL_SHARE_WEB:-true}
PUBLIC_BASE_URL: ${PUBLIC_BASE_URL:-http://localhost:${BOT_PORT:-8000}}
# Database
MONGODB_URL: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-password123}@mongodb:27017/${DATABASE_NAME:-code_keeper_bot}?authSource=admin
DATABASE_NAME: ${DATABASE_NAME:-code_keeper_bot}
# Cache
REDIS_URL: redis://:${REDIS_PASSWORD:-redis123}@redis:6379/0
CACHE_TTL: ${CACHE_TTL:-300}
# External integrations
GITHUB_TOKEN: ${GITHUB_TOKEN}
PASTEBIN_API_KEY: ${PASTEBIN_API_KEY}
# Performance
MAX_CODE_SIZE: ${MAX_CODE_SIZE:-100000}
MAX_FILES_PER_USER: ${MAX_FILES_PER_USER:-1000}
# Appearance
HIGHLIGHT_THEME: ${HIGHLIGHT_THEME:-github-dark}
# Security
ADMIN_USER_IDS: ${ADMIN_USER_IDS}
# Logging
LOG_LEVEL: ${LOG_LEVEL:-INFO}
LOG_FILE: /app/logs/bot.log
# Server (for webhooks)
PORT: 8000
WEBHOOK_URL: ${WEBHOOK_URL}
WEBHOOK_SECRET: ${WEBHOOK_SECRET}
# Backup
AUTO_BACKUP_ENABLED: ${AUTO_BACKUP_ENABLED:-true}
BACKUP_FREQUENCY_HOURS: ${BACKUP_FREQUENCY_HOURS:-24}
MAX_BACKUPS_TO_KEEP: ${MAX_BACKUPS_TO_KEEP:-7}
# Monitoring
SENTRY_DSN: ${SENTRY_DSN}
ENABLE_METRICS: ${ENABLE_METRICS:-false}
# OpenTelemetry (optional)
# ברירת מחדל בדוקר: ינסה לשלוח ל-Jaeger בתוך הרשת של compose
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://jaeger:4317}
OTEL_EXPORTER_INSECURE: ${OTEL_EXPORTER_INSECURE:-true}
# Alerts → Telegram (used by /alertmanager/webhook forwarder)
ALERT_TELEGRAM_BOT_TOKEN: ${ALERT_TELEGRAM_BOT_TOKEN:-}
ALERT_TELEGRAM_CHAT_ID: ${ALERT_TELEGRAM_CHAT_ID:-}
# Alerts tuning – reduce noise (adaptive + anomaly)
ALERT_TELEGRAM_MIN_SEVERITY: ${ALERT_TELEGRAM_MIN_SEVERITY:-critical}
# Internal anomaly detector (metrics.py)
ALERT_ERRORS_PER_MINUTE: ${ALERT_ERRORS_PER_MINUTE:-40}
ALERT_AVG_RESPONSE_TIME: ${ALERT_AVG_RESPONSE_TIME:-0} # 0 disables avg_rt anomaly
ALERT_AVG_RESPONSE_TIME_DEPLOY: ${ALERT_AVG_RESPONSE_TIME_DEPLOY:-10}
DEPLOY_GRACE_PERIOD_SECONDS: ${DEPLOY_GRACE_PERIOD_SECONDS:-120}
ALERT_COOLDOWN_SECONDS: ${ALERT_COOLDOWN_SECONDS:-1200} # 20 minutes
# Adaptive alert manager (alert_manager.py)
ALERT_MIN_LATENCY_SECONDS: ${ALERT_MIN_LATENCY_SECONDS:-2.0} # floor for latency thresholds
ALERT_LATENCY_THRESHOLD_SCALE: ${ALERT_LATENCY_THRESHOLD_SCALE:-1.4}
ALERT_MIN_SAMPLE_COUNT: ${ALERT_MIN_SAMPLE_COUNT:-60}
ALERT_COOLDOWN_SEC: ${ALERT_COOLDOWN_SEC:-1200} # 20 minutes
ports:
- "${BOT_PORT:-8000}:8000"
volumes:
- ./logs:/app/logs
- ./backups:/app/backups
- ./temp:/app/temp
- bot_data:/app/data
networks:
- code-keeper-network
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "from config import config; print('OK')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# ===================================
# Code Keeper Bot - Development
# ===================================
code-keeper-bot-dev:
build:
context: .
dockerfile: Dockerfile
target: production
container_name: code-keeper-bot-dev
restart: unless-stopped
environment:
BOT_TOKEN: ${BOT_TOKEN}
MONGODB_URL: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-password123}@mongodb:27017/${DATABASE_NAME:-code_keeper_bot}_dev?authSource=admin
DATABASE_NAME: ${DATABASE_NAME:-code_keeper_bot}_dev
DEBUG: true
LOG_LEVEL: DEBUG
GITHUB_TOKEN: ${GITHUB_TOKEN}
PASTEBIN_API_KEY: ${PASTEBIN_API_KEY}
# Alerts → Telegram for dev as well (optional)
ALERT_TELEGRAM_BOT_TOKEN: ${ALERT_TELEGRAM_BOT_TOKEN}
ALERT_TELEGRAM_CHAT_ID: ${ALERT_TELEGRAM_CHAT_ID}
# Alerts tuning – reduce noise (dev)
ALERT_TELEGRAM_MIN_SEVERITY: ${ALERT_TELEGRAM_MIN_SEVERITY:-critical}
ALERT_ERRORS_PER_MINUTE: ${ALERT_ERRORS_PER_MINUTE:-40}
ALERT_AVG_RESPONSE_TIME: ${ALERT_AVG_RESPONSE_TIME:-0}
ALERT_AVG_RESPONSE_TIME_DEPLOY: ${ALERT_AVG_RESPONSE_TIME_DEPLOY:-10}
DEPLOY_GRACE_PERIOD_SECONDS: ${DEPLOY_GRACE_PERIOD_SECONDS:-120}
ALERT_COOLDOWN_SECONDS: ${ALERT_COOLDOWN_SECONDS:-1200}
ALERT_MIN_LATENCY_SECONDS: ${ALERT_MIN_LATENCY_SECONDS:-2.0}
ALERT_LATENCY_THRESHOLD_SCALE: ${ALERT_LATENCY_THRESHOLD_SCALE:-1.4}
ALERT_MIN_SAMPLE_COUNT: ${ALERT_MIN_SAMPLE_COUNT:-60}
ALERT_COOLDOWN_SEC: ${ALERT_COOLDOWN_SEC:-1200}
ports:
- "${BOT_DEV_PORT:-8001}:8000"
volumes:
- .:/app
- ./logs:/app/logs
- ./backups:/app/backups
- bot_dev_data:/app/data
networks:
- code-keeper-network
depends_on:
mongodb:
condition: service_healthy
profiles:
- development
command: python main.py
# ===================================
# MongoDB Express (אופציונלי)
# ===================================
mongo-express:
image: mongo-express:latest
container_name: code-keeper-mongo-express
restart: unless-stopped
ports:
- "${MONGO_EXPRESS_PORT:-8081}:8081"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USERNAME:-admin}
ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD:-password123}
ME_CONFIG_MONGODB_URL: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-password123}@mongodb:27017/
ME_CONFIG_BASICAUTH_USERNAME: ${MONGO_EXPRESS_USER:-admin}
ME_CONFIG_BASICAUTH_PASSWORD: ${MONGO_EXPRESS_PASS:-admin123}
depends_on:
- mongodb
networks:
- code-keeper-network
profiles:
- monitoring
# ===================================
# Nginx Reverse Proxy (אופציונלי)
# ===================================
nginx:
image: nginx:alpine
container_name: code-keeper-nginx
restart: unless-stopped
ports:
- "${NGINX_PORT:-80}:80"
- "${NGINX_SSL_PORT:-443}:443"
volumes:
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./docker/nginx/ssl:/etc/nginx/ssl:ro
- nginx_logs:/var/log/nginx
depends_on:
- code-keeper-bot
networks:
- code-keeper-network
profiles:
- production
# ===================================
# Prometheus Monitoring (אופציונלי)
# ===================================
prometheus:
image: prom/prometheus:latest
container_name: code-keeper-prometheus
restart: unless-stopped
ports:
- "${PROMETHEUS_PORT:-9090}:9090"
volumes:
- ./docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--storage.tsdb.retention.time=200h'
- '--web.enable-lifecycle'
networks:
- code-keeper-network
profiles:
- monitoring
# ===================================
# Alertmanager (אופציונלי)
# ===================================
alertmanager:
image: prom/alertmanager:latest
container_name: code-keeper-alertmanager
restart: unless-stopped
ports:
- "${ALERTMANAGER_PORT:-9093}:9093"
volumes:
- ./docker/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
networks:
- code-keeper-network
profiles:
- monitoring
# ===================================
# Grafana Dashboard (אופציונלי)
# ===================================
grafana:
image: grafana/grafana:latest
container_name: code-keeper-grafana
restart: unless-stopped
ports:
- "${GRAFANA_PORT:-3000}:3000"
environment:
GF_SECURITY_ADMIN_USER: ${GRAFANA_USER:-admin}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASS:-admin123}
volumes:
- grafana_data:/var/lib/grafana
- ./docker/grafana/provisioning:/etc/grafana/provisioning:ro
depends_on:
- prometheus
networks:
- code-keeper-network
profiles:
- monitoring
# ===================================
# Jaeger (Tracing backend - optional)
# ===================================
jaeger:
image: jaegertracing/all-in-one:1.57
container_name: code-keeper-jaeger
restart: unless-stopped
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
# Jaeger UI
- "${JAEGER_UI_PORT:-16686}:16686"
# OTLP gRPC receiver (for local testing outside the compose network)
- "${JAEGER_OTLP_GRPC_PORT:-4317}:4317"
# OTLP HTTP receiver (optional)
- "${JAEGER_OTLP_HTTP_PORT:-4318}:4318"
networks:
- code-keeper-network
profiles:
- monitoring
# ===================================
# Networks
# ===================================
networks:
code-keeper-network:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
# ===================================
# Volumes
# ===================================
volumes:
mongodb_data:
driver: local
mongodb_config:
driver: local
redis_data:
driver: local
bot_data:
driver: local
bot_dev_data:
driver: local
nginx_logs:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
# ===================================
# Scripts שימושיים
# ===================================
# הפעלה בסיסית:
# docker-compose up code-keeper-bot mongodb
# הפעלה עם Redis:
# docker-compose up code-keeper-bot mongodb redis
# הפעלה עם ניטור:
# docker-compose --profile monitoring up
# פיתוח:
# docker-compose --profile development up code-keeper-bot-dev mongodb
# ייצור מלא:
# docker-compose --profile production --profile monitoring up
# עצירה:
# docker-compose down
# עצירה עם מחיקת volumes:
# docker-compose down -v
# לוגים:
# docker-compose logs -f code-keeper-bot
# שחזור מגיבוי:
# docker-compose exec code-keeper-bot python -c "
# from backup_manager import backup_manager
# print(backup_manager.list_backups(user_id))
# "
# בדיקת תקינות:
# docker-compose exec code-keeper-bot python -c "
# from database import db
# print('MongoDB:', 'Connected' if db.client else 'Disconnected')
# from utils import get_memory_usage
# print('Memory:', get_memory_usage())
# "