-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
105 lines (97 loc) · 3.78 KB
/
docker-compose.yml
File metadata and controls
105 lines (97 loc) · 3.78 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
# ============================================================
# Phase 2 — Kafka KRaft Single-Broker (No Zookeeper)
# Phase 3 — Adds PostgreSQL 16 for alert persistence
# ============================================================
#
# Services:
# kafka — single broker, KRaft mode, exposed on localhost:9092
# postgres — PostgreSQL 16, exposed on localhost:5432 (Phase 3+)
#
# Usage:
# docker compose up -d # start all services
# docker compose down # stop and remove containers
# docker compose logs -f kafka # tail broker logs
# docker compose logs -f postgres # tail PostgreSQL logs
#
# Topic auto-creation is ON (auto.create.topics.enable=true).
# The 'market-trades' topic is created automatically on first produce.
# Alert topics 'wash-alerts' and 'pump-dump-alerts' are also auto-created.
#
# PostgreSQL:
# Database: surveillance
# User: surveillance
# Password: surveillance_local (dev only — override via PG_PASSWORD env var)
#
# To connect via psql:
# psql -h localhost -p 5432 -U surveillance -d surveillance
#
# To manually create topics:
# docker exec -it kafka kafka-topics.sh \
# --bootstrap-server localhost:9092 \
# --create --topic market-trades \
# --partitions 3 --replication-factor 1
# ============================================================
services:
kafka:
image: apache/kafka:3.7.0
container_name: kafka
hostname: kafka
ports:
- "9092:9092" # external (host) access
- "9093:9093" # KRaft controller port (internal)
environment:
# ---- KRaft identity ----
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka:9093"
# ---- Listeners ----
# PLAINTEXT → broker-to-broker + Spark Structured Streaming (inside Docker network)
# EXTERNAL → host machine access (localhost:9092)
# CONTROLLER → KRaft controller traffic
KAFKA_LISTENERS: "PLAINTEXT://kafka:29092,EXTERNAL://0.0.0.0:9092,CONTROLLER://kafka:9093"
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:29092,EXTERNAL://localhost:9092"
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT"
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
# ---- Performance & reliability ----
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # single broker → RF=1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_LOG_RETENTION_HOURS: 1 # keep 1h of data (dev mode)
KAFKA_LOG_SEGMENT_BYTES: 10485760 # 10 MB segments
KAFKA_NUM_PARTITIONS: 3 # 3 partitions for market-trades topic
# ---- Cluster ID (KRaft requires a stable UUID) ----
CLUSTER_ID: "MkU3OEVBNTcwNTJENDM2Qk"
volumes:
- kafka_data:/var/lib/kafka/data
healthcheck:
test: ["CMD", "/opt/kafka/bin/kafka-broker-api-versions.sh", "--bootstrap-server", "localhost:9092"]
interval: 10s
timeout: 10s
retries: 10
start_period: 30s
# ---- PostgreSQL 16 (Phase 3+) ----
postgres:
image: postgres:16-alpine
container_name: surveillance-postgres
hostname: postgres
ports:
- "5432:5432"
environment:
POSTGRES_DB: surveillance
POSTGRES_USER: surveillance
POSTGRES_PASSWORD: surveillance_local
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U surveillance -d surveillance"]
interval: 5s
timeout: 5s
retries: 10
start_period: 10s
volumes:
kafka_data:
driver: local
pgdata:
driver: local