-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
132 lines (124 loc) · 4.26 KB
/
docker-compose.yml
File metadata and controls
132 lines (124 loc) · 4.26 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
version: '3.8'
services:
# --- 1. Source Database (Backend) ---
# จำลองว่าเป็น Database ของระบบหลัก (App)
postgres:
image: postgres:14-alpine
container_name: bitka-postgres
restart: always
env_file:
- .env
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: ${AUTH_DB_NAME}
ports:
- "${DB_PORT}:5432" # ปกติคือ 5432
# สำคัญ: ต้องเปิด wal_level=logical เพื่อให้ Debezium ดูดข้อมูลได้ (CDC)
command: ["postgres", "-c", "wal_level=logical"]
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- bitka-net
# --- 2. Data Platform (Streaming Core) ---
# Kafka (Redpanda) - หัวใจของการส่งข้อมูล
redpanda:
image: docker.redpanda.com/redpandadata/redpanda:v23.3.3
container_name: bitka-redpanda
ports:
- "19092:19092" # External Port: สำหรับ Python Script ในเครื่องเรา (Localhost)
- "9644:9644" # Admin Port
command:
- redpanda start
- --smp 1
- --memory 1G
- --reserve-memory 0M
- --overprovisioned
- --node-id 0
- --check=false
# Internal (9092): สำหรับ Debezium คุยกับ Redpanda ใน Docker Network
# External (19092): สำหรับ Python Script คุยกับ Redpanda จากข้างนอก
- --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
- --advertise-kafka-addr internal://redpanda:9092,external://localhost:19092
networks:
- bitka-net
# UI สำหรับดูข้อมูลใน Kafka (Optional แต่มีไว้ debug ดีมาก)
redpanda-console:
image: redpandadata/console:latest
container_name: bitka-console
ports:
- "8080:8080"
environment:
KAFKA_BROKERS: redpanda:9092
depends_on:
- redpanda
networks:
- bitka-net
# --- 3. Change Data Capture (CDC) ---
# ตัวดูดข้อมูลจาก Source DB -> Kafka
debezium:
image: quay.io/debezium/connect:latest
container_name: bitka-debezium
ports:
- "8083:8083" # API Port
environment:
BOOTSTRAP_SERVERS: redpanda:9092
GROUP_ID: 1
CONFIG_STORAGE_TOPIC: connect_configs
OFFSET_STORAGE_TOPIC: connect_offsets
STATUS_STORAGE_TOPIC: connect_statuses
KEY_CONVERTER_SCHEMAS_ENABLE: "false"
VALUE_CONVERTER_SCHEMAS_ENABLE: "false"
depends_on:
- redpanda
- postgres
networks:
- bitka-net
# Script สั้นๆ เพื่อยิง config เข้า Debezium อัตโนมัติเมื่อเริ่มระบบ
connector-init:
image: curlimages/curl:latest
container_name: bitka-connector-init
depends_on:
- debezium
networks:
- bitka-net
volumes:
- ./connector.json:/connector.json
command: >
/bin/sh -c "
echo '⏳ Waiting for Debezium to be ready...';
while ! curl -s http://debezium:8083/ > /dev/null; do
echo 'zzZ... waiting for Debezium';
sleep 5;
done;
echo '✅ Debezium is UP! Registering Connector...';
curl -i -X POST -H 'Accept:application/json' -H 'Content-Type:application/json' http://debezium:8083/connectors/ -d @/connector.json;
echo '🎉 Done! Connector registered.';
"
# --- 4. Data Warehouse (Destination) ---
# ปลายทางที่ Python Consumer จะนำข้อมูลไปหยอด
warehouse:
image: postgres:18-alpine
container_name: bitka-warehouse
restart: always
env_file:
- .env
environment:
POSTGRES_USER: ${DW_USER}
POSTGRES_PASSWORD: ${DW_PASS}
POSTGRES_DB: ${DW_DB_NAME}
ports:
# Map Port 5433 (Host) -> 5432 (Container)
# เพื่อให้ Python Script connect ผ่าน localhost:5433 ได้
- "${DW_PORT_EXTERNAL}:5432"
volumes:
- warehouse_data:/var/lib/postgresql/data
networks:
- bitka-net
volumes:
postgres_data:
warehouse_data:
networks:
bitka-net:
driver: bridge
name: ${NETWORK_NAME}