Files
secondary-school-grade-archive/deploy/update.sh
T
dekun 521a0fc66f Remove built-in proxy from deploy scripts and show pip install progress.
Proxy is optional via manual env vars only; update.sh also drops quiet pip/npm flags.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 12:50:06 +08:00

43 lines
1.0 KiB
Bash

#!/usr/bin/env bash
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'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $*"; }
cd "${INSTALL_DIR}" || exit 1
find "${INSTALL_DIR}" -name "*.sh" -exec sed -i 's/\r$//' {} +
log_info "拉取最新代码…"
git fetch origin
git checkout "${BRANCH}" 2>/dev/null || true
git pull origin "${BRANCH}"
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
log_info "更新网关…"
cd ../deploy/pm2
npm ci
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 "更新完成"