fix(ci): 增加PG/Redis端口连通性检查,解决容器healthy但映射端口连不上 (#615)
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Successful in 45s
CI/CD Pipeline / Frontend Lint (push) Successful in 5m20s
CI/CD Pipeline / Unit Tests (push) Successful in 5m32s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m50s
CI/CD Pipeline / Build Staging API Image (push) Successful in 6m2s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 6m7s
CI/CD Pipeline / Integration Tests (push) Successful in 1m34s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 8m15s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 46s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 34s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 2m10s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 5m23s
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Successful in 45s
CI/CD Pipeline / Frontend Lint (push) Successful in 5m20s
CI/CD Pipeline / Unit Tests (push) Successful in 5m32s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m50s
CI/CD Pipeline / Build Staging API Image (push) Successful in 6m2s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 6m7s
CI/CD Pipeline / Integration Tests (push) Successful in 1m34s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 8m15s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 46s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 34s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 2m10s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 5m23s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
This commit was merged in pull request #615.
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