-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathdocker-compose-scalable.yml
More file actions
274 lines (264 loc) · 7.75 KB
/
docker-compose-scalable.yml
File metadata and controls
274 lines (264 loc) · 7.75 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
264
265
266
267
268
269
270
271
272
273
274
version: '3.8'
services:
# PostgreSQL Master (Primary) Database
postgres-master:
image: postgres:15-alpine
container_name: vesting-vault-master
restart: unless-stopped
environment:
POSTGRES_DB: vesting_vault
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_REPLICATION_USER: replicator
POSTGRES_REPLICATION_PASSWORD: replicator_password
ports:
- "5432:5432"
volumes:
- postgres_master_data:/var/lib/postgresql/data
- ./database/init:/docker-entrypoint-initdb.d
- ./database/master-config/postgresql.conf:/etc/postgresql/postgresql.conf
- ./database/master-config/pg_hba.conf:/etc/postgresql/pg_hba.conf
networks:
- vesting-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d vesting_vault"]
interval: 10s
timeout: 5s
retries: 5
# PostgreSQL Read Replica 1
postgres-replica-1:
image: postgres:15-alpine
container_name: vesting-vault-replica-1
restart: unless-stopped
environment:
POSTGRES_DB: vesting_vault
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
PGUSER: postgres
POSTGRES_MASTER_SERVICE: postgres-master
POSTGRES_REPLICATION_USER: replicator
POSTGRES_REPLICATION_PASSWORD: replicator_password
ports:
- "5433:5432"
volumes:
- postgres_replica_1_data:/var/lib/postgresql/data
- ./database/replica-config/postgresql.conf:/etc/postgresql/postgresql.conf
- ./database/replica-config/pg_hba.conf:/etc/postgresql/pg_hba.conf
- ./database/replica-setup/setup-replica.sh:/docker-entrypoint-initdb.d/setup-replica.sh
networks:
- vesting-network
depends_on:
postgres-master:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d vesting_vault"]
interval: 10s
timeout: 5s
retries: 5
# PostgreSQL Read Replica 2
postgres-replica-2:
image: postgres:15-alpine
container_name: vesting-vault-replica-2
restart: unless-stopped
environment:
POSTGRES_DB: vesting_vault
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
PGUSER: postgres
POSTGRES_MASTER_SERVICE: postgres-master
POSTGRES_REPLICATION_USER: replicator
POSTGRES_REPLICATION_PASSWORD: replicator_password
ports:
- "5434:5432"
volumes:
- postgres_replica_2_data:/var/lib/postgresql/data
- ./database/replica-config/postgresql.conf:/etc/postgresql/postgresql.conf
- ./database/replica-config/pg_hba.conf:/etc/postgresql/pg_hba.conf
- ./database/replica-setup/setup-replica.sh:/docker-entrypoint-initdb.d/setup-replica.sh
networks:
- vesting-network
depends_on:
postgres-master:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d vesting_vault"]
interval: 10s
timeout: 5s
retries: 5
# PgBouncer for Write Operations (Master)
pgbouncer-write:
image: pgbouncer/pgbouncer:latest
container_name: vesting-vault-pgbouncer-write
restart: unless-stopped
environment:
DATABASES_HOST: postgres-master
DATABASES_PORT: 5432
DATABASES_USER: postgres
DATABASES_PASSWORD: password
DATABASES_DBNAME: vesting_vault
POOL_MODE: transaction
MAX_CLIENT_CONN: 200
DEFAULT_POOL_SIZE: 20
MIN_POOL_SIZE: 5
RESERVE_POOL_SIZE: 5
RESERVE_POOL_TIMEOUT: 5
SERVER_RESET_QUERY: DISCARD ALL
ADMIN_USERS: postgres
STATS_USERS: postgres
ports:
- "6432:6432"
networks:
- vesting-network
depends_on:
postgres-master:
condition: service_healthy
healthcheck:
test: ["CMD", "pg_isready", "-h", "localhost", "-p", "6432"]
interval: 10s
timeout: 5s
retries: 5
# PgBouncer for Read Operations (Replicas)
pgbouncer-read:
image: pgbouncer/pgbouncer:latest
container_name: vesting-vault-pgbouncer-read
restart: unless-stopped
environment:
DATABASES_HOST: postgres-replica-1,postgres-replica-2
DATABASES_PORT: 5432
DATABASES_USER: postgres
DATABASES_PASSWORD: password
DATABASES_DBNAME: vesting_vault
POOL_MODE: transaction
MAX_CLIENT_CONN: 400
DEFAULT_POOL_SIZE: 40
MIN_POOL_SIZE: 10
RESERVE_POOL_SIZE: 10
RESERVE_POOL_TIMEOUT: 5
SERVER_RESET_QUERY: DISCARD ALL
ADMIN_USERS: postgres
STATS_USERS: postgres
CLIENT_TLS_SSLMODE: disable
ports:
- "6433:6432"
networks:
- vesting-network
depends_on:
postgres-replica-1:
condition: service_healthy
postgres-replica-2:
condition: service_healthy
healthcheck:
test: ["CMD", "pg_isready", "-h", "localhost", "-p", "6432"]
interval: 10s
timeout: 5s
retries: 5
# Backend API
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: vesting-vault-backend
restart: unless-stopped
environment:
NODE_ENV: development
PORT: 3000
# Write database (master)
DB_WRITE_HOST: pgbouncer-write
DB_WRITE_PORT: 6432
DB_WRITE_NAME: vesting_vault
DB_WRITE_USER: postgres
DB_WRITE_PASSWORD: password
# Read database (replicas)
DB_READ_HOST: pgbouncer-read
DB_READ_PORT: 6432
DB_READ_NAME: vesting_vault
DB_READ_USER: postgres
DB_READ_PASSWORD: password
# Legacy compatibility
DB_HOST: pgbouncer-write
DB_PORT: 6432
DB_NAME: vesting_vault
DB_USER: postgres
DB_PASSWORD: password
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
STELLAR_NETWORK_PASSPHRASE: ${STELLAR_NETWORK_PASSPHRASE:-"Test SDF Network ; September 2015"}
# Database cluster settings
DB_CLUSTER_MODE: true
DB_REPLICA_LAG_THRESHOLD: 1000
ports:
- "3000:3000"
depends_on:
pgbouncer-write:
condition: service_healthy
pgbouncer-read:
condition: service_healthy
networks:
- vesting-network
volumes:
- ./backend:/app
- /app/node_modules
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Redis (for caching/sessions)
redis:
image: redis:7-alpine
container_name: vesting-vault-redis
restart: unless-stopped
ports:
- "6379:6379"
volumes:
- redis_data:/data
networks:
- vesting-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 3
# Database Health Monitor
db-health-monitor:
build:
context: ./database/health-monitor
dockerfile: Dockerfile
container_name: vesting-vault-db-health-monitor
restart: unless-stopped
environment:
POSTGRES_MASTER_HOST: postgres-master
POSTGRES_MASTER_PORT: 5432
POSTGRES_REPLICA_HOSTS: postgres-replica-1:5432,postgres-replica-2:5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: vesting_vault
REDIS_HOST: redis
REDIS_PORT: 6379
CHECK_INTERVAL: 30
LAG_THRESHOLD: 1000
networks:
- vesting-network
depends_on:
postgres-master:
condition: service_healthy
postgres-replica-1:
condition: service_healthy
postgres-replica-2:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- ./logs:/app/logs
volumes:
postgres_master_data:
driver: local
postgres_replica_1_data:
driver: local
postgres_replica_2_data:
driver: local
redis_data:
driver: local
networks:
vesting-network:
driver: bridge