fix: 适配新服务器蓝绿部署 — nginx 原生/PostgreSQL Docker 容器名/部署脚本
Some checks failed
Deploy Backend / deploy (push) Has been cancelled

This commit is contained in:
2026-07-13 18:30:33 +08:00
parent 38ee5ccbc6
commit ba00fcb1c6
6 changed files with 101 additions and 78 deletions

View File

@@ -31,7 +31,7 @@ source "${SCRIPT_DIR}/lib/test.sh"
# ---------- 默认值 ----------
PROJECT_NAME="rust-backend"
REMOTE_USER="root"
REMOTE_HOST="1panel-server"
REMOTE_HOST="aliyun-server"
APP_ENV="production"
DRY_RUN=false; SKIP_CONFIRM=false; SKIP_TESTS=false
@@ -65,8 +65,8 @@ while [[ $# -gt 0 ]]; do
echo " --dry-run 预览模式"
echo " --yes, -y 跳过确认"
echo " --skip-tests 跳过部署后测试"
echo " --target blue|green 蓝绿部署目标(默认单实例)"
echo " --remote-host IP 部署目标服务器(默认 1panel-server"
echo " --target blue|green 蓝绿部署目标"
echo " --remote-host IP 部署目标服务器(默认 aliyun-server"
echo " --rollback 回滚到指定备份"
echo " --backup-list 列出可用备份"
echo " --logs [N] 查看后端日志默认50行"
@@ -85,12 +85,15 @@ while [[ $# -gt 0 ]]; do
esac; shift
done
# 提前建立 SSH 连接(蓝绿检测需要 remote()
ssh_connect
# ---------- 蓝绿目标自动检测 + 配置 ----------
# 优先级: 手动 --target > 自动检测
detect_blue_green() {
local proxy_conf; proxy_conf=$(get_proxy_conf)
local active
active=$(remote "docker exec ${NGINX_CONTAINER} cat ${proxy_conf} 2>/dev/null" 2>/dev/null | grep -oP '127\.0\.0\.1:\d+' | head -1 || echo "")
active=$(remote "sudo cat ${proxy_conf} 2>/dev/null" 2>/dev/null | grep -oP '127\.0\.0\.1:\d+' | head -1 || echo "")
case "${APP_ENV}:${active}" in
*:4433) echo "blue" ;;
@@ -133,7 +136,7 @@ case "${APP_ENV}" in
BACKEND_PORT="8080"
fi
TEST_DOMAIN="https://dev.xmclassmate.top"
DB_CONTAINER="1Panel-postgresql-FtMo"
DB_CONTAINER="postgres"
DB_NAME="milkydata_dev"
DB_USER="milkydata" ;;
production)
@@ -147,14 +150,13 @@ case "${APP_ENV}" in
BACKEND_PORT="4433"
fi
TEST_DOMAIN="https://xmclassmate.top"
DB_CONTAINER="1Panel-postgresql-FtMo"
DB_CONTAINER="postgres"
DB_NAME="milkydata"
DB_USER="milkydata" ;;
esac
# ---------- 快捷命令 ----------
GIT_VERSION=$(get_git_info)
ssh_connect
if [ "$LIST_BACKUPS" = true ]; then list_backups; exit 0; fi
if [ "$INIT_ENV" = true ]; then init_env; exit 0; fi