fix(ci): B5 簡化網路方案 — 直接用 container IP 不做 network connect
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 7m14s
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 7m14s
network connect 需要 runner container name 不可靠 Gitea runner 在 docker 內本來就能直連同主機 container IP 用 docker inspect 取 IP 直連即可 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -133,24 +133,14 @@ 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
|
||||
# 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 網路內)
|
||||
# 取 postgres container IP — runner 在 docker 內可直連 container IP
|
||||
CONTAINER_NAME=$(docker ps --filter name=postgres-test --format '{{.Names}}' | head -1)
|
||||
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)
|
||||
--format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' | awk '{print $1}')
|
||||
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