|
3 | 3 |
|
4 | 4 | [global pg_container_name=] |
5 | 5 | [global pg_host_port=54331] |
| 6 | +[global pg_pooler_host_port=64331] |
6 | 7 | [global database_url=postgresql://postgres:password@localhost:$pg_host_port/postgres?sslmode=disable] |
| 8 | +[global pooled_database_url=postgresql://postgres:password@localhost:$pg_pooler_host_port/postgres?sslmode=disable] |
7 | 9 |
|
8 | 10 | [macro setup_pg_with_name shell_name initdb_args config_opts] |
9 | 11 | [shell $shell_name] |
10 | 12 | -$fail_pattern |
| 13 | + |
| 14 | + # Create network for given contianer to be able to attach pooler |
| 15 | + !docker network ls | grep ${pg_container_name}-network || docker network create ${pg_container_name}-network |
11 | 16 |
|
12 | 17 | !docker run \ |
13 | 18 | --name $pg_container_name \ |
| 19 | + --network ${pg_container_name}-network \ |
14 | 20 | -e POSTGRES_DB=electric \ |
15 | 21 | -e POSTGRES_USER=postgres \ |
16 | 22 | -e POSTGRES_PASSWORD=password \ |
|
31 | 37 | [invoke setup_pg_with_name "pg" $initdb_args $config_opts] |
32 | 38 | [endmacro] |
33 | 39 |
|
| 40 | +[macro setup_pg_with_pooler initdb_args config_opts] |
| 41 | + [invoke setup_pg_with_name "pg" $initdb_args $config_opts] |
| 42 | + [shell "pg_pooler"] |
| 43 | + -$fail_pattern |
| 44 | + |
| 45 | + !docker run \ |
| 46 | + --name "${pg_container_name}-pooler" \ |
| 47 | + --network ${pg_container_name}-network \ |
| 48 | + -e PGBOUNCER_AUTH_TYPE=trust \ |
| 49 | + -e PGBOUNCER_DATABASE=* \ |
| 50 | + -e PGBOUNCER_POOL_MODE=transaction \ |
| 51 | + -e POSTGRESQL_HOST=$pg_container_name \ |
| 52 | + -e POSTGRESQL_DATABASE=electric \ |
| 53 | + -e POSTGRESQL_USERNAME=postgres \ |
| 54 | + -e POSTGRESQL_PASSWORD=password \ |
| 55 | + -p $pg_pooler_host_port:6432 \ |
| 56 | + bitnami/pgbouncer:latest |
| 57 | + |
| 58 | + ??LOG process up: PgBouncer |
| 59 | +[endmacro] |
| 60 | + |
34 | 61 | [macro stop_pg] |
35 | 62 | [shell pg_lifecycle] |
36 | 63 | # This timeout is needed until https://github.com/electric-sql/electric/issues/1632 is fixed. |
|
87 | 114 | [invoke setup_electric_with_env "DATABASE_URL=$database_url"] |
88 | 115 | [endmacro] |
89 | 116 |
|
| 117 | +[macro setup_electric_with_pooler] |
| 118 | + [invoke setup_electric_with_env "DATABASE_URL=$database_url ELECTRIC_QUERY_DATABASE_URL=$pooled_database_url"] |
| 119 | +[endmacro] |
| 120 | + |
90 | 121 | [macro setup_multi_tenant_electric] |
91 | 122 | [invoke setup_electric_with_env ""] |
92 | 123 | [endmacro] |
|
125 | 156 |
|
126 | 157 | [macro teardown_container container_name] |
127 | 158 | -$fail_pattern |
128 | | - !docker rm -f -v $container_name |
| 159 | + !docker rm -f -v $container_name 2>/dev/null || true |
129 | 160 | ?$PS1 |
130 | 161 | [endmacro] |
131 | 162 |
|
132 | 163 | [macro teardown] |
| 164 | + [invoke teardown_container "${pg_container_name}-pooler"] |
133 | 165 | [invoke teardown_container $pg_container_name] |
134 | 166 | !../scripts/clean_up.sh |
135 | 167 | ?$PS1 |
|
0 commit comments