The first run got through install, typecheck and all 39 tests, then failed on `getaddrinfo EAI_AGAIN postgres`. This runner does not attach service containers to the job's network, so the `services:` hostname never resolves. Fixed by starting Postgres with `--network container:$HOSTNAME`, sharing the job container's own network namespace so it appears on 127.0.0.1. That works regardless of how the runner is configured — which matters here because the runner is shared with other repositories and should not need reconfiguring to suit this one. Also queries row counts through `docker exec` rather than a local psql, since the runner image is not guaranteed to ship postgresql-client, and removes the container in an `if: always()` step so a failed run does not leave it behind. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+34
-16
@@ -30,21 +30,17 @@ jobs:
|
|||||||
verify:
|
verify:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
services:
|
# Postgres is started as a step rather than through `services:`.
|
||||||
postgres:
|
#
|
||||||
image: postgres:16-alpine
|
# The runner here does not put service containers on the job's network, so
|
||||||
env:
|
# `services:` yields "getaddrinfo EAI_AGAIN postgres". Sharing the job
|
||||||
POSTGRES_USER: pig
|
# container's own network namespace (`--network container:$HOSTNAME`) puts
|
||||||
POSTGRES_PASSWORD: pig
|
# Postgres on 127.0.0.1 and works regardless of how the runner is
|
||||||
POSTGRES_DB: pig
|
# configured — which matters because this runner is shared with other
|
||||||
options: >-
|
# repositories and should not have to be reconfigured to suit this one.
|
||||||
--health-cmd "pg_isready -U pig"
|
|
||||||
--health-interval 5s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 10
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: postgres://pig:pig@postgres:5432/pig
|
DATABASE_URL: postgres://pig:pig@127.0.0.1:5432/pig
|
||||||
|
PG_CONTAINER: pig-ci-pg-${{ github.run_id }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -53,6 +49,23 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '22'
|
||||||
|
|
||||||
|
- name: Start Postgres
|
||||||
|
run: |
|
||||||
|
docker rm -f "$PG_CONTAINER" 2>/dev/null || true
|
||||||
|
docker run -d --name "$PG_CONTAINER" \
|
||||||
|
--network "container:$(cat /etc/hostname)" \
|
||||||
|
-e POSTGRES_USER=pig -e POSTGRES_PASSWORD=pig -e POSTGRES_DB=pig \
|
||||||
|
postgres:16-alpine
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
if docker exec "$PG_CONTAINER" pg_isready -U pig -q; then
|
||||||
|
echo "Postgres ready after ${i}s"; exit 0
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "Postgres did not become ready"
|
||||||
|
docker logs "$PG_CONTAINER" | tail -30
|
||||||
|
exit 1
|
||||||
|
|
||||||
- name: Install
|
- name: Install
|
||||||
run: npm install --no-audit --no-fund
|
run: npm install --no-audit --no-fund
|
||||||
|
|
||||||
@@ -79,9 +92,10 @@ jobs:
|
|||||||
# pointed at twice, and nobody notices until the counts look odd.
|
# pointed at twice, and nobody notices until the counts look odd.
|
||||||
run: |
|
run: |
|
||||||
npx tsx packages/db/src/seed/index.ts > /dev/null
|
npx tsx packages/db/src/seed/index.ts > /dev/null
|
||||||
BEFORE=$(psql "$DATABASE_URL" -tAc "select count(*) from contacts")
|
count() { docker exec "$PG_CONTAINER" psql -U pig -d pig -tAc "select count(*) from contacts"; }
|
||||||
|
BEFORE=$(count)
|
||||||
npx tsx packages/db/src/seed/index.ts > /dev/null
|
npx tsx packages/db/src/seed/index.ts > /dev/null
|
||||||
AFTER=$(psql "$DATABASE_URL" -tAc "select count(*) from contacts")
|
AFTER=$(count)
|
||||||
echo "contacts: $BEFORE -> $AFTER"
|
echo "contacts: $BEFORE -> $AFTER"
|
||||||
test "$BEFORE" = "$AFTER" || { echo "SEED IS NOT IDEMPOTENT"; exit 1; }
|
test "$BEFORE" = "$AFTER" || { echo "SEED IS NOT IDEMPOTENT"; exit 1; }
|
||||||
|
|
||||||
@@ -122,3 +136,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Docker image builds
|
- name: Docker image builds
|
||||||
run: docker build -t pig:ci .
|
run: docker build -t pig:ci .
|
||||||
|
|
||||||
|
- name: Stop Postgres
|
||||||
|
if: always()
|
||||||
|
run: docker rm -f "$PG_CONTAINER" 2>/dev/null || true
|
||||||
|
|||||||
Reference in New Issue
Block a user