From a702b3078cf2c79fa922b3a3f407e08adb137503 Mon Sep 17 00:00:00 2001 From: Hardik Bhatia Date: Sat, 26 Sep 2026 20:33:31 +0530 Subject: [PATCH] fix(docker): wait for PostgreSQL before starting services --- .github/workflows/ci.yml | 21 +++++++++++++++++++-- docker-compose.yml | 8 +++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88b1069..9fb659a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,10 +46,27 @@ jobs: - run: PYTHONPATH=sdks/python/src python -m unittest discover -s sdks/python/tests -v - name: Rust SDK run: cargo test --locked --manifest-path sdks/rust/Cargo.toml - - name: Validate and build containers + - name: Validate containers and start with a fresh database env: ADMIN_PASSWORD: ci-admin-password-not-for-production CONTROL_PLANE_SECRET: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef POSTGRES_PASSWORD: 0123456789abcdef0123456789abcdef GATEWAY_API_KEY: pf_0123456789abcdef0123456789abcdef0123456789abcdef - run: docker compose config --quiet && docker compose build + run: | + docker compose config --quiet + cleanup() { + compose_exit_status=$? + if [ "$compose_exit_status" -ne 0 ]; then + docker compose logs --no-color || true + fi + docker compose down --volumes || compose_exit_status=$? + exit "$compose_exit_status" + } + trap cleanup EXIT + docker compose up --build --wait --wait-timeout 120 + curl --fail --silent --show-error http://127.0.0.1:8080/v1/health > /dev/null + curl --fail --silent --show-error http://127.0.0.1:8081/health > /dev/null + curl --fail --silent --show-error --retry 10 --retry-connrefused --retry-delay 1 http://127.0.0.1:3000/ > /dev/null + for container in $(docker compose ps -q); do + test "$(docker inspect --format '{{.RestartCount}}' "$container")" -eq 0 + done diff --git a/docker-compose.yml b/docker-compose.yml index ae87413..beb4e11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,8 @@ services: ports: - "127.0.0.1:55432:5432" healthcheck: - test: ["CMD-SHELL", "pg_isready -U pyro -d pyro"] + # The temporary initialization server only accepts Unix-socket connections. + test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "pyro", "-d", "pyro"] interval: 5s timeout: 3s retries: 20 @@ -35,6 +36,9 @@ services: GATEWAY_API_KEY: ${GATEWAY_API_KEY:?Set GATEWAY_API_KEY in .env} ports: - "127.0.0.1:8080:8080" + depends_on: + postgres: + condition: service_healthy healthcheck: test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/v1/health"] interval: 5s @@ -60,6 +64,8 @@ services: ports: - "127.0.0.1:8081:8081" depends_on: + postgres: + condition: service_healthy gateway: condition: service_healthy healthcheck: