Skip to content

Commit

Permalink
fix timescale build args (#470)
Browse files Browse the repository at this point in the history
* fix timescale build args

* fix #463

* fix #462 (comment)

* DRY functions

---------

Co-authored-by: spatialgeobyte <[email protected]>
  • Loading branch information
NyakudyaA and spatialgeobyte committed Mar 17, 2024
1 parent 7571792 commit 0772eb3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
BUILD_TIMESCALE=false
TIMESCALE_VERSION=2-2.14.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docker-compose.build-timescale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 15 additions & 4 deletions scripts/env-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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

}
4 changes: 2 additions & 2 deletions scripts/setup-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
5 changes: 3 additions & 2 deletions scripts/setup-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}


0 comments on commit 0772eb3

Please sign in to comment.