fix(cd): B5 測試改用 container IP,解決 DinD port mapping 問題
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 2m1s
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 2m1s
act runner 內 -p 15433:5432 的 localhost 不通 改用 docker inspect 取 container IP 直連 5432 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -139,23 +139,26 @@ jobs:
|
||||
if ! command -v psql &>/dev/null; then
|
||||
apt-get install -y -q postgresql-client
|
||||
fi
|
||||
# 啟動測試 DB(直接 docker run,避免 services: 容器名稱為空問題)
|
||||
# 啟動測試 DB — 用 container IP 直連,避免 DinD port mapping 問題
|
||||
# 2026-04-10 Claude Sonnet 4.6: -p 15433:5432 在 act runner 內 localhost 不通
|
||||
docker run -d --name pg-test-b5 \
|
||||
-e POSTGRES_DB=awoooi_test \
|
||||
-e POSTGRES_USER=awoooi \
|
||||
-e POSTGRES_PASSWORD=awoooi_test_2026 \
|
||||
-p 15433:5432 \
|
||||
pgvector/pgvector:pg16
|
||||
# 等待就緒
|
||||
for i in $(seq 1 20); do
|
||||
PGPASSWORD=awoooi_test_2026 pg_isready -h localhost -p 15433 -U awoooi && break || sleep 2
|
||||
# 取得 container IP
|
||||
PG_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pg-test-b5)
|
||||
echo "PG container IP: $PG_IP"
|
||||
# 等待就緒(用 container IP,最多 60 秒)
|
||||
for i in $(seq 1 30); do
|
||||
PGPASSWORD=awoooi_test_2026 pg_isready -h "$PG_IP" -p 5432 -U awoooi && break || sleep 2
|
||||
done
|
||||
# 初始化 schema
|
||||
PGPASSWORD=awoooi_test_2026 psql \
|
||||
-h localhost -p 15433 -U awoooi -d awoooi_test \
|
||||
-h "$PG_IP" -p 5432 -U awoooi -d awoooi_test \
|
||||
-f tests/integration/setup_test_schema.sql
|
||||
# 跑測試
|
||||
TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@localhost:15433/awoooi_test?ssl=disable" \
|
||||
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
|
||||
# 清理
|
||||
docker rm -f pg-test-b5 || true
|
||||
|
||||
Reference in New Issue
Block a user