fix(deploy): align deployment with split infrastructure

This commit is contained in:
Xiaoxia AI
2026-06-20 19:02:48 +08:00
parent 751d0edbba
commit d31c62d4e2
8 changed files with 78 additions and 12 deletions
+2 -2
View File
@@ -69,7 +69,7 @@ jobs:
set -eu
i=0
while [ "$i" -lt 30 ]; do
if wget -qO- http://127.0.0.1:8000/api/v1/health; then
if wget -qO- http://127.0.0.1:8000/health; then
exit 0
fi
i=$((i + 1))
@@ -139,7 +139,7 @@ jobs:
set -eu
i=0
while [ "$i" -lt 30 ]; do
if wget -qO- http://127.0.0.1:8000/api/v1/health; then
if wget -qO- http://127.0.0.1:8000/health; then
exit 0
fi
i=$((i + 1))
+4
View File
@@ -131,6 +131,10 @@ class OSSStorageService:
return self.bucket.object_exists(storage_key)
# 向后兼容的服务类名
MinIOService = OSSStorageService
_storage_service = None
+2 -2
View File
@@ -17,7 +17,7 @@ services:
networks:
- xiaoxia-net
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://localhost:8000/api/v1/health"]
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)"]
interval: 30s
timeout: 10s
retries: 3
@@ -49,7 +49,7 @@ services:
networks:
- xiaoxia-net
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://localhost:80"]
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:80"]
interval: 30s
timeout: 5s
retries: 3
+19 -2
View File
@@ -1,20 +1,37 @@
#!/bin/sh
set -eu
# 容器内路径(通过 -v /:/host 映射)
ROOT_DIR="/host/var/lib/xiaoxia-saas-production/repo"
COMPOSE_DIR="$ROOT_DIR/infra/docker"
ENV_FILE="/host/var/lib/xiaoxia-saas-production/.env"
ensure_container_running() {
name="$1"
if ! docker inspect "$name" >/dev/null 2>&1; then
echo "❌ Required infrastructure container not found: $name"
echo " Run infra/docker/infra.yml first before deploying applications."
exit 1
fi
state="$(docker inspect -f '{{.State.Status}}' "$name")"
if [ "$state" != "running" ]; then
echo "❌ Required infrastructure container is not running: $name ($state)"
exit 1
fi
}
cd "$ROOT_DIR"
cp "$ENV_FILE" "$ROOT_DIR/.env"
mkdir -p "$ROOT_DIR/apps/web/public"
[ -f "$ROOT_DIR/apps/web/public/.keep" ] || printf 'placeholder' > "$ROOT_DIR/apps/web/public/.keep"
ensure_container_running xiaoxia-postgres
ensure_container_running xiaoxia-redis
cd "$COMPOSE_DIR"
WEB_PORT="${WEB_PORT:-3001}"
export WEB_PORT
docker compose build api worker web
docker compose up -d postgres redis api worker web
docker compose up -d api worker web
docker compose ps
+19 -2
View File
@@ -1,20 +1,37 @@
#!/bin/sh
set -eu
# 容器内路径(通过 -v /:/host 映射)
ROOT_DIR="/host/var/lib/xiaoxia-saas-staging/repo"
COMPOSE_DIR="$ROOT_DIR/infra/docker"
ENV_FILE="/host/var/lib/xiaoxia-saas-staging/.env"
ensure_container_running() {
name="$1"
if ! docker inspect "$name" >/dev/null 2>&1; then
echo "❌ Required infrastructure container not found: $name"
echo " Run infra/docker/infra.yml first before deploying applications."
exit 1
fi
state="$(docker inspect -f '{{.State.Status}}' "$name")"
if [ "$state" != "running" ]; then
echo "❌ Required infrastructure container is not running: $name ($state)"
exit 1
fi
}
cd "$ROOT_DIR"
cp "$ENV_FILE" "$ROOT_DIR/.env"
mkdir -p "$ROOT_DIR/apps/web/public"
[ -f "$ROOT_DIR/apps/web/public/.keep" ] || printf 'placeholder' > "$ROOT_DIR/apps/web/public/.keep"
ensure_container_running xiaoxia-postgres
ensure_container_running xiaoxia-redis
cd "$COMPOSE_DIR"
WEB_PORT="${WEB_PORT:-3001}"
export WEB_PORT
docker compose build api worker web
docker compose up -d postgres redis api worker web
docker compose up -d api worker web
docker compose ps
+29 -1
View File
@@ -24,7 +24,35 @@ server {
# SaaS API
location /api/ {
proxy_pass http://127.0.0.1:8000/api/;
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# API health and documentation
location = /health {
proxy_pass http://127.0.0.1:8000/health;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /docs {
proxy_pass http://127.0.0.1:8000/docs;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /openapi.json {
proxy_pass http://127.0.0.1:8000/openapi.json;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
+2 -2
View File
@@ -15,7 +15,7 @@ docker compose up -d --no-deps api worker web
# 4. 健康检查
echo "⏳ 等待服务启动..."
for i in {1..30}; do
if docker exec xiaoxia-api-staging wget -q --spider http://localhost:8000/api/v1/health 2>/dev/null; then
if docker exec xiaoxia-api-staging wget -q --spider http://localhost:8000/health 2>/dev/null; then
echo "✅ API 健康检查通过"
break
fi
@@ -37,7 +37,7 @@ echo "✅ 部署完成!"
echo ""
echo "📍 服务访问地址:"
echo " Web: https://api.xiaoxiajianji.com"
echo " API: https://api.xiaoxiajianji.com/api/v1/docs"
echo " API: https://api.xiaoxiajianji.com/docs"
echo ""
echo "📊 容器状态:"
docker compose ps
+1 -1
View File
@@ -9,7 +9,7 @@ pydantic-settings==2.6.0
# 数据库
psycopg2-binary==2.9.9
psycopg==3.1.18
psycopg[binary]==3.1.18
sqlalchemy==2.0.35
# 认证