diff --git a/.github/workflows/complementary-config-test.yaml b/.github/workflows/complementary-config-test.yaml index 8354be51..96f32dbd 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 /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 /bin/sh -c "datacube system init; datacube system check" docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows /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 /bin/sh -c "cd /code; ./compare-cfg.sh" diff --git a/.github/workflows/test-prod.yaml b/.github/workflows/test-prod.yaml index 64b53094..4111a900 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 b159ed30..014e4d24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,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 /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 1c0fe4be..be5823e4 100755 --- a/check-code-all.sh +++ b/check-code-all.sh @@ -2,9 +2,6 @@ # Convenience script for running Travis-like checks. set -ex -# ensure db is ready -sh ./docker/ows/wait-for-db - # Initialise ODC schemas datacube system init diff --git a/docker-compose.cleandb.yaml b/docker-compose.cleandb.yaml index 9cd563e1..bd8182ae 100644 --- a/docker-compose.cleandb.yaml +++ b/docker-compose.cleandb.yaml @@ -2,6 +2,7 @@ services: postgres: # clean postgis db image: kartoza/postgis:16 + 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: 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 b171cf52..7456c05d 100644 --- a/docker-compose.db.yaml +++ b/docker-compose.db.yaml @@ -2,6 +2,7 @@ services: postgres: # db build: docker/database/ + hostname: postgres environment: - POSTGRES_DB=${POSTGRES_DB} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} @@ -9,7 +10,15 @@ services: ports: - "${POSTGRES_PORT}:${POSTGRES_PORT}" 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: ports: - 8000:8000 + 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 fd39c43c..af3b0237 100644 --- a/docker-compose.pyspy.yaml +++ b/docker-compose.pyspy.yaml @@ -2,6 +2,9 @@ services: ows: 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 6353cd94..adeabe33 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -45,8 +45,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 f06c6a12..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=$READY_PROBE_DB --host=$POSTGRES_HOSTNAME --username=$POSTGRES_USER || [ $RETRIES -eq 0 ]; do - echo "Waiting for $READY_PROBE_DB databases, $((RETRIES-=1)) remaining attempts..." - sleep 2 -done - -exec "$@"