Skip to content

Commit

Permalink
[bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars (#51830)
Browse files Browse the repository at this point in the history
* [bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars

Signed-off-by: Jannis R <[email protected]>

* [bitnami/pgbouncer] add $PGBOUNCER_FAIL_ON_INVALID_DSN_FILE=true flag

Signed-off-by: Jannis R <[email protected]>

---------

Signed-off-by: Jannis R <[email protected]>
  • Loading branch information
derhuerst authored Nov 6, 2023
1 parent bdeb6c9 commit c734fac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,29 @@ pgbouncer_initialize() {
ini-file set --ignore-inline-comments --section "databases" --key "$PGBOUNCER_DATABASE" --value "$database_value" "$PGBOUNCER_CONF_FILE"

i=0;
while true; VAR_NAME="PGBOUNCER_DSN_${i}";
while true; VAR_NAME="PGBOUNCER_DSN_${i}"; FILE_VAR_NAME="PGBOUNCER_DSN_${i}_FILE";
do
if [ -z "${!VAR_NAME+x}" ]; then
break;
else
if [ -n "${!FILE_VAR_NAME+x}" ]; then
debug "reading \$$VAR_NAME from file, via \$$FILE_VAR_NAME (${!FILE_VAR_NAME})"
if [[ -r "${!FILE_VAR_NAME:-}" ]]; then
export "${VAR_NAME}=$(< "${!FILE_VAR_NAME}")"
unset "${FILE_VAR_NAME}"
else
if [[ "$PGBOUNCER_FAIL_ON_INVALID_DSN_FILE" == "false" ]]; then
warn "Skipping export of '${VAR_NAME}'. '${!FILE_VAR_NAME:-}' is not readable."
else
error "Failed to export \$$VAR_NAME. '${!FILE_VAR_NAME:-}' is not readable."
exit 1
fi
fi
fi

if [ -n "${!VAR_NAME:-}" ]; then
dsn=${!VAR_NAME};
ini-file set --ignore-inline-comments --section databases --key "$(echo "$dsn" | cut -d = -f 1)" --value "$(echo "$dsn" | cut -d = -f 2-)" "$PGBOUNCER_CONF_FILE";
i=$(( "$i" + 1 ));
else
break;
fi;
done;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export PGBOUNCER_SET_DATABASE_PASSWORD="${PGBOUNCER_SET_DATABASE_PASSWORD:-no}"
export PGBOUNCER_USERLIST="${PGBOUNCER_USERLIST:-}"
export PGBOUNCER_CONNECT_QUERY="${PGBOUNCER_CONNECT_QUERY:-}"
export PGBOUNCER_FORCE_INITSCRIPTS="${PGBOUNCER_FORCE_INITSCRIPTS:-false}"
export PGBOUNCER_FAIL_ON_INVALID_DSN_FILE="${PGBOUNCER_FAIL_ON_INVALID_DSN_FILE:-false}"

# Socket settings
export PGBOUNCER_SOCKET_DIR="${PGBOUNCER_SOCKET_DIR:-/tmp/}"
Expand Down
1 change: 1 addition & 0 deletions bitnami/pgbouncer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The Bitnami PgBouncer container requires a running PostgreSQL installation to co
* `PGBOUNCER_SET_DATABASE_PASSWORD`: Whether to include the backend PostgreSQL password in the database string. Default **no**.
* `PGBOUNCER_CONNECT_QUERY`: Query which will be executed after a connection is established. No Defaults.
* `PGBOUNCER_DSN_${i}`: PgBouncer configuration string for extra PostgreSQL server, where `i` is a number starting at zero (`0`).
* `PGBOUNCER_DSN_${i}_FILE`: As an alternative to specifying extra PostgreSQL servers *directly* using `PGBOUNCER_DSN_${i}` (see above), specify file paths containing the values, one file per PostgreSQL server. This is in line how other variables get read from `$…_FILE` if it is provided. – By default, when a file is missing, a warning will be printed, and all others will be used. If you set `$PGBOUNCER_FAIL_ON_INVALID_DSN_FILE` to `true`, the initialisation process will instead abort with an error.
* `PGBOUNCER_USERLIST_FILE`: Custom PgBouncer userlists file with connection credentials for any extra PostgreSQL backend. Required line format (including quotes): `"<postresql-user>" "<password>"`.

### Port and address binding
Expand Down

0 comments on commit c734fac

Please sign in to comment.