Skip to content

Commit

Permalink
compose: add health-check to postgres
Browse files Browse the repository at this point in the history
Add a health check to compose and
use that in the CI instead of the
wait-for-db-script.
  • Loading branch information
pjonsson committed Aug 6, 2024
1 parent 64865ad commit f543bb2
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/complementary-config-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/pyspy-profiling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,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.pyspy.yaml up -d
- name: Sleep for 10 seconds (stage 1 - wait for services to be ready)
uses: whatnick/wait-action@master
with:
time: '10s'
docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml up -d --wait
- name: set output container pid (stage 1 - get ows container pid)
id: set-output-container-id
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/test-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions check-code-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 9 additions & 0 deletions docker-compose.cleandb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ services:
postgres:
# clean postgis db
image: kartoza/postgis:13-3.1
hostname: postgres
environment:
- POSTGRES_DB=${DB_DATABASE}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_USER=${DB_USERNAME}
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_health
9 changes: 9 additions & 0 deletions docker-compose.db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ 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}
- POSTGRES_USER=${DB_USERNAME}
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
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
11 changes: 0 additions & 11 deletions docker/ows/wait-for-db

This file was deleted.

0 comments on commit f543bb2

Please sign in to comment.