fix(ci): 增加PG/Redis端口连通性检查,解决容器healthy但映射端口连不上的问题
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m6s
AI Code Review / AI Code Review (pull_request) Successful in 3m10s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m49s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 6m50s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 33s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 1409h47m48s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1409h48m4s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1409h48m5s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1409h48m6s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1409h48m5s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1409h48m6s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 1409h48m9s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1409h48m7s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1409h48m7s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1409h48m8s
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1410h20m16s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1410h20m9s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1410h20m13s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m6s
AI Code Review / AI Code Review (pull_request) Successful in 3m10s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m49s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 6m50s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 33s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 1409h47m48s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1409h48m4s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1409h48m5s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1409h48m6s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1409h48m5s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1409h48m6s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 1409h48m9s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1409h48m7s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1409h48m7s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1409h48m8s
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1410h20m16s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1410h20m9s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1410h20m13s
- run_validate.sh: PG健康检查后增加TCP连通性确认 - run_integration_tests.sh: PG和Redis都增加TCP连通性确认 - 解决docker端口映射延迟导致alembic迁移/测试连接失败的偶发问题
This commit is contained in:
@@ -44,6 +44,17 @@ for i in $(seq 1 15); do
|
||||
done
|
||||
docker inspect --format='{{.State.Health.Status}}' "$REDIS_CONTAINER" | grep -q healthy
|
||||
|
||||
# 额外验证:确保从宿主侧通过映射端口实际能连上 Redis
|
||||
for i in $(seq 1 20); do
|
||||
if python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $REDIS_PORT)); s.close()" 2>/dev/null; then
|
||||
echo "TCP connectivity to Redis confirmed on port $REDIS_PORT"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for TCP connectivity to Redis on port $REDIS_PORT... ($i/20)"
|
||||
sleep 2
|
||||
done
|
||||
python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $REDIS_PORT)); s.close()"
|
||||
|
||||
# --- 启动 PostgreSQL ---
|
||||
echo ""
|
||||
echo "=== 启动 PostgreSQL ==="
|
||||
@@ -73,6 +84,17 @@ for i in $(seq 1 30); do
|
||||
done
|
||||
docker inspect --format='{{.State.Health.Status}}' "$PG_CONTAINER" | grep -q healthy
|
||||
|
||||
# 额外验证:确保从宿主侧通过映射端口实际能连上 PG(端口映射可能有延迟)
|
||||
for i in $(seq 1 30); do
|
||||
if python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()" 2>/dev/null; then
|
||||
echo "TCP connectivity to PostgreSQL confirmed on port $PG_PORT"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for TCP connectivity to PostgreSQL on port $PG_PORT... ($i/30)"
|
||||
sleep 2
|
||||
done
|
||||
python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()"
|
||||
|
||||
# --- 执行迁移 ---
|
||||
echo ""
|
||||
echo "=== 执行 Alembic 迁移 ==="
|
||||
|
||||
@@ -196,6 +196,18 @@ for i in $(seq 1 30); do
|
||||
sleep 2
|
||||
done
|
||||
docker inspect --format='{{.State.Health.Status}}' "$PG_CONTAINER" | grep -q healthy
|
||||
|
||||
# 额外验证:确保从宿主侧通过映射端口实际能连上(端口映射可能有延迟)
|
||||
for i in $(seq 1 30); do
|
||||
if python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()" 2>/dev/null; then
|
||||
echo "TCP connectivity to PostgreSQL confirmed on port $PG_PORT"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for TCP connectivity to PostgreSQL on port $PG_PORT... ($i/30)"
|
||||
sleep 2
|
||||
done
|
||||
python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()"
|
||||
|
||||
PYTHONPATH="$PWD/apps/api:$PWD" python3 -m alembic upgrade head
|
||||
echo "✅ Alembic migrations applied successfully"
|
||||
docker rm -f "$PG_CONTAINER" 2>/dev/null || true
|
||||
|
||||
Reference in New Issue
Block a user