From b70664d9060e8069718c6858f2c11276201aa54a Mon Sep 17 00:00:00 2001 From: mazano Date: Thu, 30 Mar 2023 07:08:30 +0200 Subject: [PATCH] fix issue with host mounts (#419) * fix issue with host mounts and add tests --- .../datadir_init/docker-compose-gs.yml | 32 +++++++++++++++---- .../datadir_init/docker-compose.yml | 31 ++++++++++++++---- scenario_tests/datadir_init/test.sh | 14 ++++---- .../datadir_init/test_custom_waldir.sh | 4 +-- scripts/setup-database.sh | 3 +- 5 files changed, 61 insertions(+), 23 deletions(-) diff --git a/scenario_tests/datadir_init/docker-compose-gs.yml b/scenario_tests/datadir_init/docker-compose-gs.yml index 2b15149..c77d83e 100644 --- a/scenario_tests/datadir_init/docker-compose-gs.yml +++ b/scenario_tests/datadir_init/docker-compose-gs.yml @@ -7,6 +7,24 @@ volumes: recreate-pg-data-dir: init-waldir: services: + pg-local: + image: 'kartoza/postgis:${TAG:-manual-build}' + volumes: + # By default persisted volumes should be in /var/lib/postgresql + - ./default-pg-data-dir:/var/lib/postgresql + - ./tests:/tests + - ../utils:/lib/utils + environment: + # Default usage, no datadir location defined + TEST_CLASS: TestDefault + POSTGRES_PASS: 'docker' + RUN_AS_ROOT: false + healthcheck: + interval: 60s + timeout: 30s + retries: 3 + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" + pg-default: image: 'kartoza/postgis:${TAG:-manual-build}' volumes: @@ -23,7 +41,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-new: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -42,7 +60,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-recreate: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -63,7 +81,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-wrong: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -84,7 +102,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-correct: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -105,7 +123,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-not-match-1: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -126,7 +144,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-not-match-2: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -147,5 +165,5 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" diff --git a/scenario_tests/datadir_init/docker-compose.yml b/scenario_tests/datadir_init/docker-compose.yml index 57700f2..732721e 100644 --- a/scenario_tests/datadir_init/docker-compose.yml +++ b/scenario_tests/datadir_init/docker-compose.yml @@ -7,6 +7,23 @@ volumes: recreate-pg-data-dir: init-waldir: services: + pg-local: + image: 'kartoza/postgis:${TAG:-manual-build}' + volumes: + # By default persisted volumes should be in /var/lib/postgresql + - ./local-pg-data-dir:/var/lib/postgresql + - ./tests:/tests + - ../utils:/lib/utils + environment: + # Default usage, no datadir location defined + TEST_CLASS: TestDefault + POSTGRES_PASS: 'docker' + healthcheck: + interval: 60s + timeout: 30s + retries: 3 + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" + pg-default: image: 'kartoza/postgis:${TAG:-manual-build}' volumes: @@ -22,7 +39,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-new: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -40,7 +57,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-recreate: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -60,7 +77,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-wrong: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -80,7 +97,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-correct: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -100,7 +117,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-not-match-1: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -120,7 +137,7 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" pg-custom-waldir-not-match-2: image: 'kartoza/postgis:${TAG:-manual-build}' @@ -140,5 +157,5 @@ services: interval: 60s timeout: 30s retries: 3 - test: "pg_isready" + test: "PGPASSWORD=docker pg_isready -h 127.0.0.1 -U docker -d gis" diff --git a/scenario_tests/datadir_init/test.sh b/scenario_tests/datadir_init/test.sh index 538be73..e277076 100755 --- a/scenario_tests/datadir_init/test.sh +++ b/scenario_tests/datadir_init/test.sh @@ -13,7 +13,7 @@ fi # Run service for root user -${VERSION} up -d pg-default pg-new pg-recreate +${VERSION} up -d pg-local pg-default pg-new pg-recreate if [[ -n "${PRINT_TEST_LOGS}" ]]; then ${VERSION} logs -f & @@ -21,7 +21,7 @@ fi sleep 30 -services=("pg-default" "pg-new" "pg-recreate") +services=("pg-local" "pg-default" "pg-new" "pg-recreate") for service in "${services[@]}"; do @@ -40,9 +40,11 @@ bash ./test_custom_waldir.sh ${VERSION} down -v -# Run service for none root user -${VERSION} -f docker-compose-gs.yml up -d pg-default pg-new pg-recreate +# Run service for none root user +mkdir default-pg-data-dir + +${VERSION} -f docker-compose-gs.yml up -d pg-local pg-default pg-new pg-recreate if [[ -n "${PRINT_TEST_LOGS}" ]]; then ${VERSION} -f docker-compose-gs.yml logs -f & @@ -50,7 +52,7 @@ fi sleep 30 -services=("pg-default" "pg-new" "pg-recreate") +services=("pg-local" "pg-default" "pg-new" "pg-recreate") for service in "${services[@]}"; do @@ -67,4 +69,4 @@ done # special meta test to check the setup #bash ./test_custom_waldir_gs.sh -${VERSION} -f docker-compose-gs.yml down -v \ No newline at end of file +${VERSION} -f docker-compose-gs.yml down -v diff --git a/scenario_tests/datadir_init/test_custom_waldir.sh b/scenario_tests/datadir_init/test_custom_waldir.sh index bfa3a78..d63ad30 100644 --- a/scenario_tests/datadir_init/test_custom_waldir.sh +++ b/scenario_tests/datadir_init/test_custom_waldir.sh @@ -23,11 +23,11 @@ fi # Try to make sure that container recreation is successful echo "### Checking Container Recreation" ${VERSION} down -${VERSION} up -d pg-default pg-new pg-recreate +${VERSION} up -d pg-local pg-default pg-new pg-recreate sleep 60 -services=("pg-default" "pg-new" "pg-recreate") +services=("pg-local" "pg-default" "pg-new" "pg-recreate") for service in "${services[@]}"; do diff --git a/scripts/setup-database.sh b/scripts/setup-database.sh index d21a754..4dbc508 100644 --- a/scripts/setup-database.sh +++ b/scripts/setup-database.sh @@ -34,7 +34,7 @@ EOF fi create_dir "${WAL_ARCHIVE}" -non_root_permission postgres postgres + # test if DATADIR has content # Do initialization if DATADIR directory is empty, or RECREATE_DATADIR is true @@ -74,6 +74,7 @@ EOF fi fi; +non_root_permission postgres postgres # Set proper permissions # needs to be done as root: chown -R postgres:postgres ${DATADIR} ${WAL_ARCHIVE}