-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
263 lines (238 loc) · 8.71 KB
/
docker-compose.yml
File metadata and controls
263 lines (238 loc) · 8.71 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
version: "3.9"
# ─────────────────────────────────────────────────────────────────────────────
# SentimentPulse — docker-compose
#
# Infrastructure (Kafka, Redis) is defined here for standalone development.
# If you already have FinStream running, point KAFKA_BOOTSTRAP_SERVERS and
# REDIS_HOST at your existing containers via .env instead of starting these.
#
# Services:
# Infrastructure: zookeeper, kafka, redis, kafdrop
# Phase 2 (this PR): sentiment-ingestor
# Phase 3 (next): sentiment-classifier
# Phase 4 (next): sentiment-persistence, sentiment-api
# Phase 5 (next): sentiment-dashboard
# ─────────────────────────────────────────────────────────────────────────────
networks:
sentimentpulse:
driver: bridge
volumes:
kafka_data:
zookeeper_data:
redis_data:
timescaledb_data:
services:
# ── Infrastructure ──────────────────────────────────────────────────────────
zookeeper:
image: confluentinc/cp-zookeeper:7.6.1
container_name: sp-zookeeper
networks: [sentimentpulse]
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
volumes:
- zookeeper_data:/var/lib/zookeeper/data
healthcheck:
test: ["CMD", "echo", "ruok", "|", "nc", "localhost", "2181"]
interval: 10s
timeout: 5s
retries: 5
kafka:
image: confluentinc/cp-kafka:7.6.1
container_name: sp-kafka
networks: [sentimentpulse]
depends_on:
zookeeper:
condition: service_healthy
ports:
- "9092:9092" # host access for local development
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
volumes:
- kafka_data:/var/lib/kafka/data
healthcheck:
test: ["CMD", "kafka-broker-api-versions", "--bootstrap-server", "localhost:29092"]
interval: 15s
timeout: 10s
retries: 10
# Kafdrop — Kafka UI for verifying messages (Phase 2 exit criteria)
kafdrop:
image: obsidiandynamics/kafdrop:latest
container_name: sp-kafdrop
networks: [sentimentpulse]
depends_on:
kafka:
condition: service_healthy
ports:
- "9000:9000"
environment:
KAFKA_BROKERCONNECT: kafka:29092
JVM_OPTS: "-Xms32M -Xmx64M"
redis:
image: redis:7.2-alpine
container_name: sp-redis
networks: [sentimentpulse]
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: redis-server --appendonly yes
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
# Kafka topic initialisation — creates raw.headlines with correct partition count
kafka-init:
image: confluentinc/cp-kafka:7.6.1
container_name: sp-kafka-init
networks: [sentimentpulse]
depends_on:
kafka:
condition: service_healthy
entrypoint: ["/bin/sh", "-c"]
command: |
"
echo 'Creating Kafka topics...'
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists \
--topic raw.headlines \
--partitions 4 \
--replication-factor 1 \
--config retention.ms=86400000
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists \
--topic enriched.sentiment \
--partitions 12 \
--replication-factor 1 \
--config retention.ms=604800000
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists \
--topic sentiment.dlq \
--partitions 2 \
--replication-factor 1 \
--config retention.ms=2592000000
echo 'Topics created.'
kafka-topics --bootstrap-server kafka:29092 --list
"
restart: "no"
# ── Phase 2 — News Ingestor ─────────────────────────────────────────────────
sentiment-ingestor:
build:
context: .
dockerfile: sentiment_ingestor/Dockerfile
container_name: sp-ingestor
networks: [sentimentpulse]
depends_on:
kafka:
condition: service_healthy
redis:
condition: service_healthy
kafka-init:
condition: service_completed_successfully
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_HOST: redis
REDIS_PORT: 6379
EDGAR_USER_AGENT: "SentimentPulse dev@example.com"
GNEWS_API_KEY: "${GNEWS_API_KEY:-}" # optional — set in .env
TICKERS_CSV_PATH: /app/data/sp500_tickers.csv
restart: unless-stopped
# ── Phase 3 — Sentiment Classifier ─────────────────────────────────────────
sentiment-classifier:
build:
context: .
dockerfile: sentiment_classifier/Dockerfile
container_name: sp-classifier
networks: [sentimentpulse]
depends_on:
kafka:
condition: service_healthy
kafka-init:
condition: service_completed_successfully
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
MODEL_DIR: /app/models/finbert-finetuned
SP500_PATTERNS_PATH: /app/data/sp500_patterns.jsonl
SP500_TICKERS_CSV: /app/data/sp500_tickers.csv
MODEL_VERSION: finbert-finetuned-v1.0
PROMETHEUS_PORT: 8000
ports:
- "8000:8000" # Prometheus /metrics
restart: unless-stopped
# ── Phase 4 — TimescaleDB ────────────────────────────────────────────────────
timescaledb:
image: timescale/timescaledb:latest-pg16
container_name: sp-timescaledb
networks: [sentimentpulse]
ports:
- "5432:5432"
environment:
POSTGRES_DB: sentimentpulse
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- timescaledb_data:/var/lib/postgresql/data
- ./db/migrations/V1__create_sentiment_events.sql:/docker-entrypoint-initdb.d/V1__create_sentiment_events.sql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d sentimentpulse"]
interval: 10s
timeout: 5s
retries: 10
# ── Phase 4 — Persistence Worker ─────────────────────────────────────────────
sentiment-persistence:
build:
context: .
dockerfile: sentiment_persistence/Dockerfile
container_name: sp-persistence
networks: [sentimentpulse]
depends_on:
kafka:
condition: service_healthy
timescaledb:
condition: service_healthy
redis:
condition: service_healthy
kafka-init:
condition: service_completed_successfully
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
DATABASE_URL: postgresql://postgres:postgres@timescaledb:5432/sentimentpulse
REDIS_HOST: redis
REDIS_PORT: 6379
restart: unless-stopped
# ── Phase 4 — Sentiment API ───────────────────────────────────────────────────
sentiment-api:
build:
context: .
dockerfile: sentiment_api/Dockerfile
container_name: sp-api
networks: [sentimentpulse]
depends_on:
timescaledb:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8081:8081" # avoids conflict with FinStream API on 8080
environment:
DATABASE_URL: postgresql://postgres:postgres@timescaledb:5432/sentimentpulse
REDIS_HOST: redis
REDIS_PORT: 6379
restart: unless-stopped
# ── Phase 5 — React Dashboard ────────────────────────────────────────────────
sentiment-dashboard:
build:
context: .
dockerfile: sentiment_dashboard/Dockerfile
container_name: sp-dashboard
networks: [sentimentpulse]
depends_on:
sentiment-api:
condition: service_started
ports:
- "3001:3001"
restart: unless-stopped