From 7d26a60af54b735f3b79ec23ab0a7549815a53b9 Mon Sep 17 00:00:00 2001 From: OG T Date: Fri, 10 Apr 2026 16:07:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20B5=20=E6=95=B4=E5=90=88=E6=B8=AC?= =?UTF-8?q?=E8=A9=A6=E6=94=B9=E7=94=A8=20docker=20run=20=E2=80=94=20?= =?UTF-8?q?=E8=A7=A3=E6=B1=BA=20Gitea=20act=20services:=20container=20name?= =?UTF-8?q?=20=E7=82=BA=E7=A9=BA=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit services: 宣告在 Gitea act runner 中 container name 為空 改為 step 內直接 docker run pg-test-b5 (port 15433) + 清理 Co-Authored-By: Claude Sonnet 4.6 --- .gitea/workflows/cd.yaml | 43 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index 91427567..36825326 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -47,21 +47,8 @@ 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 + # 2026-04-10 ogt: B5 改用 docker run 本地啟動,移除 services: 宣告 + # Gitea act runner 的 services: container name 為空,導致 CI 失敗 steps: - uses: actions/checkout@v4 @@ -142,20 +129,36 @@ jobs: # B5 整合測試 — postgres-test 由 services: 提供,localhost:15432 直連 # 2026-04-10 Claude Sonnet 4.6: 用 psql 直連 localhost:15432 初始化 schema # (docker exec 在 act runner 內無法取得 service container name) + # B5: Gitea act runner 的 services: 實作與 GitHub Actions 不同 + # service container 啟動後需直連,但 act 的 container name 可能為空 + # 2026-04-10 ogt: 改用 docker run 本地啟動取代 services: 宣告 - name: Integration Tests (B5 — 真實 DB) run: | cd apps/api - # 安裝 psql client (runner 層級持久,首次才裝) + # 安裝 psql client if ! command -v psql &>/dev/null; then apt-get install -y -q postgresql-client fi - # 初始化 schema — 直連 service container (localhost:15432) + # 啟動測試 DB(直接 docker run,避免 services: 容器名稱為空問題) + 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 + done + # 初始化 schema PGPASSWORD=awoooi_test_2026 psql \ - -h localhost -p 15432 -U awoooi -d awoooi_test \ + -h localhost -p 15433 -U awoooi -d awoooi_test \ -f 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" \ + # 跑測試 + TEST_DATABASE_URL="postgresql+asyncpg://awoooi:awoooi_test_2026@localhost:15433/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 - name: Login to Harbor uses: docker/login-action@v3