From 8b12300b2b85334a68585ff007bc4d67aa8bde04 Mon Sep 17 00:00:00 2001 From: mazano Date: Tue, 14 Apr 2020 19:00:36 +0200 Subject: [PATCH] reorder scripts and add new env variable for shared libraries (#231) * reorder scripts and add new env variable for shared libraries * Fix failing test * Increase timeout for collation tests Co-authored-by: admire --- Dockerfile | 21 ++++++------------- README.md | 4 ++++ .../tests/replication_test_master.sh | 2 +- .../tests/replication_test_slave.sh | 2 +- scenario_tests/collations/test.sh | 4 ++-- scenario_tests/collations/tests/test.sh | 2 +- scenario_tests/datadir_init/tests/test.sh | 2 +- .../replications/tests/test_master.sh | 2 +- .../replications/tests/test_node.sh | 2 +- .../docker-entrypoint.sh | 12 +++++------ env-data.sh => scripts/env-data.sh | 4 ++++ locale.gen => scripts/locale.gen | 0 setup-conf.sh => scripts/setup-conf.sh | 4 ++-- .../setup-database.sh | 4 ++-- setup-pg_hba.sh => scripts/setup-pg_hba.sh | 2 +- .../setup-replication.sh | 2 +- setup-ssl.sh => scripts/setup-ssl.sh | 2 +- setup-user.sh => scripts/setup-user.sh | 2 +- setup.sh => scripts/setup.sh | 2 +- 19 files changed, 37 insertions(+), 38 deletions(-) rename docker-entrypoint.sh => scripts/docker-entrypoint.sh (81%) rename env-data.sh => scripts/env-data.sh (98%) rename locale.gen => scripts/locale.gen (100%) rename setup-conf.sh => scripts/setup-conf.sh (96%) rename setup-database.sh => scripts/setup-database.sh (98%) rename setup-pg_hba.sh => scripts/setup-pg_hba.sh (98%) rename setup-replication.sh => scripts/setup-replication.sh (98%) rename setup-ssl.sh => scripts/setup-ssl.sh (97%) rename setup-user.sh => scripts/setup-user.sh (98%) rename setup.sh => scripts/setup.sh (96%) diff --git a/Dockerfile b/Dockerfile index a95b3ee..d411671 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ RUN set -eux \ # Generating locales takes a long time. Utilize caching by runnig it by itself # early in the build process. -COPY locale.gen /etc/locale.gen +COPY scripts/locale.gen /etc/locale.gen RUN set -eux \ && /usr/sbin/locale-gen @@ -50,24 +50,15 @@ RUN set -eux \ EXPOSE 5432 # Copy scripts -COPY docker-entrypoint.sh \ - env-data.sh \ - setup.sh \ - setup-conf.sh \ - setup-database.sh \ - setup-pg_hba.sh \ - setup-replication.sh \ - setup-ssl.sh \ - setup-user.sh \ - / +ADD scripts /scripts +WORKDIR /scripts +RUN chmod +x *.sh # Run any additional tasks here that are too tedious to put in # this dockerfile directly. RUN set -eux \ - && chmod +x /setup.sh \ - && /setup.sh \ - && chmod +x /docker-entrypoint.sh + && /scripts/setup.sh VOLUME /var/lib/postgresql -ENTRYPOINT /docker-entrypoint.sh +ENTRYPOINT /scripts/docker-entrypoint.sh diff --git a/README.md b/README.md index 3b314b9..a549217 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,10 @@ user name, password and/or default database name(or multiple databases comma sep * `-e POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology` You can pass as many extensions as you need. +* `-e SHARED_PRELOAD_LIBRARIES='pg_cron'` +Some extensions need to be registered in the postgresql.conf +as shared_preload_libraries. pg_cron should always be added because +the extension is installed with the image. * `-e SSL_CERT_FILE=/your/own/ssl_cert_file.pem` * `-e SSL_KEY_FILE=/your/own/ssl_key_file.key` * `-e SSL_CA_FILE=/your/own/ssl_ca_file.pem` diff --git a/sample/replication/tests/replication_test_master.sh b/sample/replication/tests/replication_test_master.sh index 41f6013..89537b4 100755 --- a/sample/replication/tests/replication_test_master.sh +++ b/sample/replication/tests/replication_test_master.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -. /env-data.sh +. /scripts/env-data.sh set -e diff --git a/sample/replication/tests/replication_test_slave.sh b/sample/replication/tests/replication_test_slave.sh index 6eaeab1..3b4230d 100755 --- a/sample/replication/tests/replication_test_slave.sh +++ b/sample/replication/tests/replication_test_slave.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -. /env-data.sh +. /scripts/env-data.sh set -e diff --git a/scenario_tests/collations/test.sh b/scenario_tests/collations/test.sh index 1b36eef..28a3953 100755 --- a/scenario_tests/collations/test.sh +++ b/scenario_tests/collations/test.sh @@ -8,7 +8,7 @@ source ../test-env.sh # Run service docker-compose up -d -sleep 5 +sleep 30 services=("pg" "pg-new") @@ -16,7 +16,7 @@ for service in "${services[@]}"; do # Execute tests until docker-compose exec $service pg_isready; do - sleep 1 + sleep 30 done; docker-compose exec $service /bin/bash /tests/test.sh diff --git a/scenario_tests/collations/tests/test.sh b/scenario_tests/collations/tests/test.sh index f1ad178..4b303df 100644 --- a/scenario_tests/collations/tests/test.sh +++ b/scenario_tests/collations/tests/test.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/scenario_tests/datadir_init/tests/test.sh b/scenario_tests/datadir_init/tests/test.sh index b30adf9..ae83323 100644 --- a/scenario_tests/datadir_init/tests/test.sh +++ b/scenario_tests/datadir_init/tests/test.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/scenario_tests/replications/tests/test_master.sh b/scenario_tests/replications/tests/test_master.sh index e9f0840..fdc4042 100644 --- a/scenario_tests/replications/tests/test_master.sh +++ b/scenario_tests/replications/tests/test_master.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/scenario_tests/replications/tests/test_node.sh b/scenario_tests/replications/tests/test_node.sh index ca2068e..b21e3d5 100644 --- a/scenario_tests/replications/tests/test_node.sh +++ b/scenario_tests/replications/tests/test_node.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/docker-entrypoint.sh b/scripts/docker-entrypoint.sh similarity index 81% rename from docker-entrypoint.sh rename to scripts/docker-entrypoint.sh index aa27599..6a61470 100755 --- a/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -2,29 +2,29 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # Setup postgres CONF file -source /setup-conf.sh +source /scripts/setup-conf.sh # Setup ssl -source /setup-ssl.sh +source /scripts/setup-ssl.sh # Setup pg_hba.conf -source /setup-pg_hba.sh +source /scripts/setup-pg_hba.sh if [[ -z "$REPLICATE_FROM" ]]; then # This means this is a master instance. We check that database exists echo "Setup master database" - source /setup-database.sh + source /scripts/setup-database.sh entry_point_script kill_postgres else # This means this is a slave/replication instance. echo "Setup slave database" - source /setup-replication.sh + source /scripts/setup-replication.sh fi diff --git a/env-data.sh b/scripts/env-data.sh similarity index 98% rename from env-data.sh rename to scripts/env-data.sh index 867b4ae..bdb34ac 100644 --- a/env-data.sh +++ b/scripts/env-data.sh @@ -213,6 +213,10 @@ if [ -z "$EXTRA_CONF" ]; then EXTRA_CONF="" fi +if [ -z "${SHARED_PRELOAD_LIBRARIES}" ]; then + SHARED_PRELOAD_LIBRARIES='pg_cron' +fi + # Compatibility with official postgres variable # Official postgres variable gets priority if [ -n "${POSTGRES_PASSWORD}" ]; then diff --git a/locale.gen b/scripts/locale.gen similarity index 100% rename from locale.gen rename to scripts/locale.gen diff --git a/setup-conf.sh b/scripts/setup-conf.sh similarity index 96% rename from setup-conf.sh rename to scripts/setup-conf.sh index e0fe92d..667f306 100644 --- a/setup-conf.sh +++ b/scripts/setup-conf.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then @@ -47,7 +47,7 @@ primary_conninfo = 'host=${REPLICATE_FROM} port=${REPLICATE_PORT} user=${REPLICA recovery_target_timeline=${TARGET_TIMELINE} recovery_target_action=${TARGET_ACTION} promote_trigger_file = '${PROMOTE_FILE}' -shared_preload_libraries = 'pg_cron' +shared_preload_libraries = '${SHARED_PRELOAD_LIBRARIES}' cron.database_name = '${SINGLE_DB}' EOF diff --git a/setup-database.sh b/scripts/setup-database.sh similarity index 98% rename from setup-database.sh rename to scripts/setup-database.sh index ca48dba..da3598e 100644 --- a/setup-database.sh +++ b/scripts/setup-database.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh # test if DATADIR has content # Do initialization if DATADIR is empty, or RECREATE_DATADIR is true @@ -36,7 +36,7 @@ done echo "postgres ready" # Setup user -source /setup-user.sh +source /scripts/setup-user.sh # enable extensions in template1 if env variable set to true if [[ "$(boolean ${POSTGRES_TEMPLATE_EXTENSIONS})" == TRUE ]] ; then diff --git a/setup-pg_hba.sh b/scripts/setup-pg_hba.sh similarity index 98% rename from setup-pg_hba.sh rename to scripts/setup-pg_hba.sh index d6d3238..f695597 100644 --- a/setup-pg_hba.sh +++ b/scripts/setup-pg_hba.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.pg_hba.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then diff --git a/setup-replication.sh b/scripts/setup-replication.sh similarity index 98% rename from setup-replication.sh rename to scripts/setup-replication.sh index cca6060..01db10a 100755 --- a/setup-replication.sh +++ b/scripts/setup-replication.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh # This script will setup slave instance to use standby replication diff --git a/setup-ssl.sh b/scripts/setup-ssl.sh similarity index 97% rename from setup-ssl.sh rename to scripts/setup-ssl.sh index f134e9c..8ce2a6f 100644 --- a/setup-ssl.sh +++ b/scripts/setup-ssl.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.ssl.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then diff --git a/setup-user.sh b/scripts/setup-user.sh similarity index 98% rename from setup-user.sh rename to scripts/setup-user.sh index 378f066..35b4d1c 100644 --- a/setup-user.sh +++ b/scripts/setup-user.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh # This script will setup new configured user diff --git a/setup.sh b/scripts/setup.sh similarity index 96% rename from setup.sh rename to scripts/setup.sh index 83a9cd5..d64c2fd 100755 --- a/setup.sh +++ b/scripts/setup.sh @@ -3,7 +3,7 @@ chmod 600 /etc/ssl/private/ssl-cert-snakeoil.key # These tasks are run as root -source /env-data.sh +source /scripts/env-data.sh # Restrict subnet to docker private network