From 0772eb31009bf36df7c39432f916b31d6bcc52f4 Mon Sep 17 00:00:00 2001 From: mazano Date: Sun, 17 Mar 2024 20:07:08 +0200 Subject: [PATCH] fix timescale build args (#470) * fix timescale build args * fix #463 * fix https://github.com/kartoza/docker-postgis/issues/462#issuecomment-1980535546 * DRY functions --------- Co-authored-by: spatialgeobyte <158478685+spatialgeobyte@users.noreply.github.com> --- .example.env | 3 ++- README.md | 2 +- docker-compose.build-timescale.yml | 1 + scripts/env-data.sh | 19 +++++++++++++++---- scripts/setup-conf.sh | 4 ++-- scripts/setup-user.sh | 5 +++-- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.example.env b/.example.env index 5a7750d7..c80e82e8 100644 --- a/.example.env +++ b/.example.env @@ -16,4 +16,5 @@ LANGS="en_US.UTF-8,id_ID.UTF-8" POSTGRES_MAJOR_VERSION=16 POSTGIS_MAJOR_VERSION=3 POSTGIS_MINOR_RELEASE=4 -BUILD_TIMESCALE=false \ No newline at end of file +BUILD_TIMESCALE=false +TIMESCALE_VERSION=2-2.14.2 diff --git a/README.md b/README.md index 522c7c78..4f7e10d4 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ This image uses the initial PostgreSQL values which disables the archiving optio * `-e WAL_SIZE=4GB` * `-e MIN_WAL_SIZE=2048MB` * `-e WAL_SEGSIZE=1024` -* `-e MAINTAINANCE_WORK_MEM=128MB` +* `-e MAINTENANCE_WORK_MEM=128MB` #### Configure networking diff --git a/docker-compose.build-timescale.yml b/docker-compose.build-timescale.yml index 23fddc37..4225ab19 100644 --- a/docker-compose.build-timescale.yml +++ b/docker-compose.build-timescale.yml @@ -15,6 +15,7 @@ services: POSTGIS_MAJOR_VERSION: ${POSTGIS_MAJOR_VERSION} POSTGIS_MINOR_RELEASE: ${POSTGIS_MINOR_RELEASE} BUILD_TIMESCALE: ${BUILD_TIMESCALE} + TIMESCALE_VERSION: ${TIMESCALE_VERSION} target: postgis-base postgis-prod: diff --git a/scripts/env-data.sh b/scripts/env-data.sh index a1c6ff59..122b3d9d 100644 --- a/scripts/env-data.sh +++ b/scripts/env-data.sh @@ -174,8 +174,8 @@ if [ -z "${IP_LIST}" ]; then IP_LIST='*' fi -if [ -z "${MAINTAINANCE_WORKERS}" ]; then - MAINTAINANCE_WORKERS=2 +if [ -z "${MAINTENANCE_WORKERS}" ]; then + MAINTENANCE_WORKERS=2 fi if [ -z "${ARCHIVE_MODE}" ]; then @@ -251,8 +251,8 @@ if [ -z "${MAX_WORKERS}" ]; then MAX_WORKERS=4 fi -if [ -z "${MAINTAINANCE_WORK_MEM}" ]; then - MAINTAINANCE_WORK_MEM=128MB +if [ -z "${MAINTENANCE_WORK_MEM}" ]; then + MAINTENANCE_WORK_MEM=128MB fi @@ -610,6 +610,7 @@ function non_root_permission() { function role_check() { ROLE_NAME=$1 echo "Creating user $1" + echo -e "\e[32m [Entrypoint] Creating/Updating user \e[1;31m $1 \033[0m" RESULT=$(su - postgres -c "psql postgres -t -c \"SELECT 1 FROM pg_roles WHERE rolname = '$ROLE_NAME'\"") COMMAND="ALTER" if [ -z "$RESULT" ]; then @@ -618,3 +619,13 @@ function role_check() { } +function role_creation() { + ROLE_NAME=$1 + ROLE_STATUS=$2 + ROLE_PASS=$3 + STATEMENT="$COMMAND USER \"$ROLE_NAME\" WITH ${ROLE_STATUS} ENCRYPTED PASSWORD '$ROLE_PASS';" + echo "$STATEMENT" > /tmp/setup_user.sql + su - postgres -c "psql postgres -f /tmp/setup_user.sql" + rm /tmp/setup_user.sql + +} \ No newline at end of file diff --git a/scripts/setup-conf.sh b/scripts/setup-conf.sh index a0e60231..68cf76d5 100644 --- a/scripts/setup-conf.sh +++ b/scripts/setup-conf.sh @@ -27,11 +27,11 @@ superuser_reserved_connections= 10 listen_addresses = '${IP_LIST}' shared_buffers = ${SHARED_BUFFERS} work_mem = ${WORK_MEM} -maintenance_work_mem = ${MAINTAINANCE_WORK_MEM} +maintenance_work_mem = ${MAINTENANCE_WORK_MEM} wal_buffers = ${WAL_BUFFERS} random_page_cost = 2.0 xmloption = 'document' -max_parallel_maintenance_workers = ${MAINTAINANCE_WORKERS} +max_parallel_maintenance_workers = ${MAINTENANCE_WORKERS} max_parallel_workers = ${MAX_WORKERS} shared_preload_libraries = '${SHARED_PRELOAD_LIBRARIES}' cron.database_name = '${SINGLE_DB}' diff --git a/scripts/setup-user.sh b/scripts/setup-user.sh index f5a017b8..3427c654 100644 --- a/scripts/setup-user.sh +++ b/scripts/setup-user.sh @@ -7,9 +7,10 @@ source /scripts/env-data.sh # Check user already exists role_check "$POSTGRES_USER" -su - postgres -c "psql postgres -c \"$COMMAND USER $POSTGRES_USER WITH SUPERUSER ENCRYPTED PASSWORD '$POSTGRES_PASS';\"" +role_creation ${POSTGRES_USER} SUPERUSER $POSTGRES_PASS role_check "$REPLICATION_USER" -su - postgres -c "psql postgres -c \"$COMMAND USER $REPLICATION_USER WITH REPLICATION ENCRYPTED PASSWORD '$REPLICATION_PASS';\"" +role_creation ${REPLICATION_USER} REPLICATION ${REPLICATION_PASS} +