diff --git a/12/Dockerfile.rhel8 b/12/Dockerfile.rhel8 index c37c48e5..1579cf3f 100644 --- a/12/Dockerfile.rhel8 +++ b/12/Dockerfile.rhel8 @@ -9,6 +9,8 @@ FROM ubi8/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=12 \ POSTGRESQL_PREV_VERSION=10 \ diff --git a/12/root/usr/share/container-scripts/postgresql/common.sh b/12/root/usr/share/container-scripts/postgresql/common.sh index 0486c735..878fd448 100644 --- a/12/root/usr/share/container-scripts/postgresql/common.sh +++ b/12/root/usr/share/container-scripts/postgresql/common.sh @@ -209,7 +209,10 @@ initdb_wrapper () # Initialize the database cluster with utf8 support enabled by default. # This might affect performance, see: # http://www.postgresql.org/docs/12/static/locale.html - LANG=${LANG:-en_US.utf8} "$@" + ENCODING=${POSTGRESQL_ENCODING:-UTF8} + LOCALE=${POSTGRESQL_LOCALE:-en_US} + if [ ${LOCALE} == "C" ] ; then LANG=C; fi + LANG=${LANG:-$LOCALE.$ENCODING} "$@" -E $ENCODING } function initialize_database() { @@ -242,7 +245,16 @@ EOF function create_users() { if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then createuser "$POSTGRESQL_USER" - createdb --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" + + EXTRA_ARGS="" + if [ -v POSTGRESQL_ENCODING ]; then + EXTRA_ARGS="$EXTRA_ARGS -E $POSTGRESQL_ENCODING" + fi + if [ -v POSTGRESQL_LOCALE ]; then + EXTRA_ARGS="$EXTRA_ARGS -l $POSTGRESQL_LOCALE" + fi + + createdb $EXTRA_ARGS --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" fi if [ -v POSTGRESQL_MASTER_USER ]; then diff --git a/13/Dockerfile.c9s b/13/Dockerfile.c9s index 4b870a53..9ee52942 100644 --- a/13/Dockerfile.c9s +++ b/13/Dockerfile.c9s @@ -9,6 +9,8 @@ FROM quay.io/sclorg/s2i-core-c9s:c9s # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=13 \ POSTGRESQL_PREV_VERSION=12 \ diff --git a/13/Dockerfile.rhel8 b/13/Dockerfile.rhel8 index c736efdc..f0a88d29 100644 --- a/13/Dockerfile.rhel8 +++ b/13/Dockerfile.rhel8 @@ -9,6 +9,8 @@ FROM ubi8/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=13 \ POSTGRESQL_PREV_VERSION=12 \ diff --git a/13/Dockerfile.rhel9 b/13/Dockerfile.rhel9 index 19d70596..3a95fdf2 100644 --- a/13/Dockerfile.rhel9 +++ b/13/Dockerfile.rhel9 @@ -9,6 +9,8 @@ FROM ubi9/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=13 \ POSTGRESQL_PREV_VERSION=12 \ diff --git a/13/root/usr/share/container-scripts/postgresql/common.sh b/13/root/usr/share/container-scripts/postgresql/common.sh index 369fd133..789ad4ae 100644 --- a/13/root/usr/share/container-scripts/postgresql/common.sh +++ b/13/root/usr/share/container-scripts/postgresql/common.sh @@ -209,7 +209,10 @@ initdb_wrapper () # Initialize the database cluster with utf8 support enabled by default. # This might affect performance, see: # http://www.postgresql.org/docs/13/static/locale.html - LANG=${LANG:-en_US.utf8} "$@" + ENCODING=${POSTGRESQL_ENCODING:-UTF8} + LOCALE=${POSTGRESQL_LOCALE:-en_US} + if [ ${LOCALE} == "C" ] ; then LANG=C; fi + LANG=${LANG:-$LOCALE.$ENCODING} "$@" -E $ENCODING } function initialize_database() { @@ -242,7 +245,16 @@ EOF function create_users() { if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then createuser "$POSTGRESQL_USER" - createdb --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" + + EXTRA_ARGS="" + if [ -v POSTGRESQL_ENCODING ]; then + EXTRA_ARGS="$EXTRA_ARGS -E $POSTGRESQL_ENCODING" + fi + if [ -v POSTGRESQL_LOCALE ]; then + EXTRA_ARGS="$EXTRA_ARGS -l $POSTGRESQL_LOCALE" + fi + + createdb $EXTRA_ARGS --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" fi if [ -v POSTGRESQL_MASTER_USER ]; then diff --git a/15/Dockerfile.c9s b/15/Dockerfile.c9s index e78d45b8..92a21f55 100644 --- a/15/Dockerfile.c9s +++ b/15/Dockerfile.c9s @@ -9,6 +9,8 @@ FROM quay.io/sclorg/s2i-core-c9s:c9s # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=15 \ POSTGRESQL_PREV_VERSION=13 \ diff --git a/15/Dockerfile.fedora b/15/Dockerfile.fedora index 5940bee6..e248a8ec 100644 --- a/15/Dockerfile.fedora +++ b/15/Dockerfile.fedora @@ -9,6 +9,8 @@ FROM quay.io/fedora/s2i-core:40 # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV NAME=postgresql \ VERSION=0 \ diff --git a/15/Dockerfile.rhel8 b/15/Dockerfile.rhel8 index 302ee20f..8961ef06 100644 --- a/15/Dockerfile.rhel8 +++ b/15/Dockerfile.rhel8 @@ -9,6 +9,8 @@ FROM ubi8/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=15 \ POSTGRESQL_PREV_VERSION=13 \ diff --git a/15/Dockerfile.rhel9 b/15/Dockerfile.rhel9 index 1a09870a..f37d9a9c 100644 --- a/15/Dockerfile.rhel9 +++ b/15/Dockerfile.rhel9 @@ -9,6 +9,8 @@ FROM ubi9/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=15 \ POSTGRESQL_PREV_VERSION=13 \ diff --git a/15/root/usr/share/container-scripts/postgresql/common.sh b/15/root/usr/share/container-scripts/postgresql/common.sh index 76a2eb0f..60c9889b 100644 --- a/15/root/usr/share/container-scripts/postgresql/common.sh +++ b/15/root/usr/share/container-scripts/postgresql/common.sh @@ -209,7 +209,10 @@ initdb_wrapper () # Initialize the database cluster with utf8 support enabled by default. # This might affect performance, see: # http://www.postgresql.org/docs/15/static/locale.html - LANG=${LANG:-en_US.utf8} "$@" + ENCODING=${POSTGRESQL_ENCODING:-UTF8} + LOCALE=${POSTGRESQL_LOCALE:-en_US} + if [ ${LOCALE} == "C" ] ; then LANG=C; fi + LANG=${LANG:-$LOCALE.$ENCODING} "$@" -E $ENCODING } function initialize_database() { @@ -242,7 +245,16 @@ EOF function create_users() { if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then createuser "$POSTGRESQL_USER" - createdb --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" + + EXTRA_ARGS="" + if [ -v POSTGRESQL_ENCODING ]; then + EXTRA_ARGS="$EXTRA_ARGS -E $POSTGRESQL_ENCODING" + fi + if [ -v POSTGRESQL_LOCALE ]; then + EXTRA_ARGS="$EXTRA_ARGS -l $POSTGRESQL_LOCALE" + fi + + createdb $EXTRA_ARGS --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" fi if [ -v POSTGRESQL_MASTER_USER ]; then diff --git a/16/Dockerfile.c10s b/16/Dockerfile.c10s index 388dcdb8..5c3155f4 100644 --- a/16/Dockerfile.c10s +++ b/16/Dockerfile.c10s @@ -9,6 +9,8 @@ FROM quay.io/sclorg/s2i-core-c10s:c10s # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=16 \ POSTGRESQL_PREV_VERSION=15 \ diff --git a/16/Dockerfile.c9s b/16/Dockerfile.c9s index 9eaa70c3..d7b1e200 100644 --- a/16/Dockerfile.c9s +++ b/16/Dockerfile.c9s @@ -9,6 +9,8 @@ FROM quay.io/sclorg/s2i-core-c9s:c9s # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=16 \ POSTGRESQL_PREV_VERSION=15 \ diff --git a/16/Dockerfile.fedora b/16/Dockerfile.fedora index 15ba45d1..da083558 100644 --- a/16/Dockerfile.fedora +++ b/16/Dockerfile.fedora @@ -9,6 +9,8 @@ FROM quay.io/fedora/s2i-core:40 # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV NAME=postgresql \ VERSION=0 \ diff --git a/16/Dockerfile.rhel10 b/16/Dockerfile.rhel10 index b482e7c8..4c19820e 100644 --- a/16/Dockerfile.rhel10 +++ b/16/Dockerfile.rhel10 @@ -9,6 +9,8 @@ FROM ubi10/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=16 \ POSTGRESQL_PREV_VERSION=15 \ diff --git a/16/Dockerfile.rhel8 b/16/Dockerfile.rhel8 index caeb622d..b5c78d61 100644 --- a/16/Dockerfile.rhel8 +++ b/16/Dockerfile.rhel8 @@ -9,6 +9,8 @@ FROM ubi8/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=16 \ POSTGRESQL_PREV_VERSION=15 \ diff --git a/16/Dockerfile.rhel9 b/16/Dockerfile.rhel9 index e560842d..d7f81934 100644 --- a/16/Dockerfile.rhel9 +++ b/16/Dockerfile.rhel9 @@ -9,6 +9,8 @@ FROM ubi9/s2i-core # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION=16 \ POSTGRESQL_PREV_VERSION=15 \ diff --git a/16/root/usr/share/container-scripts/postgresql/common.sh b/16/root/usr/share/container-scripts/postgresql/common.sh index fdb4410e..160eed44 100644 --- a/16/root/usr/share/container-scripts/postgresql/common.sh +++ b/16/root/usr/share/container-scripts/postgresql/common.sh @@ -209,7 +209,10 @@ initdb_wrapper () # Initialize the database cluster with utf8 support enabled by default. # This might affect performance, see: # http://www.postgresql.org/docs/16/static/locale.html - LANG=${LANG:-en_US.utf8} "$@" + ENCODING=${POSTGRESQL_ENCODING:-UTF8} + LOCALE=${POSTGRESQL_LOCALE:-en_US} + if [ ${LOCALE} == "C" ] ; then LANG=C; fi + LANG=${LANG:-$LOCALE.$ENCODING} "$@" -E $ENCODING } function initialize_database() { @@ -242,7 +245,16 @@ EOF function create_users() { if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then createuser "$POSTGRESQL_USER" - createdb --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" + + EXTRA_ARGS="" + if [ -v POSTGRESQL_ENCODING ]; then + EXTRA_ARGS="$EXTRA_ARGS -E $POSTGRESQL_ENCODING" + fi + if [ -v POSTGRESQL_LOCALE ]; then + EXTRA_ARGS="$EXTRA_ARGS -l $POSTGRESQL_LOCALE" + fi + + createdb $EXTRA_ARGS --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" fi if [ -v POSTGRESQL_MASTER_USER ]; then diff --git a/src/Dockerfile b/src/Dockerfile index 881312e8..ec4918fe 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -9,6 +9,8 @@ FROM {{ spec.s2i_base }} # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV POSTGRESQL_VERSION={{ spec.version }} \ {% if spec.prod != "rhel8" or spec.prod != "rhel9" or spec.version == "10" %} diff --git a/src/Dockerfile.fedora b/src/Dockerfile.fedora index 5078ddd8..496d418a 100644 --- a/src/Dockerfile.fedora +++ b/src/Dockerfile.fedora @@ -13,6 +13,8 @@ FROM quay.io/fedora/s2i-core:38 # * $POSTGRESQL_DATABASE - Name of the database to create # * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' # PostgreSQL administrative account +# * $POSTGRESQL_ENCODING - Database encoding. Default to UTF8 +# * $POSTGRESQL_LOCALE - Database locale. Default to en_US ENV NAME=postgresql \ VERSION=0 \ diff --git a/src/root/usr/share/container-scripts/postgresql/common.sh b/src/root/usr/share/container-scripts/postgresql/common.sh index bdad9f9b..1fc39b70 100644 --- a/src/root/usr/share/container-scripts/postgresql/common.sh +++ b/src/root/usr/share/container-scripts/postgresql/common.sh @@ -210,7 +210,10 @@ initdb_wrapper () # Initialize the database cluster with utf8 support enabled by default. # This might affect performance, see: # http://www.postgresql.org/docs/{{ spec.version }}/static/locale.html - LANG=${LANG:-en_US.utf8} "$@" + ENCODING=${POSTGRESQL_ENCODING:-UTF8} + LOCALE=${POSTGRESQL_LOCALE:-en_US} + if [ ${LOCALE} == "C" ] ; then LANG=C; fi + LANG=${LANG:-$LOCALE.$ENCODING} "$@" -E $ENCODING } function initialize_database() { @@ -243,7 +246,16 @@ EOF function create_users() { if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then createuser "$POSTGRESQL_USER" - createdb --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" + + EXTRA_ARGS="" + if [ -v POSTGRESQL_ENCODING ]; then + EXTRA_ARGS="$EXTRA_ARGS -E $POSTGRESQL_ENCODING" + fi + if [ -v POSTGRESQL_LOCALE ]; then + EXTRA_ARGS="$EXTRA_ARGS -l $POSTGRESQL_LOCALE" + fi + + createdb $EXTRA_ARGS --owner="$POSTGRESQL_USER" "$POSTGRESQL_DATABASE" fi if [ -v POSTGRESQL_MASTER_USER ]; then diff --git a/test/run_test b/test/run_test index 98e9fdb2..c5504070 100755 --- a/test/run_test +++ b/test/run_test @@ -29,6 +29,7 @@ run_migration_test run_pgaudit_test run_env_extension_load_test run_logging_test +run_locales_test " test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0 @@ -1101,6 +1102,54 @@ run_logging_test() echo " Success!" } +run_locales_test() { + local data_dir config_dir name=pg-test-locales-1 + # create a dir for data + create_volume_dir + data_dir="${volume_dir}" + + DOCKER_ARGS="-e POSTGRESQL_ADMIN_PASSWORD=Mellon + -e POSTGRESQL_LOCALE=en_GB + -e POSTGRESQL_ENCODING=ISO885915 + -v ${data_dir}:/var/lib/pgsql/data:Z" create_container $name + + wait_ready "$name" + + # LATIN9 is a alias for ISO885915 + docker exec -i $(get_cid "$name") bash -c "psql <