fix(ci): B5 改用 Gitea Actions services: — 正確的 service container 架構
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 1m50s
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 1m50s
之前所有方案都在對抗 DinD 網路隔離,根本解法是用 services: services.postgres-test 與 runner 同網路,localhost:15432 直連 不再需要 docker compose、docker cp、network connect 等 workaround Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,21 @@ jobs:
|
||||
# 2026-04-02 Claude Code: 加入 timeout 防止 docker build/push 卡住超過 45 分鐘
|
||||
timeout-minutes: 45
|
||||
runs-on: ubuntu-latest
|
||||
# B5 整合測試用 service container — 與 runner 同網路,localhost:15432 可用
|
||||
services:
|
||||
postgres-test:
|
||||
image: pgvector/pgvector:pg16
|
||||
env:
|
||||
POSTGRES_DB: awoooi_test
|
||||
POSTGRES_USER: awoooi
|
||||
POSTGRES_PASSWORD: awoooi_test_2026
|
||||
ports:
|
||||
- 15432:5432
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U awoooi -d awoooi_test"
|
||||
--health-interval 5s
|
||||
--health-timeout 3s
|
||||
--health-retries 10
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -124,32 +139,17 @@ jobs:
|
||||
exit $PYTEST_EXIT
|
||||
|
||||
# ── 整合測試 B5 (2026-04-10) ──────────────────────────────────────────
|
||||
# --network container:postgres-test 共享網路命名空間,localhost:5432 = postgres
|
||||
# B5 整合測試 — postgres-test 由 services: 提供,localhost:15432 直連
|
||||
- name: Integration Tests (B5 — 真實 DB)
|
||||
continue-on-error: true
|
||||
run: |
|
||||
cd apps/api
|
||||
docker compose -f docker-compose.test.yml up -d --wait
|
||||
docker compose -f docker-compose.test.yml exec -T postgres-test \
|
||||
psql -U awoooi -d awoooi_test \
|
||||
< tests/integration/setup_test_schema.sql
|
||||
PG_CONTAINER=$(docker ps --filter name=postgres-test --format '{{.Names}}' | head -1)
|
||||
echo "postgres container: $PG_CONTAINER"
|
||||
# DinD: volume mount 不可靠,用 docker cp 把代碼放進臨時 container
|
||||
# 共享 postgres container 網路命名空間,localhost:5432 直連
|
||||
PYTEST_CTR=$(docker create \
|
||||
--network "container:${PG_CONTAINER}" \
|
||||
-w /workspace \
|
||||
-e TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@localhost:5432/awoooi_test?ssl=disable" \
|
||||
python:3.11-slim \
|
||||
sh -c "pip install -q uv && uv pip install -q --system -e '.[dev]' && pytest tests/integration/test_b5_core_flows.py -v --tb=short")
|
||||
docker cp . "$PYTEST_CTR:/workspace"
|
||||
docker start -a "$PYTEST_CTR"
|
||||
TEST_EXIT=$?
|
||||
docker rm "$PYTEST_CTR" 2>/dev/null || true
|
||||
TEST_EXIT=$?
|
||||
docker compose -f docker-compose.test.yml down -v 2>/dev/null || true
|
||||
exit $TEST_EXIT
|
||||
# 初始化 schema (用 docker exec 進 service container)
|
||||
PG_CTR=$(docker ps --filter name=postgres-test --format '{{.Names}}' | head -1)
|
||||
docker exec -i "$PG_CTR" \
|
||||
psql -U awoooi -d awoooi_test < tests/integration/setup_test_schema.sql
|
||||
# 跑測試 — service container 在同網路,localhost:15432 可連
|
||||
TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@localhost:15432/awoooi_test?ssl=disable" \
|
||||
/opt/api-venv/bin/pytest tests/integration/test_b5_core_flows.py -v --tb=short
|
||||
|
||||
- name: Login to Harbor
|
||||
uses: docker/login-action@v3
|
||||
|
||||
Reference in New Issue
Block a user