Skip to content

Commit

Permalink
Merge pull request #2 from dapperlabs-platform/edoburu#53
Browse files Browse the repository at this point in the history
Adds multiple database support
  • Loading branch information
noyceb authored Feb 16, 2022
2 parents 6032fbf + 278df62 commit c8432c1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,36 @@ if [ ! -e "${_AUTH_FILE}" ]; then
touch "${_AUTH_FILE}"
fi

if [ -n "$DB_USER" -a -n "$DB_PASSWORD" -a -e "${_AUTH_FILE}" ] && ! grep -q "^\"$DB_USER\"" "${_AUTH_FILE}"; then
if [ "$AUTH_TYPE" != "plain" ]; then
if [ ! -n "${AUTH_USERLIST}" ] ; then
if [ -n "$DB_USER" -a -n "$DB_PASSWORD" -a -e "${_AUTH_FILE}" ] && ! grep -q "^\"$DB_USER\"" "${_AUTH_FILE}"; then
if [ "$AUTH_TYPE" != "plain" ]; then
pass="md5$(echo -n "$DB_PASSWORD$DB_USER" | md5sum | cut -f 1 -d ' ')"
else
else
pass="$DB_PASSWORD"
fi
echo "\"$DB_USER\" \"$pass\"" >> ${PG_CONFIG_DIR}/userlist.txt
echo "Wrote authentication credentials to ${PG_CONFIG_DIR}/userlist.txt"
fi
echo "\"$DB_USER\" \"$pass\"" >> ${PG_CONFIG_DIR}/userlist.txt
echo "Wrote authentication credentials to ${PG_CONFIG_DIR}/userlist.txt"
else
echo "${AUTH_USERLIST}" | tr , '\n' >> ${PG_CONFIG_DIR}/userlist.txt
fi

if [ ! -f ${PG_CONFIG_DIR}/pgbouncer.ini ]; then
echo "Create pgbouncer config in ${PG_CONFIG_DIR}"

if [ -n "${DB_DATABASES}" ] ; then
DB_DATABASES=`echo "${DB_DATABASES}" | tr , '\n'`
else
DB_DATABASES="${DB_NAME:-*} = host=${DB_HOST:?"Setup pgbouncer config error! You must set DB_HOST or DB_DATABASES env"} port=${DB_PORT:-5432} user=${DB_USER:-postgres}"
fi

# Config file is in “ini” format. Section names are between “[” and “]”.
# Lines starting with “;” or “#” are taken as comments and ignored.
# The characters “;” and “#” are not recognized when they appear later in the line.
printf "\
################## Auto generated ##################
[databases]
${DB_NAME:-*} = host=${DB_HOST:?"Setup pgbouncer config error! You must set DB_HOST env"} \
port=${DB_PORT:-5432} user=${DB_USER:-postgres}
${DB_DATABASES}
${CLIENT_ENCODING:+client_encoding = ${CLIENT_ENCODING}\n}\
[pgbouncer]
Expand Down

0 comments on commit c8432c1

Please sign in to comment.