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 964fef8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion db/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ services:
- traefik

pgbouncer:
image: edoburu/pgbouncer:latest
build:
context: ./pgbouncer
container_name: ${DB_BOUNCER?DB_BOUNCER}
restart: always
environment:
Expand Down
4 changes: 4 additions & 0 deletions db/pgbouncer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM edoburu/pgbouncer:latest

# Custom step to generate all users from environment variables
RUN ./generate-config.sh
26 changes: 26 additions & 0 deletions db/pgbouncer/generate-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Define users and passwords
declare -A users
users=(
["DB_USER"]="$DB_ROOT_PASSWORD"
["FERRY_DB_USER"]="$FERRY_DB_PASSWORD"
["HASURA_DB_USER"]="$HASURA_DB_PASSWORD"
)

output_file="/etc/pgbouncer/userlist.txt"

for user in "${!users[@]}"; do
if [ -z "${users[$user]}" ]; then
echo "Error: Password for $user is not set in the environment variables."
exit 1
fi
done

> "$output_file" # Clear the file

for user in "${!users[@]}"; do
password="${users[$user]}"
md5_hash=$(echo -n "md5$(echo -n "${password}${user}" | md5sum | awk '{print $1}')")
echo "\"$user\" \"$md5_hash\"" >> "$output_file"
done

0 comments on commit 964fef8

Please sign in to comment.