|
|
@@ -1,12 +1,12 @@
|
|
|
#!/bin/bash
|
|
|
# 自动部署脚本 - 由 webhook 触发
|
|
|
-# 用于 /data/ai/deploy.sh 的软链接
|
|
|
|
|
|
set -e
|
|
|
|
|
|
DEPLOY_LOG="/tmp/deploy-auto.log"
|
|
|
PROJECT_DIR="/data/ai/audio_codebuddy"
|
|
|
BACKEND_PORT="3100"
|
|
|
+FRONTEND_DIR="/data/ai/audio/frontend"
|
|
|
|
|
|
log() {
|
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$DEPLOY_LOG"
|
|
|
@@ -21,21 +21,28 @@ cd "$PROJECT_DIR"
|
|
|
log "执行 git pull..."
|
|
|
git pull origin master 2>&1 | tee -a "$DEPLOY_LOG"
|
|
|
|
|
|
-# 构建后端
|
|
|
+# ========== 构建前端 ==========
|
|
|
+log "构建前端..."
|
|
|
+cd "$PROJECT_DIR/my-uniapp-vue3"
|
|
|
+npm install 2>&1 | tee -a "$DEPLOY_LOG"
|
|
|
+npm run build:h5 2>&1 | tee -a "$DEPLOY_LOG"
|
|
|
+
|
|
|
+# 复制前端文件到部署目录
|
|
|
+log "部署前端..."
|
|
|
+rm -rf "$FRONTEND_DIR/build/h5" 2>/dev/null || true
|
|
|
+cp -r "$PROJECT_DIR/my-uniapp-vue3/dist/build/h5" "$FRONTEND_DIR/build/h5"
|
|
|
+log "前端部署完成"
|
|
|
+
|
|
|
+# ========== 构建后端 ==========
|
|
|
log "构建后端..."
|
|
|
cd "$PROJECT_DIR/server"
|
|
|
+npm install 2>&1 | tee -a "$DEPLOY_LOG"
|
|
|
npm run build 2>&1 | tee -a "$DEPLOY_LOG"
|
|
|
|
|
|
-# 安装依赖(如果 package.json 有变化)
|
|
|
-log "检查依赖..."
|
|
|
-npm install --production 2>&1 | tee -a "$DEPLOY_LOG" || true
|
|
|
-
|
|
|
# 重启后端服务
|
|
|
log "重启后端服务..."
|
|
|
|
|
|
-# 使用 PM2 重启
|
|
|
if command -v pm2 &> /dev/null; then
|
|
|
- # 需要设置 SERVER_PORT=3100
|
|
|
pm2 delete server 2>/dev/null || true
|
|
|
SERVER_PORT=3100 pm2 start dist/app.js --name server 2>&1 | tee -a "$DEPLOY_LOG"
|
|
|
pm2 save 2>&1 | tee -a "$DEPLOY_LOG"
|