Skip to content

Commit

Permalink
experiment generating multiple login users for pgbouncer
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Nov 24, 2024
1 parent eafd428 commit f1a127e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
13 changes: 11 additions & 2 deletions db/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions db/pgbouncer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
15 changes: 15 additions & 0 deletions db/pgbouncer/wrapped-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit f1a127e

Please sign in to comment.