-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.infra.yml
More file actions
195 lines (178 loc) · 7.68 KB
/
docker-compose.infra.yml
File metadata and controls
195 lines (178 loc) · 7.68 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
# docker-compose.infra.yml
# Phase 1: Infrastructure Foundation — Redis + Kafka (KRaft mode, no ZooKeeper)
#
# Usage:
# docker compose -f docker-compose.infra.yml up -d
# docker compose -f docker-compose.infra.yml down -v # tear down with volumes
#
# Version Matrix (as of Feb 2026):
# - Redis: 7.4.x (latest stable)
# - Kafka: apache/kafka:latest (official Apache image, KRaft mode)
# - Kafka UI: latest (optional, for visual inspection)
#
# NOTE: Bitnami Kafka images are no longer freely available on Docker Hub
# (moved behind Broadcom paywall Sep 2025). We use the official
# Apache Kafka image instead.
name: apollo-subs-infra
networks:
apollo-subs-net:
driver: bridge
volumes:
redis-data:
kafka-data:
services:
# ──────────────────────────────────────────────────────────
# Redis 7.4 — Subscription state store (callback URLs, TTLs, verifiers)
# ──────────────────────────────────────────────────────────
redis:
image: redis:7.4-alpine
container_name: redis
hostname: redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
networks:
- apollo-subs-net
command: >
redis-server
--appendonly yes
--maxmemory 256mb
--maxmemory-policy allkeys-lru
--save 60 1000
--loglevel notice
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
start_period: 5s
restart: unless-stopped
# ──────────────────────────────────────────────────────────
# Kafka (Official Apache image) — KRaft combined mode
# Image: apache/kafka (available since Kafka 3.7+, currently 4.1.x)
# No ZooKeeper needed — uses built-in KRaft consensus
#
# Env var convention: KAFKA_ prefix + config name with dots→underscores
# e.g. num.partitions → KAFKA_NUM_PARTITIONS
# ──────────────────────────────────────────────────────────
kafka:
image: apache/kafka:latest
container_name: kafka
hostname: kafka
ports:
- "9092:9092" # External (host) listener
volumes:
- kafka-data:/tmp/kraft-combined-logs
networks:
- apollo-subs-net
environment:
# ── KRaft Combined Mode (broker + controller in one process) ──
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
# ── Listener Configuration ──
# INTERNAL → Docker-internal communication (subgraphs, other containers)
# EXTERNAL → Host machine access (for local dev tooling, kafka-init)
# CONTROLLER → KRaft consensus (internal only)
KAFKA_LISTENERS: INTERNAL://:19092,EXTERNAL://:9092,CONTROLLER://:9093
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:19092,EXTERNAL://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
# ── Cluster ID (required for KRaft) ──
CLUSTER_ID: apollo-subs-kafka-cluster-01
# ── Topic Defaults ──
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
KAFKA_NUM_PARTITIONS: 3
KAFKA_DEFAULT_REPLICATION_FACTOR: 1
KAFKA_MIN_INSYNC_REPLICAS: 1
KAFKA_LOG_RETENTION_HOURS: 24
# ── Performance Tuning ──
KAFKA_MESSAGE_MAX_BYTES: 1048576
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
healthcheck:
test: >
/opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list || exit 1
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
restart: unless-stopped
# ──────────────────────────────────────────────────────────
# Kafka Topic Initializer — Creates required topics on startup
# Runs once and exits after topics are created
# ──────────────────────────────────────────────────────────
kafka-init:
image: apache/kafka:latest
container_name: kafka-init
networks:
- apollo-subs-net
depends_on:
kafka:
condition: service_healthy
entrypoint: ["/bin/bash", "-c"]
command:
- |
echo "🚀 Creating Kafka topics..."
# notification-events: Main subscription event topic
# 3 partitions to support 2+ subgraph consumer instances
/opt/kafka/bin/kafka-topics.sh --create \
--if-not-exists \
--bootstrap-server kafka:19092 \
--topic notification-events \
--partitions 3 \
--replication-factor 1 \
--config retention.ms=86400000 \
--config cleanup.policy=delete
# system-alerts: Broadcast topic for system-wide alerts
# Single partition — all consumers receive all messages
/opt/kafka/bin/kafka-topics.sh --create \
--if-not-exists \
--bootstrap-server kafka:19092 \
--topic system-alerts \
--partitions 1 \
--replication-factor 1 \
--config retention.ms=86400000 \
--config cleanup.policy=delete
# order-status-changed: Consumed by the Orders subgraph (Redis-backed architecture).
# Partitioned by orderId key — same order always hits the same partition.
# Multiple subgraph pods in the same consumer group share partitions automatically.
/opt/kafka/bin/kafka-topics.sh --create \
--if-not-exists \
--bootstrap-server kafka:19092 \
--topic order-status-changed \
--partitions 3 \
--replication-factor 1 \
--config retention.ms=86400000 \
--config cleanup.policy=delete
echo ""
echo "✅ Topics created successfully:"
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server kafka:19092
echo ""
echo "📊 Topic details:"
/opt/kafka/bin/kafka-topics.sh --describe --bootstrap-server kafka:19092 --topic notification-events
/opt/kafka/bin/kafka-topics.sh --describe --bootstrap-server kafka:19092 --topic system-alerts
/opt/kafka/bin/kafka-topics.sh --describe --bootstrap-server kafka:19092 --topic order-status-changed
# ──────────────────────────────────────────────────────────
# Kafka UI — Optional visual inspection tool
# Access at http://localhost:8080
# ──────────────────────────────────────────────────────────
kafka-ui:
image: provectuslabs/kafka-ui:latest
container_name: kafka-ui
ports:
- "8080:8080"
networks:
- apollo-subs-net
depends_on:
kafka:
condition: service_healthy
environment:
- KAFKA_CLUSTERS_0_NAME=apollo-subs-local
- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:19092
- DYNAMIC_CONFIG_ENABLED=true
restart: unless-stopped