-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
286 lines (270 loc) · 8.88 KB
/
docker-compose.yml
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
version: '3.8'
services:
postgres_source:
image: postgres:12.19
environment:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
ports:
- "5433:5432"
command:
- "postgres"
- "-c"
- "wal_level=logical"
- "-c"
- "max_wal_senders=10"
- "-c"
- "max_replication_slots=4"
- "-c"
- "wal_sender_timeout=0"
- "-c"
- "wal_writer_delay=1ms"
- "-c"
- "wal_writer_flush_after=32kB"
- "-c"
- "max_wal_size=4GB"
volumes:
- pg_source_data:/var/lib/postgresql/data
- ./scripts/init_replication.sh:/docker-entrypoint-initdb.d/init_replication.sh
healthcheck:
test: ["CMD-SHELL", "pg_isready -U testuser -d testdb"]
interval: 10s
timeout: 5s
retries: 5
postgres_source_ro_1:
image: postgres:12.19
environment:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
PGPASSWORD: testpass
ports:
- "5435:5432"
volumes:
- pg_source_ro_1_data:/var/lib/postgresql/data
depends_on:
postgres_source:
condition: service_healthy
command: |
bash -c '
pg_basebackup -h postgres_source -p 5432 -U testuser -D /var/lib/postgresql/data -Fp -Xs -P -R
echo "hot_standby = on" >> /var/lib/postgresql/data/postgresql.auto.conf
exec docker-entrypoint.sh postgres
'
postgres_source_ro_2:
image: postgres:12.19
environment:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
PGPASSWORD: testpass
ports:
- "5436:5432"
volumes:
- pg_source_ro_2_data:/var/lib/postgresql/data
depends_on:
postgres_source:
condition: service_healthy
command: |
bash -c '
pg_basebackup -h postgres_source -p 5432 -U testuser -D /var/lib/postgresql/data -Fp -Xs -P -R
echo "hot_standby = on" >> /var/lib/postgresql/data/postgresql.auto.conf
exec docker-entrypoint.sh postgres
'
postgres_target:
image: postgres:12.19
environment:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
ports:
- "5434:5432"
volumes:
- pg_target_data:/var/lib/postgresql/data
- ./scripts/upgrade_pg.sh:/upgrade_pg.sh # Mount upgrade script
entrypoint: []
command: |
bash -c "
docker-entrypoint.sh postgres \
-c 'wal_level=logical' \
-c 'max_wal_senders=10' \
-c 'max_replication_slots=4' \
-c 'wal_sender_timeout=0' \
-c 'wal_writer_delay=1ms' \
-c 'wal_writer_flush_after=32kB' \
-c 'max_wal_size=4GB' &
while true; do sleep 86400; done
"
postgres_target_ro_1:
image: postgres:15
user: postgres
environment:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
PGPASSWORD: testpass
ports:
- "5437:5432"
volumes:
- pg_target_ro_1_data:/var/lib/postgresql/data
depends_on:
- postgres_target
command: |
bash -c '
while true; do
echo "Running version check..."
if psql --host=postgres_target --port=5432 --username=testuser --dbname=testdb --no-align --tuples-only --command="SELECT version()" | grep -q "PostgreSQL 15"; then
echo "PostgreSQL 15 detected, starting replication..."
pg_basebackup -h postgres_target -p 5432 -U testuser -D /var/lib/postgresql/data -Fp -Xs -P -R
echo "hot_standby = on" >> /var/lib/postgresql/data/postgresql.auto.conf
exec docker-entrypoint.sh postgres
fi
echo "Not PostgreSQL 15, waiting 5 seconds..."
sleep 5
done'
postgres_target_ro_2:
image: postgres:15
user: postgres
environment:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
PGPASSWORD: testpass
ports:
- "5438:5432"
volumes:
- pg_target_ro_2_data:/var/lib/postgresql/data
depends_on:
- postgres_target
command: |
bash -c '
while true; do
echo "Running version check..."
if psql --host=postgres_target --port=5432 --username=testuser --dbname=testdb --no-align --tuples-only --command="SELECT version()" | grep -q "PostgreSQL 15"; then
echo "PostgreSQL 15 detected, starting replication..."
pg_basebackup -h postgres_target -p 5432 -U testuser -D /var/lib/postgresql/data -Fp -Xs -P -R
echo "hot_standby = on" >> /var/lib/postgresql/data/postgresql.auto.conf
exec docker-entrypoint.sh postgres
fi
echo "Not PostgreSQL 15, waiting 5 seconds..."
sleep 5
done'
pgbouncer:
image: edoburu/pgbouncer:v1.23.1-p2
volumes:
- ./configs/pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini
- ./configs/pgbouncer_new.ini:/etc/pgbouncer/pgbouncer_new.ini
- ./configs/userlist.txt:/etc/pgbouncer/userlist.txt
command: ["/usr/bin/pgbouncer", "/etc/pgbouncer/pgbouncer.ini"]
ports:
- "6433:6432"
depends_on:
postgres_source:
condition: service_healthy
zookeeper:
image: confluentinc/cp-zookeeper:7.4.0
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"
kafka:
image: confluentinc/cp-kafka:7.4.0
depends_on:
- zookeeper
ports:
- "9092:9092"
- "9101:9101"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,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_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_JMX_PORT: 9101
KAFKA_JMX_HOSTNAME: localhost
KAFKA_PROCESS_ROLES: 'broker,controller'
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka:29093'
KAFKA_LISTENERS: 'PLAINTEXT://kafka:29092,CONTROLLER://kafka:29093,PLAINTEXT_HOST://0.0.0.0:9092'
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT'
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
# Replace CLUSTER_ID with a unique base64 UUID using "bin/kafka-storage.sh random-uuid"
# See https://docs.confluent.io/kafka/operations-tools/kafka-tools.html#kafka-storage-sh
CLUSTER_ID: 'MkU3OEVBNTcwNTJENDM2Qk'
KAFKA_MESSAGE_MAX_BYTES: 1000000
KAFKA_REPLICA_FETCH_MAX_BYTES: 1000000
KAFKA_NUM_PARTITIONS: 1
KAFKA_LOG_FLUSH_INTERVAL_MESSAGES: 1
KAFKA_LOG_FLUSH_INTERVAL_MS: 100
kafka-connect-cdc:
image: debezium/connect:2.7.2.Final
depends_on:
- kafka
- postgres_source
- postgres_target
ports:
- "8083:8083"
environment:
BOOTSTRAP_SERVERS: kafka:29092
GROUP_ID: 1
CONFIG_STORAGE_TOPIC: connect_configs_cdc
OFFSET_STORAGE_TOPIC: connect_offsets_cdc
STATUS_STORAGE_TOPIC: connect_statuses_cdc
KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_KEY_CONVERTER_SCHEMAS_ENABLE: "false"
CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE: "false"
kafka-connect-outbox:
image: debezium/connect:2.7.2.Final
depends_on:
- kafka
- postgres_source
- postgres_target
ports:
- "8084:8083"
environment:
BOOTSTRAP_SERVERS: kafka:29092
GROUP_ID: 2 # Different group ID
CONFIG_STORAGE_TOPIC: connect_configs_outbx
OFFSET_STORAGE_TOPIC: connect_offsets_outbx
STATUS_STORAGE_TOPIC: connect_statuses_outbx
KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_KEY_CONVERTER_SCHEMAS_ENABLE: "false"
CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE: "false"
elixir_test_app:
build:
context: ./elixir_app
dockerfile: ../docker/Dockerfile
environment:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
PGBOUNCER_HOST: pgbouncer
PGBOUNCER_PORT: 6432
depends_on:
- pgbouncer
control-center:
image: confluentinc/cp-enterprise-control-center:7.6.0
hostname: control-center
container_name: control-center
depends_on:
- kafka
ports:
- "9021:9021"
environment:
CONTROL_CENTER_BOOTSTRAP_SERVERS: 'kafka:29092'
CONTROL_CENTER_CONNECT_CONNECT-DEFAULT_CLUSTER: 'kafka-connect-cdc:8083'
CONTROL_CENTER_CONNECT_CONNECT-SECONDARY_CLUSTER: 'kafka-connect-outbox:8083'
CONTROL_CENTER_CONNECT_HEALTHCHECK_ENDPOINT: '/connectors'
CONTROL_CENTER_REPLICATION_FACTOR: 1
CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS: 1
CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS: 1
CONFLUENT_METRICS_TOPIC_REPLICATION: 1
PORT: 9021
volumes:
pg_source_data:
pg_source_ro_1_data:
pg_source_ro_2_data:
pg_target_ro_1_data:
pg_target_ro_2_data:
pg_target_data: