This commit is contained in:
zuowei1216
2025-12-22 21:06:29 +08:00
parent 8ea58fe480
commit 1b19ff1b92
179 changed files with 21895 additions and 3774 deletions

251
tempdocs/部署指南.md Normal file
View File

@@ -0,0 +1,251 @@
# 🚀 DesignerCEP 完整部署指南
## 📊 最终架构
```
app.aidg168.uk → 前端应用Caddy 静态文件)
backend.aidg168.uk → 后端 APIFastAPI + MySQL
```
---
## 📁 项目目录结构
```
DesignerCEP/
├── Designer/ ← 前端源代码
│ ├── src/ ← Vue 源码
│ ├── dist_core/ ← ⭐ 构建输出(需要复制到 Server
│ ├── package.json
│ └── vite.config.ts
├── Server/ ← 后端 + 部署配置
│ ├── app/ ← 后端代码FastAPI
│ │ ├── api/ ← API 路由
│ │ ├── models/ ← 数据模型
│ │ └── main.py ← 入口文件
│ │
│ ├── static/ ← ⭐ 前端文件放这里
│ │ └── app/ ← ⭐ Designer/dist_core/ 复制到这里
│ │ ├── index.html
│ │ ├── assets/
│ │ └── ...
│ │
│ ├── archives/ ← Core 版本压缩包
│ ├── docker-compose.yml ← Docker 配置
│ ├── Dockerfile ← 后端镜像
│ ├── requirements.txt ← Python 依赖
│ └── mysql.cnf ← MySQL 配置
├── Caddyfile ← Caddy 配置
└── AdminTool/ ← 自动化部署工具
```
---
## 🔧 本地准备(您现在要做的)
### 步骤 1构建前端
```bash
cd Designer
npm install
npm run build:core
```
**输出**`Designer/dist_core/` 目录
### 步骤 2复制前端到 Server
```powershell
# 在项目根目录执行
xcopy /E /Y Designer\dist_core\* Server\static\app\
```
**验证**
```bash
dir Server\static\app\
# 应该看到:
# - index-core.html
# - assets/
# - CSInterface.js
# - vite.svg
```
### 步骤 3配置环境变量
复制 `Server/.env.example``Server/.env`,并修改:
```env
ENV=production
SECRET_KEY=修改为随机密钥
ALLOWED_ORIGINS=https://app.aidg168.uk,https://backend.aidg168.uk
SMTP_USER=您的邮箱
SMTP_PASSWORD=您的邮箱密码
```
---
## 📤 上传到服务器
### 方法 A打包上传推荐
```powershell
# 1. 压缩 Server 文件夹
Compress-Archive -Path Server\* -DestinationPath DesignerCEP-Server.zip
# 2. 上传到服务器
scp DesignerCEP-Server.zip root@103.97.201.136:/root/
# 3. 上传 Caddyfile
scp Caddyfile root@103.97.201.136:/etc/caddy/Caddyfile
```
### 方法 B使用自动化脚本
```bash
cd AdminTool
python auto_deploy_core.py --version 1.0.0 --deploy
```
---
## 🐳 服务器部署
### SSH 登录服务器
```bash
ssh root@103.97.201.136
```
### 步骤 1解压文件
```bash
cd /root
unzip DesignerCEP-Server.zip -d /var/www/DesignerCEP/Server
cd /var/www/DesignerCEP/Server
```
### 步骤 2配置 Caddy
```bash
# Caddyfile 已上传到 /etc/caddy/Caddyfile
# 验证配置
caddy validate --config /etc/caddy/Caddyfile
# 重启 Caddy
systemctl restart caddy
systemctl status caddy
```
### 步骤 3启动 Docker 服务
```bash
cd /var/www/DesignerCEP/Server
# 启动所有服务Caddy + FastAPI + MySQL
docker-compose up -d
# 查看日志
docker-compose logs -f
# 查看运行状态
docker-compose ps
```
---
## ✅ 验证部署
### 1. 检查服务状态
```bash
# Caddy
systemctl status caddy
# Docker 服务
docker-compose ps
```
### 2. 测试 API
```bash
curl https://backend.aidg168.uk/health
# 期望:{"status":"healthy"}
```
### 3. 测试前端
浏览器访问:
```
https://app.aidg168.uk/
```
**期望**:能看到登录页面
---
## 📋 完整部署清单
- [ ] 前端已构建:`Designer/dist_core/`
- [ ] 前端已复制到:`Server/static/app/`
- [ ] Server 文件夹已打包
- [ ] Caddyfile 已上传到服务器
- [ ] Server 已上传并解压
- [ ] `.env` 已配置
- [ ] Caddy 已重启
- [ ] Docker 服务已启动
- [ ] `https://app.aidg168.uk/` 可访问
- [ ] `https://backend.aidg168.uk/health` 可访问
---
## 🎯 快速命令汇总
### 本地准备
```powershell
# 1. 构建前端
cd Designer
npm run build:core
# 2. 复制前端到 Server
cd ..
xcopy /E /Y Designer\dist_core\* Server\static\app\
# 3. 检查文件
dir Server\static\app\
# 4. 打包 Server
Compress-Archive -Path Server\* -DestinationPath Server.zip
```
### 服务器部署
```bash
# 1. 上传文件
scp Server.zip root@103.97.201.136:/root/
scp Caddyfile root@103.97.201.136:/etc/caddy/Caddyfile
# 2. SSH 登录
ssh root@103.97.201.136
# 3. 解压并部署
cd /root
unzip Server.zip -d /var/www/DesignerCEP/Server
cd /var/www/DesignerCEP/Server
# 4. 启动服务
systemctl restart caddy
docker-compose up -d
# 5. 查看日志
docker-compose logs -f
```
---
**完成后访问 https://app.aidg168.uk/ 测试!** 🎉