diff --git a/scripts/.releaseignore-prod b/scripts/.releaseignore-prod index d863158..dcc5060 100644 --- a/scripts/.releaseignore-prod +++ b/scripts/.releaseignore-prod @@ -21,7 +21,8 @@ tsconfig.app.json tsconfig.json tsconfig.node.json vite.config.ts -index.html +# 开发入口页(dist/index.html 必须保留) +/index.html DEVELOPMENT_RELEASE_RULES.md ENGINEERING_WORKFLOW_RULES.md PRODUCTION_RELEASE_RULES.md diff --git a/scripts/release-prod.sh b/scripts/release-prod.sh index 7cab483..64fb65a 100755 --- a/scripts/release-prod.sh +++ b/scripts/release-prod.sh @@ -11,7 +11,7 @@ RELEASES_DIR="${REMOTE_ROOT}/releases" BACKUP_DIR="${REMOTE_ROOT}/backups/memind_adm" ARCHIVE_DIR="${REMOTE_ROOT}/archives" IGNORE_FILE="${ROOT}/scripts/.releaseignore-prod" -WEB_HEALTH_URL="${STUDIO_WEB_HEALTH_URL:-http://127.0.0.1:5174/}" +WEB_HEALTH_URL="${STUDIO_WEB_HEALTH_URL:-http://127.0.0.1:5174/ops/}" API_HEALTH_URL="${STUDIO_API_HEALTH_URL:-http://127.0.0.1:8085/health}" RELEASE_TS="$(date +%Y%m%d-%H%M%S)" SHORT_SHA="$(git -C "${ROOT}" rev-parse --short HEAD 2>/dev/null || echo no-git)" @@ -98,7 +98,7 @@ if [[ "${SKIP_BUILD}" -ne 1 ]]; then say "本地构建 dist(103 不再执行前端构建)" ( cd "${ROOT}" - npm run build + VITE_BASE_PATH="${VITE_BASE_PATH:-/ops}" npm run build ) fi diff --git a/scripts/remote_restart.sh b/scripts/remote_restart.sh index 25f1967..5cf84a9 100755 --- a/scripts/remote_restart.sh +++ b/scripts/remote_restart.sh @@ -16,6 +16,18 @@ command -v node >/dev/null 2>&1 || { echo "❌ 未找到 node" >&2; exit 1; } cd "${ROOT}" +if [[ -f "${ROOT}/.env" ]]; then + set -a + # shellcheck disable=SC1091 + source "${ROOT}/.env" + set +a +fi + +BASE_PATH="${VITE_BASE_PATH:-/ops}" +if [[ "${BASE_PATH}" != */ ]]; then + BASE_PATH="${BASE_PATH}/" +fi + if [[ ! -d dist ]]; then echo "❌ ${ROOT}/dist 不存在,请先构建或 rsync dist" >&2 exit 1 @@ -27,11 +39,18 @@ if [[ ! -d node_modules ]]; then fi echo "==> 停止旧进程 (port ${PORT}, ${API_PORT})..." +if [[ -f "${PID_FILE}" ]]; then + kill "$(cat "${PID_FILE}")" 2>/dev/null || true +fi +if [[ -f "${API_PID_FILE}" ]]; then + kill "$(cat "${API_PID_FILE}")" 2>/dev/null || true +fi lsof -ti "TCP:${PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill 2>/dev/null || true lsof -ti "TCP:${API_PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill 2>/dev/null || true -sleep 1 +sleep 2 lsof -ti "TCP:${PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill -9 2>/dev/null || true lsof -ti "TCP:${API_PORT}" -sTCP:LISTEN 2>/dev/null | xargs kill -9 2>/dev/null || true +sleep 1 echo "==> 启动 Admin API @ 127.0.0.1:${API_PORT}..." nohup node server/index.mjs >>"${API_LOG}" 2>&1 & @@ -44,14 +63,15 @@ if ! curl -sf "http://127.0.0.1:${API_PORT}/health" >/dev/null; then exit 1 fi -echo "==> 启动 vite preview @ 127.0.0.1:${PORT}..." -nohup npm run dev:preview -- --host 127.0.0.1 --port "${PORT}" >>"${LOG}" 2>&1 & +echo "==> 启动 vite preview @ 127.0.0.1:${PORT} (base=${BASE_PATH})..." +nohup npx vite preview --host 127.0.0.1 --port "${PORT}" --base "${BASE_PATH}" --outDir dist >>"${LOG}" 2>&1 & echo $! >"${PID_FILE}" sleep 2 -if curl -sf "http://127.0.0.1:${PORT}/" >/dev/null; then - echo "✅ memind_adm 已就绪: http://127.0.0.1:${PORT}/" - curl -sf "http://127.0.0.1:${PORT}/" >/dev/null && echo " 首页 OK" +preview_url="http://127.0.0.1:${PORT}${BASE_PATH}" +if curl -sf "${preview_url}" >/dev/null; then + echo "✅ memind_adm 已就绪: ${preview_url}" + curl -sf "${preview_url}" >/dev/null && echo " 首页 OK" echo " 登录请使用数据库中已初始化的 admin 账号" else echo "❌ 启动失败,最近日志:" >&2