92 lines
4.3 KiB
YAML
92 lines
4.3 KiB
YAML
name: VPS Deploy
|
|
# VPS 生产部署(人工 UI 点 Run workflow 或 agent 通过 API dispatch 触发)。
|
|
# 与 ci-cd.yml 分离: ci-cd(push) 只到 NAS 验证; VPS 必须 nas-verify 绿后由此 workflow 主动触发。
|
|
#
|
|
# 严格版本一致: 接收 sha input, checkout 该 commit(= NAS 验证通过的那个), 部署到 VPS。
|
|
# 不会部署 nas-verify 未验证过的代码。
|
|
#
|
|
# 触发方式:
|
|
# 人工: Gitea → Actions → vps-deploy.yml → Run workflow → 填 sha(NAS 验证通过的 commit)
|
|
# agent: MCP dispatch_workflow workflow_id=vps-deploy.yml ref=master inputs={sha:<full-sha>}
|
|
# 或 curl POST /api/v1/repos/sanguo/sanguo_vnpy_v2/actions/workflows/vps-deploy.yml/dispatches
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
sha:
|
|
description: "NAS 验证通过的 commit SHA(完整 40 位, ci-cd 的 nas-verify 输出)"
|
|
required: true
|
|
type: string
|
|
|
|
jobs:
|
|
vps:
|
|
runs-on: macos-arm64
|
|
env:
|
|
HOME: /Users/chufeng
|
|
steps:
|
|
- name: checkout 指定 commit(= NAS 验证通过的版本)
|
|
env:
|
|
TOKEN: ${{ github.token }}
|
|
run: |
|
|
set -e
|
|
SHA="${{ inputs.sha }}"
|
|
git init .
|
|
git config --local http.proxy ""
|
|
git config --local https.proxy ""
|
|
git remote add origin "http://oauth2:${TOKEN}@192.168.2.154:3000/${GITHUB_REPOSITORY}.git"
|
|
git fetch --depth 1 origin "$SHA"
|
|
git checkout FETCH_HEAD
|
|
echo "部署 commit: $(git rev-parse HEAD)"
|
|
- name: promote 代码到 VPS (只推 VPS, 不动 NAS)
|
|
run: bash scripts/nas_sync/promote.sh --target vps
|
|
- name: VPS 冒烟 (LocalUnifiedProvider 真数据)
|
|
run: ssh 49.232.102.198 'cd C:\sanguo_vnpy_v2 && C:\Python310\python.exe -X utf8 scripts/data_platform/verify_unified_e2e.py'
|
|
- name: 前端构建 + 推 dist 到 VPS (公网前端无管线, 此处补齐)
|
|
run: |
|
|
set -e
|
|
cd frontend
|
|
npm ci
|
|
npm run build
|
|
cd ..
|
|
tar czf /tmp/dist_latest.tgz -C frontend/dist .
|
|
scp -o ConnectTimeout=20 /tmp/dist_latest.tgz 49.232.102.198:C:/sanguo_vnpy_v2/dist_latest.tgz
|
|
- name: VPS 替换 dist + 重启 sanguo-api (等端口释放防 10048 竞态, 再等起服)
|
|
run: |
|
|
set -e
|
|
ssh 49.232.102.198 'C:\Python310\python.exe -X utf8 C:\sanguo_vnpy_v2\scripts\nas_sync\vps_update_dist.py' | tee /tmp/dist_swap.log
|
|
grep -q DIST_UPDATE_DONE /tmp/dist_swap.log
|
|
# 停 API → 等端口彻底释放(旧实例被杀后端口有滞留, 立即重启会 10048 静默崩)
|
|
ssh 49.232.102.198 'schtasks /end /tn sanguo-api' || true
|
|
for i in $(seq 1 30); do
|
|
ssh 49.232.102.198 'netstat -ano -p tcp' | tr -d '\r' | grep -q ':8000.*LISTEN' || { echo "port freed after $((i*2))s"; break; }
|
|
sleep 2
|
|
done
|
|
ssh 49.232.102.198 'schtasks /run /tn sanguo-api'
|
|
# 等新实例监听 + /docs 可用(VPS 启动需数分钟, 上限 10 分钟)
|
|
for i in $(seq 1 60); do
|
|
if ssh 49.232.102.198 'netstat -ano -p tcp' | tr -d '\r' | grep -q ':8000.*LISTEN'; then
|
|
echo "API listening after ~$((i*10))s"; break
|
|
fi
|
|
sleep 10
|
|
if [ "$i" = "60" ]; then echo "API 10 分钟未监听 8000"; exit 1; fi
|
|
done
|
|
for i in $(seq 1 12); do
|
|
ssh 49.232.102.198 'powershell -NoProfile -Command "(Invoke-WebRequest -UseBasicParsing http://127.0.0.1:8000/docs).StatusCode"' 2>/dev/null | grep -q 200 && { echo "API /docs 200"; exit 0; }
|
|
sleep 10
|
|
done
|
|
echo "API 监听但 /docs 2 分钟未返回 200"; exit 1
|
|
- name: mark vps-deployed tag (VPS 版本真相, session 用 git log vps-deployed..HEAD 查未部署)
|
|
env:
|
|
TOKEN: ${{ github.token }}
|
|
run: |
|
|
set -e
|
|
SHA="${{ inputs.sha }}"
|
|
git tag -f vps-deployed "$SHA"
|
|
git push -f "http://oauth2:${TOKEN}@192.168.2.154:3000/${GITHUB_REPOSITORY}.git" refs/tags/vps-deployed
|
|
echo "✅ vps-deployed → ${SHA::7}"
|
|
- name: 关闭 [待推VPS] issue (tag=HEAD → gap 清空 = 绿)
|
|
env:
|
|
GTOKEN: ${{ github.token }}
|
|
run: |
|
|
export VPS_LOG=""
|
|
python3 scripts/ci/vps_pending_check.py
|