|
| 1 | +version: '3.8' |
| 2 | + |
| 3 | +services: |
| 4 | + # PostgreSQL primary node |
| 5 | + postgres-primary: |
| 6 | + build: |
| 7 | + context: . |
| 8 | + dockerfile: docker/Dockerfile.postgres |
| 9 | + container_name: pgraft-primary |
| 10 | + environment: |
| 11 | + POSTGRES_DB: testdb |
| 12 | + POSTGRES_USER: postgres |
| 13 | + POSTGRES_PASSWORD: postgres |
| 14 | + PGRaft_NODE_ID: 1 |
| 15 | + PGRaft_NODE_NAME: primary |
| 16 | + PGRaft_CLUSTER_NAME: test-cluster |
| 17 | + PGRaft_RAFT_PORT: 5433 |
| 18 | + PGRaft_LOG_LEVEL: 2 |
| 19 | + ports: |
| 20 | + - "5433:5432" |
| 21 | + - "8080:8080" # ramd HTTP API |
| 22 | + volumes: |
| 23 | + - postgres_primary_data:/var/lib/postgresql/data |
| 24 | + - ./pgraft:/usr/local/share/postgresql/extension/pgraft |
| 25 | + networks: |
| 26 | + - pgraft-network |
| 27 | + command: > |
| 28 | + postgres |
| 29 | + -c shared_preload_libraries=pgraft |
| 30 | + -c pgraft.node_id=1 |
| 31 | + -c pgraft.node_name=primary |
| 32 | + -c pgraft.cluster_name=test-cluster |
| 33 | + -c pgraft.raft_port=5433 |
| 34 | + -c pgraft.log_level=2 |
| 35 | + -c wal_level=replica |
| 36 | + -c max_wal_senders=10 |
| 37 | + -c max_replication_slots=10 |
| 38 | + -c hot_standby=on |
| 39 | + healthcheck: |
| 40 | + test: ["CMD-SHELL", "pg_isready -U postgres -d testdb"] |
| 41 | + interval: 10s |
| 42 | + timeout: 5s |
| 43 | + retries: 5 |
| 44 | + |
| 45 | + # PostgreSQL standby node 1 |
| 46 | + postgres-standby1: |
| 47 | + build: |
| 48 | + context: . |
| 49 | + dockerfile: docker/Dockerfile.postgres |
| 50 | + container_name: pgraft-standby1 |
| 51 | + environment: |
| 52 | + POSTGRES_DB: testdb |
| 53 | + POSTGRES_USER: postgres |
| 54 | + POSTGRES_PASSWORD: postgres |
| 55 | + PGRaft_NODE_ID: 2 |
| 56 | + PGRaft_NODE_NAME: standby1 |
| 57 | + PGRaft_CLUSTER_NAME: test-cluster |
| 58 | + PGRaft_RAFT_PORT: 5434 |
| 59 | + PGRaft_LOG_LEVEL: 2 |
| 60 | + ports: |
| 61 | + - "5434:5432" |
| 62 | + - "8081:8080" # ramd HTTP API |
| 63 | + volumes: |
| 64 | + - postgres_standby1_data:/var/lib/postgresql/data |
| 65 | + - ./pgraft:/usr/local/share/postgresql/extension/pgraft |
| 66 | + networks: |
| 67 | + - pgraft-network |
| 68 | + depends_on: |
| 69 | + - postgres-primary |
| 70 | + command: > |
| 71 | + bash -c " |
| 72 | + until pg_basebackup -h postgres-primary -U postgres -D /var/lib/postgresql/data -R -S standby1; |
| 73 | + do echo 'Waiting for primary to be ready...'; sleep 2; done && |
| 74 | + postgres |
| 75 | + -c shared_preload_libraries=pgraft |
| 76 | + -c pgraft.node_id=2 |
| 77 | + -c pgraft.node_name=standby1 |
| 78 | + -c pgraft.cluster_name=test-cluster |
| 79 | + -c pgraft.raft_port=5434 |
| 80 | + -c pgraft.log_level=2 |
| 81 | + -c wal_level=replica |
| 82 | + -c max_wal_senders=10 |
| 83 | + -c max_replication_slots=10 |
| 84 | + -c hot_standby=on |
| 85 | + -c primary_conninfo='host=postgres-primary port=5432 user=postgres' |
| 86 | + " |
| 87 | + healthcheck: |
| 88 | + test: ["CMD-SHELL", "pg_isready -U postgres -d testdb"] |
| 89 | + interval: 10s |
| 90 | + timeout: 5s |
| 91 | + retries: 5 |
| 92 | + |
| 93 | + # PostgreSQL standby node 2 |
| 94 | + postgres-standby2: |
| 95 | + build: |
| 96 | + context: . |
| 97 | + dockerfile: docker/Dockerfile.postgres |
| 98 | + container_name: pgraft-standby2 |
| 99 | + environment: |
| 100 | + POSTGRES_DB: testdb |
| 101 | + POSTGRES_USER: postgres |
| 102 | + POSTGRES_PASSWORD: postgres |
| 103 | + PGRaft_NODE_ID: 3 |
| 104 | + PGRaft_NODE_NAME: standby2 |
| 105 | + PGRaft_CLUSTER_NAME: test-cluster |
| 106 | + PGRaft_RAFT_PORT: 5435 |
| 107 | + PGRaft_LOG_LEVEL: 2 |
| 108 | + ports: |
| 109 | + - "5435:5432" |
| 110 | + - "8082:8080" # ramd HTTP API |
| 111 | + volumes: |
| 112 | + - postgres_standby2_data:/var/lib/postgresql/data |
| 113 | + - ./pgraft:/usr/local/share/postgresql/extension/pgraft |
| 114 | + networks: |
| 115 | + - pgraft-network |
| 116 | + depends_on: |
| 117 | + - postgres-primary |
| 118 | + command: > |
| 119 | + bash -c " |
| 120 | + until pg_basebackup -h postgres-primary -U postgres -D /var/lib/postgresql/data -R -S standby2; |
| 121 | + do echo 'Waiting for primary to be ready...'; sleep 2; done && |
| 122 | + postgres |
| 123 | + -c shared_preload_libraries=pgraft |
| 124 | + -c pgraft.node_id=3 |
| 125 | + -c pgraft.node_name=standby2 |
| 126 | + -c pgraft.cluster_name=test-cluster |
| 127 | + -c pgraft.raft_port=5435 |
| 128 | + -c pgraft.log_level=2 |
| 129 | + -c wal_level=replica |
| 130 | + -c max_wal_senders=10 |
| 131 | + -c max_replication_slots=10 |
| 132 | + -c hot_standby=on |
| 133 | + -c primary_conninfo='host=postgres-primary port=5432 user=postgres' |
| 134 | + " |
| 135 | + healthcheck: |
| 136 | + test: ["CMD-SHELL", "pg_isready -U postgres -d testdb"] |
| 137 | + interval: 10s |
| 138 | + timeout: 5s |
| 139 | + retries: 5 |
| 140 | + |
| 141 | + # ramd daemon for primary |
| 142 | + ramd-primary: |
| 143 | + build: |
| 144 | + context: . |
| 145 | + dockerfile: docker/Dockerfile.ramd |
| 146 | + container_name: ramd-primary |
| 147 | + environment: |
| 148 | + RAMD_CONFIG_FILE: /etc/ramd/ramd.conf |
| 149 | + RAMD_LOG_LEVEL: INFO |
| 150 | + RAMD_HTTP_PORT: 8080 |
| 151 | + ports: |
| 152 | + - "8080:8080" |
| 153 | + volumes: |
| 154 | + - ./ramd/conf:/etc/ramd |
| 155 | + - ./ramd/logs:/var/log/ramd |
| 156 | + networks: |
| 157 | + - pgraft-network |
| 158 | + depends_on: |
| 159 | + - postgres-primary |
| 160 | + command: ["ramd", "--config", "/etc/ramd/ramd.conf", "--daemon"] |
| 161 | + |
| 162 | + # ramd daemon for standby1 |
| 163 | + ramd-standby1: |
| 164 | + build: |
| 165 | + context: . |
| 166 | + dockerfile: docker/Dockerfile.ramd |
| 167 | + container_name: ramd-standby1 |
| 168 | + environment: |
| 169 | + RAMD_CONFIG_FILE: /etc/ramd/ramd.conf |
| 170 | + RAMD_LOG_LEVEL: INFO |
| 171 | + RAMD_HTTP_PORT: 8080 |
| 172 | + ports: |
| 173 | + - "8081:8080" |
| 174 | + volumes: |
| 175 | + - ./ramd/conf:/etc/ramd |
| 176 | + - ./ramd/logs:/var/log/ramd |
| 177 | + networks: |
| 178 | + - pgraft-network |
| 179 | + depends_on: |
| 180 | + - postgres-standby1 |
| 181 | + command: ["ramd", "--config", "/etc/ramd/ramd.conf", "--daemon"] |
| 182 | + |
| 183 | + # ramd daemon for standby2 |
| 184 | + ramd-standby2: |
| 185 | + build: |
| 186 | + context: . |
| 187 | + dockerfile: docker/Dockerfile.ramd |
| 188 | + container_name: ramd-standby2 |
| 189 | + environment: |
| 190 | + RAMD_CONFIG_FILE: /etc/ramd/ramd.conf |
| 191 | + RAMD_LOG_LEVEL: INFO |
| 192 | + RAMD_HTTP_PORT: 8080 |
| 193 | + ports: |
| 194 | + - "8082:8080" |
| 195 | + volumes: |
| 196 | + - ./ramd/conf:/etc/ramd |
| 197 | + - ./ramd/logs:/var/log/ramd |
| 198 | + networks: |
| 199 | + - pgraft-network |
| 200 | + depends_on: |
| 201 | + - postgres-standby2 |
| 202 | + command: ["ramd", "--config", "/etc/ramd/ramd.conf", "--daemon"] |
| 203 | + |
| 204 | + # Monitoring and management |
| 205 | + pgraft-monitor: |
| 206 | + build: |
| 207 | + context: . |
| 208 | + dockerfile: docker/Dockerfile.monitor |
| 209 | + container_name: pgraft-monitor |
| 210 | + environment: |
| 211 | + MONITOR_INTERVAL: 30 |
| 212 | + MONITOR_TARGETS: "postgres-primary:5432,postgres-standby1:5432,postgres-standby2:5432" |
| 213 | + ports: |
| 214 | + - "3000:3000" # Grafana |
| 215 | + - "9090:9090" # Prometheus |
| 216 | + volumes: |
| 217 | + - ./monitoring/grafana:/etc/grafana |
| 218 | + - ./monitoring/prometheus:/etc/prometheus |
| 219 | + - ./monitoring/dashboards:/var/lib/grafana/dashboards |
| 220 | + networks: |
| 221 | + - pgraft-network |
| 222 | + depends_on: |
| 223 | + - postgres-primary |
| 224 | + - postgres-standby1 |
| 225 | + - postgres-standby2 |
| 226 | + |
| 227 | +volumes: |
| 228 | + postgres_primary_data: |
| 229 | + postgres_standby1_data: |
| 230 | + postgres_standby2_data: |
| 231 | + |
| 232 | +networks: |
| 233 | + pgraft-network: |
| 234 | + driver: bridge |
| 235 | + ipam: |
| 236 | + config: |
| 237 | + - subnet: 172.20.0.0/16 |
0 commit comments