Skip to content

Commit 6edeae5

Browse files
authored
[+] add test patroni cluster to docker compose (#993)
- set compose project name to "pgwatch" - add .pgpass for patroni continuous discovery - add full patroni cluster with etcd nodes and haproxy - move shell helpers to dedicated folder `/docker/scripts` - set `PGUSER` for pgwatch container
1 parent 9eb87f0 commit 6edeae5

File tree

13 files changed

+107
-10
lines changed

13 files changed

+107
-10
lines changed

docker/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
COMPOSE_PROJECT_NAME=pgwatch
2+
ENVIRONMENT=development

docker/bootstrap/.pgpass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# hostname:port:database:username:password
2+
postgres:5432:postgres:pgwatch:pgwatchadmin
3+
*:5432:postgres:postgres:postgres

docker/bootstrap/patroni.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PATRONI_RESTAPI_USERNAME=admin
2+
PATRONI_RESTAPI_PASSWORD=admin
3+
PATRONI_SUPERUSER_USERNAME=postgres
4+
PATRONI_SUPERUSER_PASSWORD=postgres
5+
PATRONI_REPLICATION_USERNAME=replicator
6+
PATRONI_REPLICATION_PASSWORD=replicate
7+
PATRONI_admin_PASSWORD=admin
8+
PATRONI_admin_OPTIONS=createdb,createrole

docker/bootstrap/pgadmin_pass

Lines changed: 0 additions & 1 deletion
This file was deleted.

docker/compose.patroni.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# before use run:
2+
# docker build https://github.com/patroni/patroni.git#master -t patroni
3+
# or set PATRONI_TEST_IMAGE env var to your custom image
4+
5+
services:
6+
etcd1: &etcd
7+
image: ${PATRONI_TEST_IMAGE:-patroni}
8+
environment:
9+
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
10+
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
11+
ETCD_INITIAL_CLUSTER: etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
12+
ETCD_INITIAL_CLUSTER_STATE: new
13+
ETCD_INITIAL_CLUSTER_TOKEN: tutorial
14+
ETCD_UNSUPPORTED_ARCH: arm64
15+
container_name: etcd1
16+
hostname: etcd1
17+
command: etcd --name etcd1 --initial-advertise-peer-urls http://etcd1:2380
18+
profiles: ["patroni"]
19+
20+
etcd2:
21+
<<: *etcd
22+
container_name: etcd2
23+
hostname: etcd2
24+
command: etcd --name etcd2 --initial-advertise-peer-urls http://etcd2:2380
25+
profiles: ["patroni"]
26+
27+
etcd3:
28+
<<: *etcd
29+
container_name: etcd3
30+
hostname: etcd3
31+
command: etcd --name etcd3 --initial-advertise-peer-urls http://etcd3:2380
32+
ports: # publish etcd client port only on one node for debugging
33+
- "2379:2379"
34+
- "2380:2380"
35+
profiles: ["patroni"]
36+
37+
haproxy:
38+
image: ${PATRONI_TEST_IMAGE:-patroni}
39+
env_file: bootstrap/patroni.env
40+
hostname: haproxy
41+
container_name: haproxy
42+
ports:
43+
- "5000:5000"
44+
- "5001:5001"
45+
command: haproxy
46+
environment: &haproxy_env
47+
ETCDCTL_ENDPOINTS: http://etcd1:2379,http://etcd2:2379,http://etcd3:2379
48+
PATRONI_ETCD3_HOSTS: "'etcd1:2379','etcd2:2379','etcd3:2379'"
49+
PATRONI_SCOPE: demo
50+
profiles: ["patroni"]
51+
52+
patroni1:
53+
image: ${PATRONI_TEST_IMAGE:-patroni}
54+
env_file: bootstrap/patroni.env
55+
hostname: patroni1
56+
container_name: patroni1
57+
environment:
58+
<<: *haproxy_env
59+
PATRONI_NAME: patroni1
60+
profiles: ["patroni"]
61+
62+
patroni2:
63+
image: ${PATRONI_TEST_IMAGE:-patroni}
64+
env_file: bootstrap/patroni.env
65+
hostname: patroni2
66+
container_name: patroni2
67+
environment:
68+
<<: *haproxy_env
69+
PATRONI_NAME: patroni2
70+
profiles: ["patroni"]
71+
72+
patroni3:
73+
image: ${PATRONI_TEST_IMAGE:-patroni}
74+
env_file: bootstrap/patroni.env
75+
hostname: patroni3
76+
container_name: patroni3
77+
environment:
78+
<<: *haproxy_env
79+
PATRONI_NAME: patroni3
80+
profiles: ["patroni"]

docker/compose.pgadmin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
PGADMIN_DEFAULT_PASSWORD: admin
88
volumes:
99
- "./bootstrap/pgadmin_servers.json:/pgadmin4/servers.json"
10-
- "./bootstrap/pgadmin_pass:/pgadmin4/pass"
10+
- "./bootstrap/.pgpass:/pgadmin4/pass"
1111
ports:
1212
- "80:80"
1313
depends_on:

docker/compose.pgwatch.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
image: cybertecpostgresql/pgwatch:latest
88
container_name: pgwatch
99
environment:
10+
PGUSER: postgres
1011
PW_SOURCES: postgresql://pgwatch@postgres:5432/pgwatch
1112
# PW_METRICS: /etc/pgwatch/metrics.yml
1213
command:
@@ -18,6 +19,7 @@ services:
1819
# - "6060:6060" # Uncomment for profiling
1920
volumes:
2021
- "../internal/metrics/metrics.yaml:/etc/pgwatch/metrics.yml"
22+
- "./bootstrap/.pgpass:/root/.pgpass:ro"
2123
depends_on:
2224
postgres:
23-
condition: service_healthy
25+
condition: service_healthy

docker/docker-compose.timescaledb.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ include:
66
- path: compose.pgwatch.yml
77
- path: compose.pgadmin.yml
88
- path: compose.prometheus.yml
9+
- path: compose.patroni.yml

docker/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ include:
55
- path: compose.grafana.yml
66
- path: compose.pgwatch.yml
77
- path: compose.pgadmin.yml
8-
- path: compose.prometheus.yml
8+
- path: compose.prometheus.yml
9+
- path: compose.patroni.yml
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
cd "$(dirname "${BASH_SOURCE[0]}")"
3+
cd "$(dirname "${BASH_SOURCE[0]}")/.."
44

55
export MSYS_NO_PATHCONV=1
66

@@ -19,5 +19,6 @@ VALUES
1919
('demo', 'postgres', 'debug', 'postgresql://pgwatch:pgwatchadmin@postgres/pgwatch'),
2020
('demo_metrics', 'postgres', 'full', 'postgresql://pgwatch:pgwatchadmin@postgres/pgwatch_metrics'),
2121
('demo_standby', 'postgres', 'full', 'postgresql://pgwatch:pgwatchadmin@postgres-standby/pgwatch'),
22+
('demo_patroni', 'patroni', 'basic', 'etcd://etcd1:2379,etcd2:2379,etcd3:2379/service/demo'),
2223
('demo_pgbouncer', 'pgbouncer', 'pgbouncer', 'postgresql://pgwatch:pgwatchadmin@pgbouncer/pgbouncer'),
2324
('demo_pgpool', 'pgpool', 'pgpool', 'postgresql://pgwatch:pgwatchadmin@pgpool/pgwatch');"

0 commit comments

Comments
 (0)