零 Node 部署、超级管理员,并完善本地构建发布文档。

- FastAPI 单进程托管 frontend/dist,systemd 替代 PM2

- 超级管理员 admin、注册开关与用户管理

- README/DEPLOY/USAGE 说明:改代码须本地构建 dist 后 push,服务器 update.sh

- 提交 frontend/dist 与 build-frontend 脚本
This commit is contained in:
dekun
2026-06-28 13:19:41 +08:00
parent a3d4875bde
commit f1ad4273f4
34 changed files with 1567 additions and 268 deletions
+15 -15
View File
@@ -4,39 +4,39 @@ set -euo pipefail
INSTALL_DIR="${INSTALL_DIR:-/opt/secondary-school-grade-archive}"
BRANCH="${BRANCH:-main}"
PIP_MIRROR="${PIP_MIRROR:-https://pypi.tuna.tsinghua.edu.cn/simple}"
NPM_REGISTRY="${NPM_REGISTRY:-https://registry.npmmirror.com}"
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
cd "${INSTALL_DIR}" || exit 1
find "${INSTALL_DIR}" -name "*.sh" -exec sed -i 's/\r$//' {} +
chmod +x deploy/start.sh
log_info "拉取最新代码…"
git fetch origin
git checkout "${BRANCH}" 2>/dev/null || true
git pull origin "${BRANCH}"
if [[ ! -f "${INSTALL_DIR}/frontend/dist/index.html" ]]; then
log_error "未找到 frontend/dist/index.html"
log_error "请先在开发机构建前端并推送到仓库: cd frontend && npm run build && git add frontend/dist && git push"
exit 1
fi
log_info "更新后端依赖…"
cd backend
source venv/bin/activate
pip install -r requirements.txt --progress-bar on -i "${PIP_MIRROR}"
deactivate
log_info "重建前端…"
cd ../frontend
npm config set registry "${NPM_REGISTRY}"
npm ci
npm run build
if command -v pm2 &>/dev/null; then
pm2 delete grade-api grade-web 2>/dev/null || true
fi
log_info "更新网关…"
cd ../deploy/pm2
npm ci
log_info "重启 systemd 服务…"
systemctl restart grade-archive
log_info "重启 PM2…"
cd "${INSTALL_DIR}"
pm2 reload deploy/pm2/ecosystem.config.cjs --update-env || pm2 start deploy/pm2/ecosystem.config.cjs
pm2 save
log_info "更新完成"
log_info "更新完成 — 访问端口见 .env 中 WEB_PORT(默认 23566"