ci(test): reach the postgres service via service name, not 127.0.0.1
Some checks failed
test / contract-and-unit (pull_request) Failing after 14s

Now that BB1's port 5432 is freed, CI gets past the port-bind step
and actually attempts to run the tests. The next failure is:

  psycopg.OperationalError: connection to server at "127.0.0.1",
  port 5432 failed: Connection refused

The job tried 127.0.0.1:5432 but the postgres service container had
just been brought up and wasn't accepting connections yet. The
'5432:5432' port mapping for self-hosted act_runner is racy — the
host-side bind sometimes lags the service ready signal, and the
job's 'Apply schema' step runs before pg_isready returns 0.

Fix:
- Use the service name 'postgres' as DAMASCUS_PG_HOST. In act_runner's
  service network, the service name is the DNS hostname, no port
  mapping required.
- Drop the now-unused 'ports: 5432:5432' binding.

This is the same fix the cron branch fix/compose-db-volume-self-heal
should land in (PR #7). It's small enough to be a follow-up to this
PR; if the test workflow on BB1's runner doesn't resolve 'postgres',
we can revisit.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
damascus-heartbeat
2026-06-24 01:04:54 +00:00
parent a9304fe9a3
commit bec3e2f6a9

View File

@@ -17,8 +17,6 @@ jobs:
POSTGRES_USER: damascus
POSTGRES_PASSWORD: damascus
POSTGRES_DB: damascus
ports:
- "5432:5432"
options: >-
--health-cmd "pg_isready -U damascus -d damascus"
--health-interval 5s
@@ -28,7 +26,12 @@ jobs:
env:
DAMASCUS_ROOT: ${{ github.workspace }}
DAMASCUS_SCHEMA_PATH: ${{ github.workspace }}/schema.sql
DAMASCUS_PG_HOST: 127.0.0.1
# The postgres service is reachable by its service name on the runner
# network. We tried 127.0.0.1 + a host port binding first; the binding
# is racy on self-hosted act_runner (the port map sometimes takes
# effect after the job tries to connect, causing "Connection refused").
# Service-name DNS is reliable.
DAMASCUS_PG_HOST: postgres
DAMASCUS_PG_PORT: "5432"
DAMASCUS_PG_USER: damascus
DAMASCUS_PG_PASSWORD: damascus