-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
397 lines (381 loc) · 10.7 KB
/
docker-compose.yml
File metadata and controls
397 lines (381 loc) · 10.7 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
services:
# Invoice API Service (Existing)
invoice-api:
build: ./api
hostname: invoice-api
container_name: invoice-api
environment:
- API_HOST=0.0.0.0
- API_PORT=8000
- KAFKA_BOOTSTRAP_SERVERS=broker:29092
ports:
- "8000:8000"
deploy:
resources:
limits:
memory: 2G
cpus: '1.0'
reservations:
memory: 1G
cpus: '0.5'
depends_on:
broker:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
networks:
- invoice-network
restart: unless-stopped
# Invoice Generator Service (Existing)
invoice-generator:
build: ./generator
hostname: invoice-generator
container_name: invoice-generator
depends_on:
- invoice-api
environment:
- API_ENDPOINT=http://invoice-api:8000/invoices
- GENERATION_RATE=50
- GENERATION_DURATION=0 # 0 = unlimited
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
networks:
- invoice-network
restart: unless-stopped
command: ["python", "invoice_generator.py", "--rate=50", "--api-endpoint=http://invoice-api:8000/invoices"]
# Zookeeper for Kafka
zookeeper:
image: confluentinc/cp-zookeeper:7.4.0
hostname: zookeeper
container_name: invoice-zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
volumes:
- zookeeper-data:/var/lib/zookeeper/data
- zookeeper-logs:/var/lib/zookeeper/log
healthcheck:
test: ["CMD", "bash", "-c", "echo 'ruok' | nc localhost 2181"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
networks:
- invoice-network
# Kafka Broker
broker:
image: confluentinc/cp-server:7.4.0
hostname: broker
container_name: invoice-broker
depends_on:
zookeeper:
condition: service_healthy
ports:
- "9092:9092"
- "9101:9101"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
KAFKA_CONFLUENT_BALANCER_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_JMX_PORT: 9101
KAFKA_JMX_HOSTNAME: localhost
KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://schema-registry:8081
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:29092
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
CONFLUENT_METRICS_ENABLE: 'true'
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'
# Performance tuning for invoice streaming
KAFKA_NUM_PARTITIONS: 6
KAFKA_DEFAULT_REPLICATION_FACTOR: 1
KAFKA_LOG_RETENTION_HOURS: 168 # 7 days
KAFKA_LOG_SEGMENT_BYTES: 1073741824 # 1GB
volumes:
- kafka-data:/var/lib/kafka/data
healthcheck:
test: ["CMD", "kafka-topics", "--bootstrap-server", "localhost:9092", "--list"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 4G
cpus: '1.0'
networks:
- invoice-network
# Initialize Kafka topics for Invoice Streaming
kafka-setup:
image: confluentinc/cp-kafka:7.4.0
container_name: invoice-kafka-setup
depends_on:
broker:
condition: service_healthy
command: |
bash -c "
echo 'Creating simple invoice streaming topic...';
kafka-topics --create --if-not-exists --bootstrap-server broker:29092 --topic invoice-stream --partitions 6 --replication-factor 1;
echo 'Single topic created: invoice-stream';
kafka-topics --list --bootstrap-server broker:29092;
"
networks:
- invoice-network
# Schema Registry for data governance
schema-registry:
image: confluentinc/cp-schema-registry:7.4.0
hostname: schema-registry
container_name: invoice-schema-registry
depends_on:
broker:
condition: service_healthy
ports:
- "8081:8081"
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'broker:29092'
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081/subjects"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
networks:
- invoice-network
# Kafka UI for monitoring
kafka-ui:
image: provectuslabs/kafka-ui:v0.7.2
container_name: invoice-kafka-ui
depends_on:
broker:
condition: service_healthy
ports:
- "8080:8080"
environment:
KAFKA_CLUSTERS_0_NAME: invoice-cluster
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: broker:29092
KAFKA_CLUSTERS_0_JMXPORT: 9101
KAFKA_CLUSTERS_0_SCHEMAREGISTRY: http://schema-registry:8081
DYNAMIC_CONFIG_ENABLED: true
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
networks:
- invoice-network
kafka-bridge:
build: ./kafka_bridge
hostname: kafka-bridge
container_name: kafka-bridge
depends_on:
invoice-api:
condition: service_healthy
broker:
condition: service_healthy
environment:
- API_URL=http://invoice-api:8000/invoices
- KAFKA_SERVERS=broker:29092
- KAFKA_TOPIC=invoice-stream
- POLL_INTERVAL=5
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
networks:
- invoice-network
restart: unless-stopped
# MongoDB Database
mongodb:
image: mongo:7.0
hostname: mongodb
container_name: mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123
MONGO_INITDB_DATABASE: invoices
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
- ./config/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
deploy:
resources:
limits:
memory: 4G
cpus: '1.0'
networks:
- invoice-network
restart: unless-stopped
# MongoDB Web UI (Simple and Reliable)
mongo-express:
image: mongo-express:1.0.2
hostname: mongo-express
container_name: mongo-express
depends_on:
- mongodb
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: password123
ME_CONFIG_MONGODB_URL: mongodb://admin:password123@mongodb:27017/
ME_CONFIG_BASICAUTH_USERNAME: mongouser
ME_CONFIG_BASICAUTH_PASSWORD: mongopass
ME_CONFIG_MONGODB_SERVER: mongodb
ports:
- "8084:8081"
networks:
- invoice-network
restart: unless-stopped
# Spark Master - for Invoice Processing
spark-master:
build:
context: .
dockerfile: Dockerfile.spark
hostname: spark-master
container_name: invoice-spark-master
ports:
- "8090:8080" # Spark Master Web UI
- "7077:7077" # Spark Master port
- "6066:6066" # Spark Master REST port
environment:
- SPARK_MODE=master
- SPARK_RPC_AUTHENTICATION_ENABLED=no
- SPARK_RPC_ENCRYPTION_ENABLED=no
- SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
- SPARK_SSL_ENABLED=no
- SPARK_USER=spark
- SPARK_MASTER_OPTS=-Dspark.deploy.defaultCores=2
volumes:
- ./spark-apps:/opt/spark-apps
- ./spark-data:/opt/spark-data
- ./spark-logs:/opt/spark/logs
- ./jars:/opt/spark/jars/extra
healthcheck:
test: ["CMD-SHELL", "pgrep -f 'org.apache.spark.deploy.master.Master' || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
networks:
- invoice-network
restart: unless-stopped
# Spark Worker 1
spark-worker-1:
build:
context: .
dockerfile: Dockerfile.spark
hostname: spark-worker-1
container_name: invoice-spark-worker-1
ports:
- "8091:8081" # Worker Web UI
environment:
- SPARK_MODE=worker
- SPARK_MASTER_URL=spark://spark-master:7077
- SPARK_WORKER_MEMORY=4G
- SPARK_WORKER_CORES=2
- SPARK_RPC_AUTHENTICATION_ENABLED=no
- SPARK_RPC_ENCRYPTION_ENABLED=no
- SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
- SPARK_SSL_ENABLED=no
- SPARK_USER=spark
- SPARK_WORKER_OPTS=-Dspark.worker.cleanup.enabled=true
volumes:
- ./spark-apps:/opt/spark-apps
- ./spark-data:/opt/spark-data
- ./spark-logs:/opt/spark/logs
- ./jars:/opt/spark/jars/extra
depends_on:
spark-master:
condition: service_healthy
networks:
- invoice-network
restart: unless-stopped
# Spark Streaming Application - Runs Continuously
spark-streaming:
build:
context: .
dockerfile: Dockerfile.spark
hostname: spark-streaming
container_name: invoice-spark-streaming
depends_on:
spark-master:
condition: service_healthy
mongodb:
condition: service_started
broker:
condition: service_healthy
environment:
- SPARK_MASTER_URL=spark://spark-master:7077
- SPARK_APPLICATION_PYTHON_LOCATION=/opt/spark-apps/invoice_processor.py
volumes:
- ./spark-apps:/opt/spark-apps
- ./spark-data:/opt/spark-data
- ./spark-logs:/opt/spark/logs
- ./jars:/opt/spark/jars/extra
command: >
spark-submit
--master spark://spark-master:7077
--packages org.mongodb.spark:mongo-spark-connector_2.12:10.3.0,org.apache.spark:spark-sql-kafka-0-10_2.12:3.5.0
--driver-memory 1g
--executor-memory 1g
/opt/spark-apps/invoice_processor.py
deploy:
resources:
limits:
memory: 2G
cpus: '1.0'
networks:
- invoice-network
restart: unless-stopped
powerbi-api:
build:
context: ./powerbi-api
dockerfile: Dockerfile
ports:
- "5000:5000"
depends_on:
- mongodb
networks:
- invoice-network
environment:
- MONGO_HOST=mongodb
volumes:
zookeeper-data:
zookeeper-logs:
kafka-data:
mongodb_data:
networks:
invoice-network:
driver: bridge