优化: Keep-Alive/rate-limiter/dead-code清理 + deploy.sh蓝绿自动检测 + 压测文档
This commit is contained in:
53
deploy.sh
53
deploy.sh
@@ -2,6 +2,8 @@
|
||||
# ===========================================
|
||||
# Rust Backend Deployment Script
|
||||
# ===========================================
|
||||
# Rust Backend Deployment Script
|
||||
# ===========================================
|
||||
# Usage: ./deploy.sh [development|production] [options]
|
||||
#
|
||||
# Options:
|
||||
@@ -16,6 +18,7 @@
|
||||
# --post-logs 部署后显示日志
|
||||
# --init-env 初始化 systemd service 模板
|
||||
# --deploy-service 上传 systemd service 文件到服务器
|
||||
# --target blue|green 蓝绿部署目标(默认单实例)
|
||||
# ===========================================
|
||||
|
||||
set -euo pipefail
|
||||
@@ -60,7 +63,7 @@ while [[ $# -gt 0 ]]; do
|
||||
echo " --dry-run 预览模式"
|
||||
echo " --yes, -y 跳过确认"
|
||||
echo " --skip-tests 跳过部署后测试"
|
||||
echo " --target blue|green 蓝绿部署目标(仅 production)"
|
||||
echo " --target blue|green 蓝绿部署目标(默认单实例)"
|
||||
echo " --rollback 回滚到指定备份"
|
||||
echo " --backup-list 列出可用备份"
|
||||
echo " --logs [N] 查看后端日志(默认50行)"
|
||||
@@ -79,11 +82,37 @@ while [[ $# -gt 0 ]]; do
|
||||
esac; shift
|
||||
done
|
||||
|
||||
# ---------- 蓝绿目标检测 ----------
|
||||
if [ "${APP_ENV}" = "production" ] && [ -n "$BG_TARGET" ]; then
|
||||
case "$BG_TARGET" in
|
||||
blue) BG_PORT="4433"; BG_DIR="rust_backend_blue"; BG_SVC="rust-backend-blue.service" ;;
|
||||
green) BG_PORT="4434"; BG_DIR="rust_backend_green"; BG_SVC="rust-backend-green.service" ;;
|
||||
# ---------- 蓝绿目标自动检测 + 配置 ----------
|
||||
# 优先级: 手动 --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 "")
|
||||
|
||||
case "${APP_ENV}:${active}" in
|
||||
*:4433) echo "blue" ;;
|
||||
*:4434) echo "green" ;;
|
||||
*:8083) echo "blue" ;;
|
||||
*:8084) echo "green" ;;
|
||||
*) echo "" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ -z "$BG_TARGET" ] && [ "${APP_ENV}" = "production" ]; then
|
||||
# 自动检测:部署到待命环境(仅生产环境支持蓝绿)
|
||||
active_target=$(detect_blue_green)
|
||||
if [ -n "$active_target" ]; then
|
||||
BG_TARGET=$([ "$active_target" = "blue" ] && echo "green" || echo "blue")
|
||||
log_info "自动检测: 当前活动 ${active_target},部署到 ${BG_TARGET}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$BG_TARGET" ]; then
|
||||
case "${APP_ENV}:${BG_TARGET}" in
|
||||
production:blue) BG_PORT="4433"; BG_DIR="rust_backend_blue"; BG_SVC="rust-backend-blue.service" ;;
|
||||
production:green) BG_PORT="4434"; BG_DIR="rust_backend_green"; BG_SVC="rust-backend-green.service" ;;
|
||||
development:blue) BG_PORT="8083"; BG_DIR="rust_backend_dev_blue"; BG_SVC="rust-backend-dev-blue.service" ;;
|
||||
development:green)BG_PORT="8084"; BG_DIR="rust_backend_dev_green";BG_SVC="rust-backend-dev-green.service" ;;
|
||||
*) echo "错误: --target 只能是 blue 或 green"; exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
@@ -91,10 +120,16 @@ fi
|
||||
# ---------- 环境配置 ----------
|
||||
case "${APP_ENV}" in
|
||||
development)
|
||||
REMOTE_DIR="/root/rust/rust_backend_dev"
|
||||
SERVICE_NAME="rust-backend-dev.service"
|
||||
if [ -n "$BG_TARGET" ]; then
|
||||
REMOTE_DIR="/root/rust/${BG_DIR}"
|
||||
SERVICE_NAME="${BG_SVC}"
|
||||
BACKEND_PORT="${BG_PORT}"
|
||||
else
|
||||
REMOTE_DIR="/root/rust/rust_backend_dev"
|
||||
SERVICE_NAME="rust-backend-dev.service"
|
||||
BACKEND_PORT="8080"
|
||||
fi
|
||||
TEST_DOMAIN="https://dev.xmclassmate.top"
|
||||
BACKEND_PORT="8080"
|
||||
DB_CONTAINER="1Panel-postgresql-FtMo"
|
||||
DB_NAME="milkydata_dev"
|
||||
DB_USER="milkydata" ;;
|
||||
|
||||
Reference in New Issue
Block a user