diff --git a/.github/workflows/complementary-config-test.yaml b/.github/workflows/complementary-config-test.yaml index 5e13b55c..a75cc474 100644 --- a/.github/workflows/complementary-config-test.yaml +++ b/.github/workflows/complementary-config-test.yaml @@ -60,8 +60,7 @@ jobs: export LOCAL_GID=$(id -g $USER) cd ./datacube-ows export $(grep -v '^#' ./complementary_config_test/.env_complementary_config_dea_dev | xargs) - docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml up -d - docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows_18 /bin/sh -c "cd /code; sh ./docker/ows/wait-for-db" + docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml up -d --wait docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows_18 /bin/sh -c "datacube system init; datacube system check" docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows_18 /bin/sh -c "curl https://raw.githubusercontent.com/GeoscienceAustralia/dea-config/master/dev/services/wms/inventory.json -o /tmp/inventory.json" docker compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows_18 /bin/sh -c "cd /code; ./compare-cfg.sh" diff --git a/.github/workflows/test-prod.yaml b/.github/workflows/test-prod.yaml index 7af740cc..bae2251f 100644 --- a/.github/workflows/test-prod.yaml +++ b/.github/workflows/test-prod.yaml @@ -57,12 +57,7 @@ jobs: export LOCAL_UID=$(id -u $USER) export LOCAL_GID=$(id -g $USER) export $(grep -v '^#' .env_simple | xargs) - docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.prod.yaml up -d - - - name: Sleep for 10 seconds - uses: whatnick/wait-action@master - with: - time: '10s' + docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.prod.yaml up -d --wait # Run some tests on the images # These tests require a working database diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c156fd45..d2a46e28 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -62,7 +62,7 @@ jobs: export LOCAL_UID=$(id -u $USER) export LOCAL_GID=$(id -g $USER) export $(grep -v '^#' .env_simple | xargs) - docker compose -f docker-compose.yaml -f docker-compose.db.yaml up -d + docker compose -f docker-compose.yaml -f docker-compose.db.yaml up -d --wait docker compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows_18 /bin/sh -c "cd /code;./check-code-all.sh" docker compose -f docker-compose.yaml -f docker-compose.db.yaml down diff --git a/check-code-all.sh b/check-code-all.sh index 8ac70aa0..fba63de0 100755 --- a/check-code-all.sh +++ b/check-code-all.sh @@ -2,8 +2,6 @@ # Convenience script for running Travis-like checks. set -ex -# ensure db is ready -sh ./docker/ows/wait-for-db # Run tests, taking coverage. # Users can specify extra folders as arguments. diff --git a/docker-compose.cleandb.yaml b/docker-compose.cleandb.yaml index 5a771f79..b3b05f77 100644 --- a/docker-compose.cleandb.yaml +++ b/docker-compose.cleandb.yaml @@ -2,6 +2,7 @@ services: postgres: # clean postgis db image: kartoza/postgis:13-3.1 + hostname: postgres environment: - POSTGRES_DB=${DB_DATABASE} - POSTGRES_PASSWORD=${DB_PASSWORD} @@ -9,9 +10,17 @@ services: ports: - "${DB_PORT}:5432" restart: always + healthcheck: + test: ["CMD", "pg_isready", "-h", "postgres", "-q", "-d", "$$POSTGRES_DB", "-U", "$$POSTGRES_USER"] + timeout: 45s + interval: 10s + retries: 10 # Overwrite ows so it can talk to docker db ows_18: ports: - 8000:8000 environment: DB_PORT: 5432 + depends_on: + postgres: + condition: service_healthy diff --git a/docker-compose.db.yaml b/docker-compose.db.yaml index e1c6d758..00d1c0fc 100644 --- a/docker-compose.db.yaml +++ b/docker-compose.db.yaml @@ -2,6 +2,7 @@ services: postgres: # db with some data from s2_l2a pre-indexed build: docker/database/ + hostname: postgres environment: - POSTGRES_DB=${DB_DATABASE} - POSTGRES_PASSWORD=${DB_PASSWORD} @@ -9,9 +10,17 @@ services: ports: - "${DB_PORT}:5432" restart: always + healthcheck: + test: ["CMD", "pg_isready", "-h", "postgres", "-q", "-d", "$$POSTGRES_DB", "-U", "$$POSTGRES_USER"] + timeout: 45s + interval: 10s + retries: 10 # Overwrite ows so it can talk to docker db ows_18: ports: - 8000:8000 environment: DB_PORT: 5432 + depends_on: + postgres: + condition: service_healthy diff --git a/docker-compose.index.yaml b/docker-compose.index.yaml index d2c5e3dc..7b264adf 100644 --- a/docker-compose.index.yaml +++ b/docker-compose.index.yaml @@ -9,5 +9,6 @@ services: DB_DATABASE: ${DB_DATABASE} restart: always depends_on: - - postgres + postgres: + condition: service_healthy command: tail -f /dev/null diff --git a/docker-compose.pyspy.yaml b/docker-compose.pyspy.yaml index 2bba0f49..436c1707 100644 --- a/docker-compose.pyspy.yaml +++ b/docker-compose.pyspy.yaml @@ -2,6 +2,9 @@ services: ows_18: cap_add: - SYS_PTRACE + depends_on: + postgres: + condition: service_healthy pyspy: build: docker/pyspy/ diff --git a/docker-compose.yaml b/docker-compose.yaml index ba687afb..dec1fbc7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -38,8 +38,7 @@ services: SENTRY_DSN: "${SENTRY_DSN}" volumes: - ${OWS_CFG_DIR}:${OWS_CFG_MOUNT_DIR} - - ./docker/ows/wait-for-db:/usr/local/bin/wait-for-db - ./:/code/ - ./artifacts:/mnt/artifacts restart: always - command: ["wait-for-db", "flask", "run", "--host=0.0.0.0", "--port=8000"] + command: ["flask", "run", "--host=0.0.0.0", "--port=8000"] diff --git a/docker/ows/wait-for-db b/docker/ows/wait-for-db deleted file mode 100755 index 732e4970..00000000 --- a/docker/ows/wait-for-db +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -RETRIES=10 - -# Wait until Database is ready -until pg_isready --dbname=$DB_DATABASE --host=$DB_HOSTNAME --port=$DB_PORT --username=$DB_USERNAME || [ $RETRIES -eq 0 ]; do - echo "Waiting for $DB_HOSTNAME server, $((RETRIES-=1)) remaining attempts..." - sleep 2 -done - -exec "$@"