[bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars (#51830)

* [bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars

Signed-off-by: Jannis R <mail@jannisr.de>

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

Signed-off-by: Jannis R <mail@jannisr.de>

---------

Signed-off-by: Jannis R <mail@jannisr.de>
This commit is contained in:
Jannis R 2023-11-06 09:45:52 +01:00 committed by GitHub
parent bdeb6c947c
commit c734facf8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -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;

View File

@ -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/}"

View File

@ -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