Files
gongxue-base/deploy.sh
wangziqi 151ef06ec2 refactor: 精简部署流程,移除 MySQL 管理
MySQL 已在服务器运行,部署只需三步:
1. 本地构建 → rsync 同步
2. npm ci(首次)+ migration:run
3. pm2 startOrReload
2026-07-20 15:35:45 +08:00

45 lines
1.1 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.

#!/usr/bin/env bash
# 恭学教育 — PM2 部署脚本
# 用法: ./deploy.sh [ssh_host]
# 前提: 服务器 MySQL 已在运行PM2 已安装
set -euo pipefail
SSH_HOST="${1:-tencent}"
REMOTE_DIR="/opt/gongxue"
echo "=== 1/4 本地构建后端 ==="
npm run build -w @gongxue/server
echo "=== 2/4 本地构建前端 ==="
npm run build -w @gongxue/admin
echo "=== 3/4 同步到 ${SSH_HOST} ==="
rsync -avz --delete \
--exclude='node_modules' \
--exclude='.git' \
--exclude='*.db' \
--exclude='.DS_Store' \
--exclude='logs/' \
--exclude='.turbo/' \
./ "${SSH_HOST}:${REMOTE_DIR}/"
echo "=== 4/4 安装依赖 → 迁移 → PM2 重载 ==="
ssh "${SSH_HOST}" "
cd ${REMOTE_DIR}
mkdir -p logs
if [ ! -d node_modules ]; then
echo '首次部署,安装依赖...'
npm ci --omit=dev
fi
echo '执行数据库迁移...'
npm run migration:run -w @gongxue/server
echo 'PM2 重载...'
pm2 startOrReload ecosystem.config.cjs --update-env
pm2 save
pm2 status
"
echo ""
echo "部署完成!"
echo "访问: http://$(ssh "${SSH_HOST}" 'hostname -I 2>/dev/null | awk "{print \$1}" || curl -s ifconfig.me')"