fix(ci): scope integration Postgres discovery to this job's network

`--filter name=integration` matched EVERY concurrent integration run's
Postgres service container. A dev push and the main-merge run overlap
on the shared act_runner daemon → 2 candidates → the "expected exactly
1" guard aborts (false failure; not a code defect).

Discover instead by intersecting networks: act_runner attaches the job
container and its service container to a shared per-job network, so
select the postgres that sits on a network this job container is also
on. The dev-compose container is skipped explicitly as before.

CI-only change; the released v2026.05.19.0 code is unaffected (a clean
re-run of the failed job passes — the failure was a concurrency race).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 22:50:04 -04:00
parent c681191b42
commit eaddb2478a
+25 -13
View File
@@ -83,19 +83,31 @@ jobs:
run: | run: |
set -eux set -eux
# Discover THIS job's Postgres service container via the # Discover THIS job's Postgres service container via the
# mounted docker socket. Scope by the job-name filter so the # mounted docker socket. act_runner attaches the job
# operator's dev compose `minstrel-postgres-*` (same image, # container and its service container(s) to a shared per-job
# same daemon) can never match. Require exactly one — abort # network, so scope discovery to a postgres that sits on a
# loudly otherwise; a wrong target would truncate real data. # network THIS job container is also on. The old
PG_LIST=$(docker ps --filter "name=integration" --filter "ancestor=postgres:16-alpine" --format '{{.ID}} {{.Names}}') # `--filter name=integration` matched EVERY concurrent
echo "candidates: ${PG_LIST:-<none>}" # integration run's postgres (a dev push + the main-merge run
PG_COUNT=$(printf '%s\n' "$PG_LIST" | grep -c . || true) # overlap → 2 candidates → false "expected exactly 1" abort).
test "$PG_COUNT" = "1" || { echo "FATAL: expected exactly 1 postgres service container, got $PG_COUNT"; exit 1; } # The operator's dev compose `minstrel-postgres-*` is never on
PG_ID=$(printf '%s' "$PG_LIST" | awk '{print $1}') # this job's network; skip it explicitly as belt-and-suspenders
PG_NAME=$(printf '%s' "$PG_LIST" | awk '{print $2}') # (a wrong target would truncate real data).
case "$PG_NAME" in SELF=$(cat /etc/hostname)
*minstrel-postgres*|*_postgres_*) echo "FATAL: matched the dev compose container ($PG_NAME), refusing"; exit 1 ;; SELF_NETS=$(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}' "$SELF")
esac test -n "$SELF_NETS"
echo "self ($SELF) networks: $SELF_NETS"
PG_ID=""
PG_NAME=""
for cid in $(docker ps --filter "ancestor=postgres:16-alpine" -q); do
nm=$(docker inspect -f '{{.Name}}' "$cid" | sed 's#^/##')
case "$nm" in *minstrel-postgres*|*_postgres_*) continue ;; esac
for net in $(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}' "$cid"); do
case " $SELF_NETS " in *" $net "*) PG_ID="$cid"; PG_NAME="$nm"; break 2 ;; esac
done
done
test -n "$PG_ID" || { echo "FATAL: no postgres service container on this job's network (self nets: $SELF_NETS)"; exit 1; }
echo "selected postgres: $PG_ID $PG_NAME"
PG_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$PG_ID") PG_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$PG_ID")
test -n "$PG_IP" test -n "$PG_IP"
export MINSTREL_TEST_DATABASE_URL="postgres://minstrel:minstrel@${PG_IP}:5432/minstrel_test?sslmode=disable" export MINSTREL_TEST_DATABASE_URL="postgres://minstrel:minstrel@${PG_IP}:5432/minstrel_test?sslmode=disable"