Files
yuezi-saas/deploy.sh
T

58 lines
2.3 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. rsync 直接上传 dist 到服务器
# 4. 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"
REMOTE_FRONTEND="/var/www/saas/frontend"
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. 上传 dist 到服务器 ─────────────────────────────────────
step "上传 dist 到服务器..."
sshpass -p "$SERVER_PASS" rsync -az --delete \
"$FRONTEND_DIR/dist/" \
"$SERVER:$REMOTE_FRONTEND/"
ok "前端文件已同步"
# ── 4. 触发后端同步 ───────────────────────────────────────────
step "同步后端(git pull + migrate + cache..."
sshpass -p "$SERVER_PASS" ssh "$SERVER" "bash $REMOTE_BACKEND_SCRIPT"
ok "后端同步完成"
echo ""
echo -e "${GREEN}🎉 部署完成!${NC}"