From c734facf8f7336dc875e2de2b9c7490bab43dca8 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 6 Nov 2023 09:45:52 +0100 Subject: [PATCH] [bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars (#51830) * [bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars Signed-off-by: Jannis R * [bitnami/pgbouncer] add $PGBOUNCER_FAIL_ON_INVALID_DSN_FILE=true flag Signed-off-by: Jannis R --------- Signed-off-by: Jannis R --- .../opt/bitnami/scripts/libpgbouncer.sh | 23 +++++++++++++++---- .../opt/bitnami/scripts/pgbouncer-env.sh | 1 + bitnami/pgbouncer/README.md | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh index c80cdf37a8a6..2f52b7dbfb40 100644 --- a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh +++ b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh @@ -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; diff --git a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh index f1090b6fdf0d..7e28c26262db 100644 --- a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh +++ b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh @@ -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/}" diff --git a/bitnami/pgbouncer/README.md b/bitnami/pgbouncer/README.md index 8ebc48a37e99..addbdc06b44e 100644 --- a/bitnami/pgbouncer/README.md +++ b/bitnami/pgbouncer/README.md @@ -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): `"" ""`. ### Port and address binding