Files
cma-management/.woodpecker/main.yml
T
opsBot b7950249a7 fix(deploy): 冒烟就绪轮询判据 HTTP200+status=ok,替代固定 sleep(消除冷启动假告警)
- deploy.sh: 轮询块(0.5s 间隔 / 默认 30s 上限),超时明确报错 + exit 非 0;
  SMOKE_HEALTH_URL/SMOKE_READY_MAX 可覆盖供离线演练;带 >>> cma-readiness-poll 标记便于抽取复用
- .woodpecker/main.yml backend-deploy: 同样去掉固定 sleep 3,改就绪轮询
- 验收: 离线演练 A(冷启动6s成功)/B(空端口超时非0)/C(200+degraded不误判)
- task: t2-cma-deploy-readiness-poll-20260915
2026-09-15 17:04:22 +08:00

75 lines
2.6 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
when:
- branch: main
event: push
variables:
- &ssh_setup |
apk add --no-cache openssh-client rsync
mkdir -p ~/.ssh
echo "$SSH_DEPLOY_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H git.sxbh.ltd >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
steps:
frontend-install:
image: node:20-alpine
commands:
- apk add --no-cache git
- cd frontend
- npm install -g pnpm
- pnpm install
when:
- path: frontend/**
frontend-typecheck:
image: node:20-alpine
commands:
- cd frontend
- npm install -g pnpm
- pnpm install
- pnpm vue-tsc --noEmit || true
when:
- path: frontend/**
frontend-build:
image: node:20-alpine
commands:
- cd frontend
- npm install -g pnpm
- pnpm install
- pnpm build
when:
- path: frontend/**
backend-test:
image: python:3.12
commands:
- cd backend
- pip install -r requirements.txt --quiet
- python -m pytest tests/ -x -q --disable-warnings --timeout=60 || true
when:
- path: backend/**
frontend-deploy:
image: alpine:latest
secrets:
- SSH_DEPLOY_KEY
commands:
- *ssh_setup
- rsync -avz --delete frontend/dist/ root@git.sxbh.ltd:/var/www/cma/
- ssh root@git.sxbh.ltd 'nginx -s reload || systemctl reload nginx'
when:
- path: frontend/**
backend-deploy:
image: alpine:latest
secrets:
- SSH_DEPLOY_KEY
commands:
- *ssh_setup
- |
ssh root@git.sxbh.ltd 'set -e; cd /root/cma-management; DIRTY=$(git status --porcelain 2>/dev/null | grep -v "__pycache__" | head -10); if [ -n "$DIRTY" ]; then echo "❌ 宿主机有未提交修改,中止部署:"; echo "$DIRTY"; exit 1; fi; git pull origin main; cd backend; pip install -r requirements.txt --quiet --no-cache-dir; systemctl restart cma-backend; SMOKE_READY_MAX="${SMOKE_READY_MAX:-30}"; READY_TRY=0; READY_OK=0; READY_BODY=/tmp/cma-ci-ready-body.json; while [ "$READY_TRY" -lt $(( SMOKE_READY_MAX * 2 )) ]; do CODE=$(curl -s -o "$READY_BODY" -w "%{http_code}" --max-time 2 http://127.0.0.1:8010/health || echo 000); if [ "$CODE" = "200" ] && grep -q "\"status\":\"ok\"" "$READY_BODY" 2>/dev/null; then READY_OK=1; break; fi; sleep 0.5; READY_TRY=$(( READY_TRY + 1 )); done; if [ "$READY_OK" != "1" ]; then echo "🚨 后端就绪超时 ${SMOKE_READY_MAX}s(未达 HTTP200 + status=ok)"; cat "$READY_BODY" 2>/dev/null; exit 1; fi; echo "✅ 后端就绪(轮询 ${READY_TRY} 次,上限 ${SMOKE_READY_MAX}s)"; cat "$READY_BODY"'
when:
- path: backend/**