From 95707d7e5b2d5c876a2477f4b9d044618c2fe77d Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Wed, 2 Oct 2024 18:19:17 +0200 Subject: [PATCH 1/2] Add support for locale and encoding, fix #406 Signed-off-by: Michael Scherer --- src/Dockerfile | 2 + src/Dockerfile.fedora | 2 + .../container-scripts/postgresql/common.sh | 16 +++++- test/run_test | 49 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/Dockerfile b/src/Dockerfile index ac6e25f6..082b5824 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 08260e6c..fd90d091 100755 --- a/test/run_test +++ b/test/run_test @@ -30,6 +30,7 @@ run_migration_test run_pgaudit_test run_new_pgaudit_test run_logging_test +run_locales_test " test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0 @@ -1029,6 +1030,54 @@ run_new_pgaudit_test() { run_pgaudit_test } +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 < Date: Wed, 2 Oct 2024 18:20:45 +0200 Subject: [PATCH 2/2] Regenerate scripts/doc --- 12/Dockerfile.rhel8 | 2 + .../container-scripts/postgresql/common.sh | 16 +++- 13/Dockerfile.c9s | 2 + 13/Dockerfile.rhel8 | 2 + 13/Dockerfile.rhel9 | 2 + .../container-scripts/postgresql/common.sh | 16 +++- 15/Dockerfile.c9s | 2 + 15/Dockerfile.fedora | 89 ------------------ 15/Dockerfile.rhel8 | 2 + 15/Dockerfile.rhel9 | 2 + .../container-scripts/postgresql/common.sh | 16 +++- 16/Dockerfile.c10s | 90 ------------------- 16/Dockerfile.c9s | 2 + 16/Dockerfile.fedora | 90 ------------------- 16/Dockerfile.rhel8 | 2 + 16/Dockerfile.rhel9 | 2 + .../container-scripts/postgresql/common.sh | 16 +++- 17 files changed, 76 insertions(+), 277 deletions(-) delete mode 100644 15/Dockerfile.fedora delete mode 100644 16/Dockerfile.c10s delete mode 100644 16/Dockerfile.fedora 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 af4da6c6..12955398 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 deleted file mode 100644 index 5940bee6..00000000 --- a/15/Dockerfile.fedora +++ /dev/null @@ -1,89 +0,0 @@ -FROM quay.io/fedora/s2i-core:40 - -# PostgreSQL image for OpenShift. -# Volumes: -# * /var/lib/psql/data - Database cluster for PostgreSQL -# Environment: -# * $POSTGRESQL_USER - Database user name -# * $POSTGRESQL_PASSWORD - User's password -# * $POSTGRESQL_DATABASE - Name of the database to create -# * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' -# PostgreSQL administrative account - -ENV NAME=postgresql \ - VERSION=0 \ - ARCH=x86_64 \ - \ - POSTGRESQL_VERSION=15 \ - POSTGRESQL_PREV_VERSION=13 \ - HOME=/var/lib/pgsql \ - PGUSER=postgres \ - APP_DATA=/opt/app-root - -ENV SUMMARY="PostgreSQL is an advanced Object-Relational database management system" \ - DESCRIPTION="PostgreSQL is an advanced Object-Relational database management system (DBMS). \ -The image contains the client and server programs that you'll need to \ -create, run, maintain and access a PostgreSQL DBMS server." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="PostgreSQL 15" \ - io.openshift.expose-services="5432:postgresql" \ - io.openshift.tags="database,postgresql,postgresql15" \ - com.redhat.component="$NAME" \ - maintainer="SoftwareCollections.org " \ - name="fedora/$NAME-15" \ - version="0" \ - usage="docker run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -p 5432:5432 quay.io/fedora/$NAME-15" - -EXPOSE 5432 - -COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions - -# This image must forever use UID 26 for postgres user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql15-server postgresql15-contrib nss_wrapper postgresql15-upgrade procps-ng util-linux" && \ - INSTALL_PKGS+=" findutils xz" && \ - INSTALL_PKGS+=" postgresql15-pgaudit" && \ - dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ - dnf clean all && \ - test "$(id postgres)" = "uid=26(postgres) gid=26(postgres) groups=26(postgres)" && \ - mkdir -p /var/lib/pgsql/data && \ - mkdir -p /run/postgresql && \ - /usr/libexec/fix-permissions /var/lib/pgsql /run/postgresql - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/postgresql - -COPY root / -COPY ./s2i/bin/ $STI_SCRIPTS_PATH - -# Hard links are not supported in Testing Farm approach during sync to guest -# operation system. Therefore tests are failing on error -# /usr/libexec/s2i/run no such file or directory -RUN ln -s /usr/bin/run-postgresql $STI_SCRIPTS_PATH/run - -VOLUME ["/var/lib/pgsql/data"] - -# S2I permission fixes -# -------------------- -# 1. unless specified otherwise (or - equivalently - we are in OpenShift), s2i -# build process would be executed as 'uid=26(postgres) gid=26(postgres)'. -# Such process wouldn't be able to execute the default 'assemble' script -# correctly (it transitively executes 'fix-permissions' script). So let's -# add the 'postgres' user into 'root' group here -# -# 2. we call fix-permissions on $APP_DATA here directly (UID=0 during build -# anyways) to assure that s2i process is actually able to _read_ the -# user-specified scripting. -RUN usermod -a -G root postgres && \ - /usr/libexec/fix-permissions --read-only "$APP_DATA" - -USER 26 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-postgresql"] 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 deleted file mode 100644 index 388dcdb8..00000000 --- a/16/Dockerfile.c10s +++ /dev/null @@ -1,90 +0,0 @@ -FROM quay.io/sclorg/s2i-core-c10s:c10s - -# PostgreSQL image for OpenShift. -# Volumes: -# * /var/lib/pgsql/data - Database cluster for PostgreSQL -# Environment: -# * $POSTGRESQL_USER - Database user name -# * $POSTGRESQL_PASSWORD - User's password -# * $POSTGRESQL_DATABASE - Name of the database to create -# * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' -# PostgreSQL administrative account - -ENV POSTGRESQL_VERSION=16 \ - POSTGRESQL_PREV_VERSION=15 \ - HOME=/var/lib/pgsql \ - PGUSER=postgres \ - APP_DATA=/opt/app-root - -ENV SUMMARY="PostgreSQL is an advanced Object-Relational database management system" \ - DESCRIPTION="PostgreSQL is an advanced Object-Relational database management system (DBMS). \ -The image contains the client and server programs that you'll need to \ -create, run, maintain and access a PostgreSQL DBMS server." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="PostgreSQL 16" \ - io.openshift.expose-services="5432:postgresql" \ - io.openshift.tags="database,postgresql,postgresql16,postgresql-16" \ - io.openshift.s2i.assemble-user="26" \ - name="sclorg/postgresql-16-c10s" \ - com.redhat.component="postgresql-16-container" \ - version="1" \ - usage="podman run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -p 5432:5432 sclorg/postgresql-16-c10s" \ - maintainer="SoftwareCollections.org " - -EXPOSE 5432 - -COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions - -# This image must forever use UID 26 for postgres user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext-envsubst bind-utils nss_wrapper-libs glibc-locale-source xz" && \ - PSQL_PKGS="postgresql16-server postgresql16-contrib postgresql16-upgrade" && \ - INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ - yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS $PSQL_PKGS && \ - rpm -V $INSTALL_PKGS postgresql-server postgresql-contrib postgresql-upgrade && \ - postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ - yum -y clean all --enablerepo='*' && \ - localedef -f UTF-8 -i en_US en_US.UTF-8 && \ - test "$(id postgres)" = "uid=26(postgres) gid=26(postgres) groups=26(postgres)" && \ - mkdir -p /var/lib/pgsql/data && \ - mkdir -p /run/postgresql && \ - /usr/libexec/fix-permissions /var/lib/pgsql /run/postgresql - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/postgresql \ - ENABLED_COLLECTIONS= - -COPY root / -COPY ./s2i/bin/ $STI_SCRIPTS_PATH - -# Hard links are not supported in Testing Farm approach during sync to guest -# operation system. Therefore tests are failing on error -# /usr/libexec/s2i/run no such file or directory -RUN ln -s /usr/bin/run-postgresql $STI_SCRIPTS_PATH/run - -# Not using VOLUME statement since it's not working in OpenShift Online: -# https://github.com/sclorg/httpd-container/issues/30 -# VOLUME ["/var/lib/pgsql/data"] - -# S2I permission fixes -# -------------------- -# 1. unless specified otherwise (or - equivalently - we are in OpenShift), s2i -# build process would be executed as 'uid=26(postgres) gid=26(postgres)'. -# Such process wouldn't be able to execute the default 'assemble' script -# correctly (it transitively executes 'fix-permissions' script). So let's -# add the 'postgres' user into 'root' group here -# -# 2. we call fix-permissions on $APP_DATA here directly (UID=0 during build -# anyways) to assure that s2i process is actually able to _read_ the -# user-specified scripting. -RUN usermod -a -G root postgres && \ - /usr/libexec/fix-permissions --read-only "$APP_DATA" - -USER 26 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-postgresql"] 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 deleted file mode 100644 index 15ba45d1..00000000 --- a/16/Dockerfile.fedora +++ /dev/null @@ -1,90 +0,0 @@ -FROM quay.io/fedora/s2i-core:40 - -# PostgreSQL image for OpenShift. -# Volumes: -# * /var/lib/psql/data - Database cluster for PostgreSQL -# Environment: -# * $POSTGRESQL_USER - Database user name -# * $POSTGRESQL_PASSWORD - User's password -# * $POSTGRESQL_DATABASE - Name of the database to create -# * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres' -# PostgreSQL administrative account - -ENV NAME=postgresql \ - VERSION=0 \ - ARCH=x86_64 \ - \ - POSTGRESQL_VERSION=16 \ - POSTGRESQL_PREV_VERSION=15 \ - HOME=/var/lib/pgsql \ - PGUSER=postgres \ - APP_DATA=/opt/app-root - -ENV SUMMARY="PostgreSQL is an advanced Object-Relational database management system" \ - DESCRIPTION="PostgreSQL is an advanced Object-Relational database management system (DBMS). \ -The image contains the client and server programs that you'll need to \ -create, run, maintain and access a PostgreSQL DBMS server." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="PostgreSQL 16" \ - io.openshift.expose-services="5432:postgresql" \ - io.openshift.tags="database,postgresql,postgresql16" \ - com.redhat.component="$NAME" \ - maintainer="SoftwareCollections.org " \ - name="fedora/$NAME-16" \ - version="0" \ - usage="docker run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -p 5432:5432 quay.io/fedora/$NAME-16" - -EXPOSE 5432 - -COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions - -# This image must forever use UID 26 for postgres user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \ - INSTALL_PKGS+=" procps-ng util-linux postgresql-upgrade" && \ - INSTALL_PKGS+=" findutils xz" && \ - INSTALL_PKGS+=" pgaudit" && \ - dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ - dnf clean all && \ - test "$(id postgres)" = "uid=26(postgres) gid=26(postgres) groups=26(postgres)" && \ - mkdir -p /var/lib/pgsql/data && \ - mkdir -p /run/postgresql && \ - /usr/libexec/fix-permissions /var/lib/pgsql /run/postgresql - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/postgresql - -COPY root / -COPY ./s2i/bin/ $STI_SCRIPTS_PATH - -# Hard links are not supported in Testing Farm approach during sync to guest -# operation system. Therefore tests are failing on error -# /usr/libexec/s2i/run no such file or directory -RUN ln -s /usr/bin/run-postgresql $STI_SCRIPTS_PATH/run - -VOLUME ["/var/lib/pgsql/data"] - -# S2I permission fixes -# -------------------- -# 1. unless specified otherwise (or - equivalently - we are in OpenShift), s2i -# build process would be executed as 'uid=26(postgres) gid=26(postgres)'. -# Such process wouldn't be able to execute the default 'assemble' script -# correctly (it transitively executes 'fix-permissions' script). So let's -# add the 'postgres' user into 'root' group here -# -# 2. we call fix-permissions on $APP_DATA here directly (UID=0 during build -# anyways) to assure that s2i process is actually able to _read_ the -# user-specified scripting. -RUN usermod -a -G root postgres && \ - /usr/libexec/fix-permissions --read-only "$APP_DATA" - -USER 26 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-postgresql"] 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