fix(ci): B5 整合測試 — runner 加入 compose 網路直連 postgres:5432
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m54s
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m54s
放棄 published port 路徑,改用 docker network connect 讓 runner 直接進入 compose 網路,用 container IP:5432 連線 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -124,27 +124,24 @@ jobs:
|
||||
exit $PYTEST_EXIT
|
||||
|
||||
# ── 整合測試 B5 (2026-04-10) ──────────────────────────────────────────
|
||||
# DinD 環境: runner 是 container,compose sibling 的 published port 綁在 host
|
||||
# 用 host docker bridge IP (172.17.0.1) + exposed port 15432 連 postgres
|
||||
- name: Integration Tests (B5 — 真實 DB)
|
||||
run: |
|
||||
cd apps/api
|
||||
docker compose -f docker-compose.test.yml up -d --wait
|
||||
# schema 初始化 (exec stdin 不需要 volume)
|
||||
docker compose -f docker-compose.test.yml exec -T postgres-test \
|
||||
psql -U awoooi -d awoooi_test \
|
||||
< tests/integration/setup_test_schema.sql
|
||||
# DinD: runner 連 sibling container 需走 host bridge → port 15432
|
||||
# ip 指令在精簡 runner 環境可能不存在,改用 /proc/net/route
|
||||
HOST_IP=$(awk '$2=="00000000"{printf "%d.%d.%d.%d\n",
|
||||
"0x"substr($3,7,2)+0,"0x"substr($3,5,2)+0,
|
||||
"0x"substr($3,3,2)+0,"0x"substr($3,1,2)+0}' /proc/net/route | head -1)
|
||||
# fallback: docker0 bridge 慣例 IP
|
||||
[ -z "$HOST_IP" ] && HOST_IP="172.17.0.1"
|
||||
echo "host bridge IP: $HOST_IP"
|
||||
TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@${HOST_IP}:15432/awoooi_test?ssl=disable" \
|
||||
# 直接取 postgres container 的 IP,把 runner 加入同一網路
|
||||
PG_CONTAINER=$(docker ps --filter name=postgres-test --format '{{.Names}}' | head -1)
|
||||
PG_NETWORK=$(docker inspect "$PG_CONTAINER" --format '{{range $k,$v := .NetworkSettings.Networks}}{{$k}}{{end}}' | head -1)
|
||||
PG_IP=$(docker inspect "$PG_CONTAINER" --format "{{(index .NetworkSettings.Networks \"$PG_NETWORK\").IPAddress}}")
|
||||
echo "PG container=$PG_CONTAINER network=$PG_NETWORK ip=$PG_IP"
|
||||
# runner 加入 compose 網路,直連 5432
|
||||
docker network connect "$PG_NETWORK" "$(cat /etc/hostname)" 2>/dev/null || true
|
||||
TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@${PG_IP}:5432/awoooi_test?ssl=disable" \
|
||||
/opt/api-venv/bin/pytest tests/integration/test_b5_core_flows.py -v --tb=short
|
||||
TEST_EXIT=$?
|
||||
docker network disconnect "$PG_NETWORK" "$(cat /etc/hostname)" 2>/dev/null || true
|
||||
docker compose -f docker-compose.test.yml down -v 2>/dev/null || true
|
||||
exit $TEST_EXIT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user