Files
xiaoxia-saas/scripts/rollback.sh
xiaoxia-bot 34336b2907
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 39s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m12s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m51s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m25s
feat(ci): 新增发布与灰度部署脚本
- release.sh: 一键发布脚本(打tag + 触发CI构建 + 灰度提示)
- gray_deploy.sh: 灰度发布脚本(canary容器 + nginx权重切流)
- rollback_gray.sh: 灰度回滚脚本(nginx回滚 + canary清理)
- 更新 rollback.sh 占位符为生产环境适配版

灰度范围:API + Web(Nginx upstream 权重)
Worker 暂不支持灰度(队列消费无法按比例切流)
2026-07-14 13:09:27 +08:00

43 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# 灰度回滚脚本:切回稳定版本流量
# 用法: ./scripts/rollback.sh [稳定版本号]
set -euo pipefail
STABLE_VERSION="${1:-current}"
echo "=========================================="
echo " 灰度回滚"
echo " 切回稳定版本: $STABLE_VERSION"
echo "=========================================="
# 1. 恢复Nginx全量到稳定版本
echo ""
echo ">>> 恢复Nginx全量流量到稳定版本..."
NGINX_CONF="${NGINX_CONF:-/etc/nginx/conf.d/saas-api.conf}"
if [[ -f "$NGINX_CONF" ]]; then
# 找最近的备份
LATEST_BAK=$(ls -t "${NGINX_CONF}".bak.* 2>/dev/null | head -1)
if [[ -n "$LATEST_BAK" ]]; then
cp "$LATEST_BAK" "$NGINX_CONF"
echo " 从备份恢复: $LATEST_BAK"
else
echo " 未找到备份,请手动移除 canary upstream"
fi
nginx -t && nginx -s reload
echo " ✅ Nginx 已回滚"
fi
# 2. 停止灰度版本容器(保留30分钟以便排查)
echo ""
echo ">>> 灰度版本容器将在30分钟后停止(便于排查问题)"
echo " 立即停止请执行: docker stop saas-api-canary saas-worker-canary"
echo ""
echo "=========================================="
echo " ✅ 回滚完成"
echo " 流量已全部切回稳定版本"
echo "=========================================="