fix(ci): B5 整合測試 DinD 修正 — 用 host bridge IP + published port
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 2m2s
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 2m2s
DinD 環境下 volume mount 和 compose 網路都不可靠: - runner container 的路徑 ≠ host 路徑 (volume 失敗) - compose 網路 IP 對 runner 不可路由 解法: host docker bridge (ip route default gateway) + postgres exposed port 15432 runner 直接用 /opt/api-venv/bin/pytest (host runner 上已安裝) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -124,15 +124,24 @@ jobs:
|
||||
exit $PYTEST_EXIT
|
||||
|
||||
# ── 整合測試 B5 (2026-04-10) ──────────────────────────────────────────
|
||||
# pytest-runner service 在 compose 網路內跑,hostname=postgres-test 直連
|
||||
# schema 由 postgres initdb.d 自動初始化,不依賴 host /opt/api-venv
|
||||
# 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 --profile test up \
|
||||
--abort-on-container-exit --exit-code-from pytest-runner
|
||||
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
|
||||
# docker0 bridge IP 通常是 172.17.0.1,但用 route 確保準確
|
||||
HOST_IP=$(ip route | awk '/default/{print $3}' | head -1)
|
||||
echo "host bridge IP: $HOST_IP"
|
||||
TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@${HOST_IP}:15432/awoooi_test?ssl=disable" \
|
||||
/opt/api-venv/bin/pytest tests/integration/test_b5_core_flows.py -v --tb=short
|
||||
TEST_EXIT=$?
|
||||
docker compose -f docker-compose.test.yml --profile test down -v 2>/dev/null || true
|
||||
docker compose -f docker-compose.test.yml down -v 2>/dev/null || true
|
||||
exit $TEST_EXIT
|
||||
|
||||
- name: Login to Harbor
|
||||
|
||||
@@ -17,9 +17,6 @@ services:
|
||||
POSTGRES_PASSWORD: awoooi_test_2026
|
||||
ports:
|
||||
- "15432:5432"
|
||||
# 啟動時自動執行 setup_test_schema.sql (initdb.d 機制)
|
||||
volumes:
|
||||
- ./tests/integration/setup_test_schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U awoooi -d awoooi_test"]
|
||||
interval: 5s
|
||||
@@ -40,6 +37,7 @@ services:
|
||||
|
||||
# 2026-04-10 Claude Sonnet 4.6 Asia/Taipei: 整合測試 runner
|
||||
# 在 compose 網路內跑 pytest,hostname=postgres-test 直連,不依賴 host venv
|
||||
# Schema 由 CD workflow 用 compose exec psql 初始化(避免 DinD volume 路徑問題)
|
||||
pytest-runner:
|
||||
image: python:3.11-slim
|
||||
working_dir: /workspace
|
||||
|
||||
Reference in New Issue
Block a user