-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
219 lines (209 loc) · 7.25 KB
/
Copy pathdocker-compose.yml
File metadata and controls
219 lines (209 loc) · 7.25 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
services:
# ---------------- KAFKA (KRaft mode — no Zookeeper) ----------------
# Role: Distributed message broker for real-time chat auditing and logging.
# apache/kafka:latest is the official ASF image, multi-arch (amd64 + arm64),
# runs in KRaft mode — no Zookeeper container needed.
kafka:
image: apache/kafka:latest
ports:
- "9092:9092"
environment:
# ── KRaft cluster identity ─────────────────────────────────────
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: "broker,controller"
KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka:9093"
KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
# ── Listeners ──────────────────────────────────────────────────
KAFKA_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093"
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:9092"
KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT"
# ── Reliability ────────────────────────────────────────────────
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
volumes:
- kafka-data:/var/lib/kafka/data
healthcheck:
test: ["CMD", "/opt/kafka/bin/kafka-topics.sh", "--bootstrap-server", "127.0.0.1:9092", "--list"]
interval: 15s
timeout: 10s
retries: 12
restart: always
networks:
- chatbot-net
# ---------------- KAFKA INIT (Topic Creator) ----------------
# Role: One-shot container that explicitly creates the chat_logs topic on first boot.
kafka-init:
image: apache/kafka:latest
depends_on:
kafka:
condition: service_healthy
entrypoint: ["/bin/bash", "-c"]
command:
- |
/opt/kafka/bin/kafka-topics.sh --bootstrap-server kafka:9092 --create \
--if-not-exists --topic chat_logs --partitions 1 --replication-factor 1
echo "Topic chat_logs is ready."
networks:
- chatbot-net
# ---------------- LUCENE (AI Engine) ----------------
# Role: Java microservice handling OpenNLP logic and Lucene Fuzzy Search.
# eclipse-temurin:17-jre-alpine is a multi-arch image (amd64 + arm64).
lucene:
build:
context: "./src/ai-chatbot"
ports:
- "4567:4567"
environment:
- PORT=4567
- MODELS_DIR=/app/data/models
- KB_FILE=/app/data/faq.txt
volumes:
- "./src/backend/data:/app/data"
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:4567/health"]
interval: 15s
timeout: 5s
retries: 8
restart: unless-stopped
networks:
- chatbot-net
# ---------------- BACKEND (Python/FastAPI) ----------------
# Role: The API gateway and business logic orchestrator.
# python:3.11-slim is a multi-arch image (amd64 + arm64).
backend:
build:
context: "./src/backend"
ports:
- "8000:8000"
volumes:
- "chat-logs:/app/logs"
environment:
- LUCENE_URL=http://lucene:4567
- KAFKA_BROKER=kafka:9092
- REDIS_HOST=redis
- ENABLE_TRANSLATION=1
- INTENT_MIN_CONFIDENCE=0.35
- INTENT_LOW_CONFIDENCE=0.25
- LUCENE_MIN_SCORE=2.0
depends_on:
kafka:
condition: service_healthy
lucene:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=3)"]
interval: 15s
timeout: 5s
retries: 8
restart: unless-stopped
networks:
- chatbot-net
# ---------------- REDIS (Session Store) ----------------
# Role: High-speed in-memory database for managing user sessions and states.
# redis:alpine is a multi-arch image (amd64 + arm64).
redis:
image: redis:alpine
ports:
- "6379:6379"
restart: always
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 15s
timeout: 5s
retries: 5
networks:
- chatbot-net
# ---------------- FRONTEND (React) ----------------
# Role: The User Interface layer (Instagram-style DM UI).
# node:20.10-slim and nginx:stable-alpine are both multi-arch images.
frontend:
build:
context: "./src/frontend"
ports:
- "3000:3000"
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3000/"]
interval: 15s
timeout: 5s
retries: 8
restart: unless-stopped
networks:
- chatbot-net
# ---------------- CONSUMER (Audit Worker) ----------------
# Role: Background worker that listens to Kafka and persists logs to disk.
consumer:
build:
context: "./src/backend"
command: ["python", "kafka_consumer.py"]
environment:
- KAFKA_BROKER=kafka:9092
volumes:
- "chat-logs:/app/logs"
depends_on:
kafka:
condition: service_healthy
restart: on-failure:5
networks:
- chatbot-net
# ---------------- PROMETHEUS (Metrics Collector) ----------------
# Role: Scrapes /metrics from the FastAPI backend for time-series storage.
# prom/prometheus is a multi-arch image (amd64 + arm64).
prometheus:
image: prom/prometheus:v2.51.0
ports:
- "9090:9090"
volumes:
- "./config/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro"
- prometheus-data:/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
- "--web.console.templates=/usr/share/prometheus/consoles"
- "--web.enable-lifecycle"
depends_on:
backend:
condition: service_healthy
restart: unless-stopped
networks:
- chatbot-net
# ---------------- GRAFANA (Metrics Dashboard) ----------------
# Role: Visualises Prometheus metrics with pre-loaded dashboards.
# grafana/grafana is a multi-arch image (amd64 + arm64).
grafana:
image: grafana/grafana:10.4.0
ports:
- "3001:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=chatbot123
- GF_USERS_ALLOW_SIGN_UP=false
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/grafana_dashboard.json
volumes:
- "./config/monitoring/grafana_datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml:ro"
- "./config/monitoring/grafana_dashboards.yml:/etc/grafana/provisioning/dashboards/dashboards.yml:ro"
- "./config/monitoring/grafana_dashboard.json:/etc/grafana/provisioning/dashboards/grafana_dashboard.json:ro"
- grafana-data:/var/lib/grafana
depends_on:
- prometheus
restart: unless-stopped
networks:
- chatbot-net
# ---------------- NETWORKS ----------------
networks:
chatbot-net:
driver: bridge
# ---------------- VOLUMES ----------------
volumes:
chat-logs:
kafka-data:
prometheus-data:
grafana-data: