diff --git a/db/docker-compose.yml b/db/docker-compose.yml index 93ab291..c1b1444 100644 --- a/db/docker-compose.yml +++ b/db/docker-compose.yml @@ -37,11 +37,20 @@ services: - traefik pgbouncer: - image: edoburu/pgbouncer:latest + build: + context: ./pgbouncer container_name: ${DB_BOUNCER?DB_BOUNCER} restart: always environment: - DATABASE_URL: postgresql://${HASURA_DB_USER?HASURA_DB_USER}:${HASURA_DB_PASSWORD?HASURA_DB_PASSWORD}@${DB_HOST?DB_HOST}:${DB_PORT?DB_PORT}/${FERRY_DB_NAME?FERRY_DB_NAME} + DB_USER: ${DB_USER?DB_USER} + DB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD?DB_ROOT_PASSWORD} + FERRY_DB_USER: ${FERRY_DB_USER?FERRY_DB_USER} + FERRY_DB_PASSWORD: ${FERRY_DB_PASSWORD?FERRY_DB_PASSWORD} + HASURA_DB_USER: ${HASURA_DB_USER?HASURA_DB_USER} + HASURA_DB_PASSWORD: ${HASURA_DB_PASSWORD?HASURA_DB_PASSWORD} + DB_NAME: ${FERRY_DB_NAME?FERRY_DB_NAME} + DB_HOST: ${DB_HOST?DB_HOST} + DB_PORT: ${DB_PORT?DB_PORT} AUTH_TYPE: scram-sha-256 QUERY_WAIT_TIMEOUT: 600 MAX_CLIENT_CONN: 5000 diff --git a/db/pgbouncer/Dockerfile b/db/pgbouncer/Dockerfile new file mode 100644 index 0000000..0673a90 --- /dev/null +++ b/db/pgbouncer/Dockerfile @@ -0,0 +1,7 @@ +FROM edoburu/pgbouncer:latest + +# Custom step to generate all users from environment variables +COPY wrapped-entrypoint.sh / +# Use our wrapped entrypoint with the same command +ENTRYPOINT ["/wrapped-entrypoint.sh"] +CMD ["/usr/bin/pgbouncer", "/etc/pgbouncer/pgbouncer.ini"] diff --git a/db/pgbouncer/wrapped-entrypoint.sh b/db/pgbouncer/wrapped-entrypoint.sh new file mode 100755 index 0000000..0e8ac13 --- /dev/null +++ b/db/pgbouncer/wrapped-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +output_file="/etc/pgbouncer/userlist.txt" +> "$output_file" + +echo "\"$DB_USER\" \"$DB_ROOT_PASSWORD\"" >> "$output_file" +echo "\"$FERRY_DB_USER\" \"$FERRY_DB_PASSWORD\"" >> "$output_file" +echo "\"$HASURA_DB_USER\" \"$HASURA_DB_PASSWORD\"" >> "$output_file" + +echo "Userlist generated in $output_file" +cat "$output_file" +# Run the original entrypoint +/entrypoint.sh +exec "$@"