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

@@ -556,23 +556,36 @@ let new_expires = base_time + days(pkg_days);
| 环境 | 域名 | 端口 | 远程目录 |
|------|------|------|---------|
| 测试 | dev.xmclassmate.top | 8080 | /root/rust/rust_backend_dev |
| 生产 | xmclassmate.top | 4433 | /root/rust/rust_backend |
| 生产(蓝) | xmclassmate.top | 4433 | /root/rust/rust_backend_blue |
| 生产(绿) | xmclassmate.top | 4434 | /root/rust/rust_backend_green |
**服务器**`47.109.203.92` (Aliyun, Debian 13)
**SSH 用户**`deploy`(有 sudo 权限)
**SSH 别名**`aliyun-server``~/.ssh/config` 中配置)
**nginx**:原生 nginx非 Docker/OpenResty配置位于 `/etc/nginx/sites-available/`
**PostgreSQL**Docker 容器 `postgres:17.6-alpine`host 网络模式)
### systemd 服务
| 环境 | systemd unit | 工作目录 | APP_ENV |
|------|-------------|---------|---------|
| 测试 | `rust-backend-dev.service` | `/root/rust/rust_backend_dev` | `development` |
| 生产 | `rust-backend.service` | `/root/rust/rust_backend` | (使用 .env) |
| 环境 | systemd unit | 工作目录 | SERVER_PORT |
|------|-------------|---------|-------------|
| 测试 | `rust-backend-dev.service` | `/root/rust/rust_backend_dev` | 8080 |
| 生产 | `rust-backend-blue.service` | `/root/rust/rust_backend_blue` | 4433 |
| 生产绿 | `rust-backend-green.service` | `/root/rust/rust_backend_green` | 4434 |
> ⚠️ systemd 配置使用 `EnvironmentFile=` 加载 `.env` 文件(生产、开发环境均如此)
> 生产采用蓝绿部署nginx 通过 `proxy_pass` 将流量路由到活跃环境(默认 :4433 = 蓝色)。
> `deploy.sh` 自动检测活跃环境并部署到空闲环境,部署成功后自动切换 nginx 代理。
> ⚠️ systemd 配置使用 `Environment=` 直接加载环境变量(非 `EnvironmentFile`)。
> 注意:`EnvironmentFile` 不支持多行值,多行 PEM 密钥需 base64 编码或单行格式
### 部署命令
```bash
./deploy.sh development # 部署到测试服务器
./deploy.sh production # 部署到生产服务器
./deploy.sh development # 部署到测试服务器
./deploy.sh production # 生产蓝绿部署(自动检测目标)
./deploy.sh production --target blue # 指定部署到蓝色
./deploy.sh production --target green # 指定部署到绿色
```
**deploy.sh 选项:**
@@ -584,6 +597,8 @@ let new_expires = base_time + days(pkg_days);
| `--skip-tests` | 跳过部署后测试 |
| `--rollback` | 回滚到上一个备份版本 |
| `--backup-list` | 列出可用备份 |
| `--target blue\|green` | 蓝绿部署目标 |
| `--remote-host IP` | 部署目标服务器(默认 `aliyun-server` |
| `--init-env` | 初始化远程 .env生成随机 JWT_SECRET + 推送模板到服务器) |
| `--help, -h` | 显示帮助信息 |