Files
xsl ec248e18da ops(deploy): 一键部署脚本 tools/deploy.sh + deploy.md 同步 no-cache 缓存策略
- tools/deploy.sh:git pull --ff-only → rsync web/ → /var/www/soundgame
  (排除开发用文件)→ chown www-data → 线上冒烟(大厅/子站/301/Range)。
  已在部署服务器实测全流程 PASS。
- docs/deploy.md:nginx 配置段同步为线上现行 no-cache 版本(原文档仍是
  expires+public,照抄会把「部署后旧 JS 在浏览器滞留 24h」的坑重新引回),
  并注明一键脚本入口。背景:2026-09-07 引擎句尾截断修复已正确部署,
  但旧 audio.js 被 max-age=86400 public 缓存,用户 24h 内仍执行旧代码。
2026-09-07 18:03:39 +08:00

63 lines
2.1 KiB
Bash
Executable File
Raw Permalink 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.
#!/bin/bash
# deploy.sh — 部署服务器一键上线(git pull → rsync → 冒烟验证)
#
# 用法(部署服务器上):
# bash tools/deploy.sh
#
# 做三件事:
# 1. git pull --ff-only 拉最新代码(本地有未提交改动且与远端
# 冲突时会中止,报错信息 git 自带)
# 2. rsync web/ → /var/www/soundgame(排除开发用文件;--delete 与源保持
# 精确一致)+ chown www-data
# 3. 冒烟验证线上关键 URL(大厅 / 子站 / 301 / 音频 Range)
#
# 静态文件即时生效;全站 no-cache(ETag→304),用户下次打开页面即拿到
# 新版。只有改了 nginx 配置(sites-available/soundgame.conf)才需要另行:
# sudo nginx -t && sudo systemctl reload nginx
#
# 完整部署说明见 docs/deploy.md。
set -euo pipefail
REPO=$(cd "$(dirname "$0")/.." && pwd) # 仓库根(本脚本在 tools/ 下)
DEST=/var/www/soundgame
BASE=https://game.xiangsilian.com
echo '==> git pull'
git -C "$REPO" pull --ff-only
echo "==> rsync $REPO/web/ → $DEST"
sudo rsync -a --delete \
--exclude harness/ --exclude gen/ --exclude test/ \
--exclude server/ --exclude template/ \
--exclude '*.py' --exclude '*.md' --exclude '*.sh' \
"$REPO/web/" "$DEST/"
sudo chown -R www-data:www-data "$DEST"
echo '==> 冒烟验证'
ok=1
check() { # check <描述> <期望状态码> <url> [额外 curl 参数...]
local desc=$1 expect=$2 url=$3
shift 3
local code
code=$(curl -sk -o /dev/null -w '%{http_code}' "$@" "$url" || true)
if [ "$code" = "$expect" ]; then
echo " PASS $code $desc"
else
echo " FAIL $code(期望 $expect) $desc"
ok=0
fi
}
check '大厅(HTTPS)' 200 "$BASE/"
check 'HTTP→301 跳 HTTPS' 301 "http://game.xiangsilian.com/"
check 'rpg 子站' 200 "$BASE/rpg/"
check 'dungeon 子站' 200 "$BASE/dungeon/"
check '音频 Range 206' 206 "$BASE/rpg/audio/bgm/boss.ogg" -H 'Range: bytes=0-1023'
if [ "$ok" = 1 ]; then
echo '==> 部署完成:用户下次打开页面即拿到新版(no-cache 回源验证)'
else
echo '==> 冒烟有失败项,请检查上方 FAIL 行' >&2
exit 1
fi