chore: harden build and deployment workflow

This commit is contained in:
237899745
2026-07-27 13:07:14 +08:00
parent 6692736e88
commit f5377e51bb
10 changed files with 408 additions and 71 deletions

View File

@@ -10,7 +10,7 @@
- **磁盘空间**: 至少 2GB 可用空间
### 软件依赖
- **Node.js**: 20.x LTS
- **Node.js**: 20.19+(支持 20.19-24
- **Nginx**: 1.18+
- **Git**: 2.x
@@ -27,7 +27,7 @@ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# 验证安装
node -v # 应显示 v20.x.x
node -v # 应显示 v20.19.0 或更高版本
npm -v
```
@@ -88,6 +88,19 @@ npm ci --omit=dev
mkdir -p data storage
```
### 4.1 构建 Web 前端
```bash
cd /var/www/wanwanyun/frontend
# Vite 是构建依赖,生产构建时也必须安装 devDependencies
npm ci --include=dev
npm run build
# Nginx 只需要 dist可按需释放依赖占用
rm -rf node_modules
```
### 5. 配置环境变量
```bash
@@ -115,7 +128,8 @@ ADMIN_PASSWORD=你的强密码
sudo cp /var/www/wanwanyun/nginx/nginx.conf /etc/nginx/sites-available/wanwanyun
# 修改配置中的路径
sudo sed -i 's|/usr/share/nginx/html|/var/www/wanwanyun/frontend|g' /etc/nginx/sites-available/wanwanyun
sudo sed -i 's|/usr/share/nginx/html|/var/www/wanwanyun/frontend/dist|g' /etc/nginx/sites-available/wanwanyun
sudo sed -i 's|/runtime/downloads|/var/www/wanwanyun/frontend/downloads|g' /etc/nginx/sites-available/wanwanyun
sudo sed -i 's|backend:40001|127.0.0.1:40001|g' /etc/nginx/sites-available/wanwanyun
# 创建软链接启用配置
@@ -245,6 +259,7 @@ sudo tail -f /var/log/nginx/error.log
cd /var/www/wanwanyun
sudo git pull
cd backend && npm ci --omit=dev
cd ../frontend && npm ci --include=dev && npm run build && rm -rf node_modules
sudo systemctl restart wanwanyun
```
@@ -294,14 +309,9 @@ sudo chown -R www-data:www-data /var/www/wanwanyun/backend/data/
## 性能优化
### 启用 Nginx 缓存
在 Nginx 配置的 `location /` 中添加:
```nginx
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
```
### Nginx 静态缓存
仓库配置已经对 Vite 哈希资源 `/assets/` 设置一年缓存,对兼容库 `/libs/` 设置 30 天缓存。不要在子 `location` 中单独使用 `add_header Cache-Control`,否则会覆盖上层继承的安全响应头。
### 配置日志轮转
```bash