fix(ci): B5 整合測試 — runner 加入 compose 網路才能路由到 postgres
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 15m26s
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 15m26s
問題: act runner 在 Docker 容器內,compose 網路 172.30.0.x 無法直接路由
修正: docker network connect 讓 runner 加入 api_default compose 網路,
測試後 disconnect 清理
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -133,24 +133,24 @@ jobs:
|
||||
docker compose -f docker-compose.test.yml exec -T postgres-test \
|
||||
psql -U awoooi -d awoooi_test \
|
||||
-f /dev/stdin < tests/integration/setup_test_schema.sql
|
||||
# 取得 postgres container IP: 找 api_ 開頭的 compose 網路,取第一個有效 IP
|
||||
# docker inspect 多網路時會拼接,用 json + jq 確保只取一個
|
||||
# Runner 在 Docker 容器內,需加入 compose 網路才能連到 postgres-test
|
||||
# compose 預設網路名: {project_name}_default,project = 目錄名 = api
|
||||
COMPOSE_NETWORK=$(docker network ls --filter name=api --format '{{.Name}}' | grep default | head -1)
|
||||
RUNNER_CONTAINER=$(hostname)
|
||||
echo "compose network: $COMPOSE_NETWORK, runner: $RUNNER_CONTAINER"
|
||||
if [ -n "$COMPOSE_NETWORK" ]; then
|
||||
docker network connect "$COMPOSE_NETWORK" "$RUNNER_CONTAINER" 2>/dev/null || true
|
||||
fi
|
||||
# 取 postgres container IP (compose 網路內)
|
||||
CONTAINER_NAME=$(docker ps --filter name=postgres-test --format '{{.Names}}' | head -1)
|
||||
echo "postgres-test container: $CONTAINER_NAME"
|
||||
PG_IP=$(docker inspect "$CONTAINER_NAME" \
|
||||
--format '{{json .NetworkSettings.Networks}}' \
|
||||
| python3 -c "import sys,json; nets=json.load(sys.stdin); print(list(nets.values())[0]['IPAddress'])" 2>/dev/null)
|
||||
# fallback: host 上 exposed port 15432
|
||||
if [ -z "$PG_IP" ]; then
|
||||
PG_IP="127.0.0.1"
|
||||
PG_PORT="15432"
|
||||
else
|
||||
PG_PORT="5432"
|
||||
fi
|
||||
echo "postgres-test IP: $PG_IP:$PG_PORT"
|
||||
TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@${PG_IP}:${PG_PORT}/awoooi_test?ssl=disable" \
|
||||
echo "postgres-test: $CONTAINER_NAME @ $PG_IP:5432"
|
||||
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 "$COMPOSE_NETWORK" "$RUNNER_CONTAINER" 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