Files
yuezi-saas/deploy.sh
T

74 lines
2.9 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ─────────────────────────────────────────────────────────────
# 月子 SaaS 一键部署
# 用法:./deploy.sh [commit message]
#
# 流程:
# 1. git commit + push(源码,不含 dist
# 2. 本地构建管理端前端
# 3. 本地构建 H5 客户端(微客宝)
# 4. rsync 两个 dist 到服务器
# 5. SSH 触发后端 git pull + migrate + cache
# ─────────────────────────────────────────────────────────────
set -e
SERVER="root@82.157.47.215"
SERVER_PASS="Aiying88"
COMMIT_MSG="${1:-deploy: update}"
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
FRONTEND_DIR="$ROOT_DIR/frontend"
CLIENT_DIR="$ROOT_DIR/client"
REMOTE_FRONTEND="/var/www/saas/frontend"
REMOTE_CLIENT="/var/www/saas/client-root/wkb"
REMOTE_BACKEND_SCRIPT="/var/www/saas/deploy-backend.sh"
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
step() { echo -e "${YELLOW}==> $1${NC}"; }
ok() { echo -e "${GREEN}$1${NC}"; }
# ── 1. 提交并推送源码 ─────────────────────────────────────────
step "提交源码到 git..."
cd "$ROOT_DIR"
git add -A
if git diff --cached --quiet; then
echo " 无源码变更,跳过提交"
else
git commit -m "$COMMIT_MSG"
fi
git push origin main
ok "源码已推送"
# ── 2. 构建管理端前端 ─────────────────────────────────────────
step "构建管理端前端..."
cd "$FRONTEND_DIR"
npm run build
ok "管理端前端构建完成"
# ── 3. 构建 H5 客户端 ─────────────────────────────────────────
step "构建 H5 客户端(微客宝)..."
cd "$CLIENT_DIR"
npm run build
ok "H5 客户端构建完成"
# ── 4. 上传 dist 到服务器 ─────────────────────────────────────
step "上传管理端 dist..."
sshpass -p "$SERVER_PASS" rsync -az --delete \
"$FRONTEND_DIR/dist/" \
"$SERVER:$REMOTE_FRONTEND/"
ok "管理端文件已同步"
step "上传 H5 客户端 dist..."
sshpass -p "$SERVER_PASS" ssh "$SERVER" "mkdir -p $REMOTE_CLIENT"
sshpass -p "$SERVER_PASS" rsync -az --delete \
"$FRONTEND_DIR/dist-client/" \
"$SERVER:$REMOTE_CLIENT/"
ok "H5 客户端文件已同步"
# ── 5. 触发后端同步 ───────────────────────────────────────────
step "同步后端(git pull + migrate + cache..."
sshpass -p "$SERVER_PASS" ssh "$SERVER" "bash $REMOTE_BACKEND_SCRIPT"
ok "后端同步完成"
echo ""
echo -e "${GREEN}🎉 部署完成!${NC}"