Files
chenproject/deploy.sh
2026-10-12 18:55:48 +08:00

48 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.

#!/usr/bin/env bash
# deploy.sh —— 构建并部署展示网站到 m4(chenxy.biboer.cn,cloudflared → nginx:5050)
# 用法:
# ./deploy.sh 构建新 GUI(figma/ React+Vite)+ 同步 core + rsync 到 m4
# ./deploy.sh legacy 部署旧版网站(web/ 原生 HTML,回滚用)
# ./deploy.sh local 仅同步 core 到 figma/public/py 与 web/py(不构建不部署)
set -euo pipefail
REMOTE_HOST="m4" # ssh config 中的主机别名
SITE_DIR="/Users/gavin/www/chenxy" # m4 上 nginx 站点目录(nginx conf: servers/chenxy.biboer.cn.conf)
DOMAIN="chenxy.biboer.cn"
FIGMA_DIR="figma"
echo "[1/4] 同步算法核心 fiber_delay_sim -> 两个前端"
# 新 GUI(figma/):Pyodide 从 dist/py/ 加载
rsync -a --delete --exclude '__pycache__' --exclude 'tests' \
--exclude 'experiments' --exclude 'export' --exclude 'cli.py' --exclude 'gui.py' \
fiber_delay_sim/ "$FIGMA_DIR/public/py/fiber_delay_sim/"
# 旧版(web/,legacy 回滚用)
rsync -a --delete --exclude '__pycache__' --exclude 'tests' \
--exclude 'experiments' --exclude 'export' --exclude 'cli.py' --exclude 'gui.py' \
fiber_delay_sim/ web/py/fiber_delay_sim/
if [ "${1:-}" = "local" ]; then
echo "[done] 本地预览:cd figma && npm run dev → http://127.0.0.1:5188"
exit 0
fi
if [ "${1:-}" = "legacy" ]; then
echo "[2/4] legacy 模式:跳过构建,部署旧版 web/"
SRC="web/"
else
echo "[2/4] 构建新 GUI($FIGMA_DIR → dist/)"
(cd "$FIGMA_DIR" && npm run build)
SRC="$FIGMA_DIR/dist/"
fi
echo "[3/4] 上传 ${SRC} -> ${REMOTE_HOST}:${SITE_DIR}/"
ssh -o RemoteCommand=none -o RequestTTY=no "$REMOTE_HOST" "mkdir -p ${SITE_DIR}"
rsync -az --delete -e "ssh -o RemoteCommand=none -o RequestTTY=no" "$SRC" "${REMOTE_HOST}:${SITE_DIR}/"
echo "[4/4] 验证"
sleep 1
ssh -o RemoteCommand=none -o RequestTTY=no "$REMOTE_HOST" \
"curl -s -o /dev/null -w 'm4 index -> HTTP %{http_code}\\n' http://127.0.0.1:5050/ && \
curl -s -o /dev/null -w 'm4 py core -> HTTP %{http_code}\\n' http://127.0.0.1:5050/py/fiber_delay_sim/core/fiber.py"
echo "[done] 部署完成:https://${DOMAIN}"
echo "[hint] 构建产物文件名带内容 hash 无需版本号;若 index 未更新请强制刷新;nginx 配置改动需 sudo /opt/homebrew/bin/nginx -s reload"