liufumingren 441659d303 feat(frontend): 新增蓝绿发布脚本与生产 API 地址
发布:
- 新增 scripts/deploy.mjs、rollback.mjs、init-config.mjs 与 scripts/remote/{deploy,rollback}.sh
  · 服务器上按 releases/<版本号> 存放,current 软链原子切换,发布/回滚都不中断服务
  · 切换前校验 index.html 与引用的 /assets 资源完整,并补齐历史版本静态资源(旧 chunk 不 404)
  · 真实配置 scripts/deploy.config.json 已加入忽略清单,模板 deploy.config.example.json 入库
- package.json 增加 deploy / rollback / deploy:init

接口地址:
- 新增 .env.production(VITE_API_BASE_URL=https://api.oms.gztbyc.com/api)与 .env.development
  (/api,继续走 vite 代理到本地 6090)
- request.ts 的 baseURL 改为读 VITE_API_BASE_URL;env.d.ts 声明 ImportMetaEnv
- 新增 utils/media.ts#mediaUrl:跨域部署时把后端返回的相对地址(/api/files/raw/…)
  补全为 API 站点绝对地址,用于 ImageUploader、商品列表图片、主体账号头像渲染

工程:
- tsconfig 去掉已弃用的 baseUrl(TS 7 将移除;paths 自 TS 4.1 起不再依赖它)
- .gitignore 增加 dist.tar.gz 与真实部署配置
2026-09-14 22:14:27 +08:00

52 lines
1.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

set -euo pipefail
cd "$RELEASE"
# 4.1 解压
tar -xzf dist.tar.gz
rm -f dist.tar.gz
# 4.2 完整性校验:新版本必须完整,残缺则取消切换(当前线上版本不受影响)
if [ ! -s index.html ]; then
echo "❌ 新版本 index.html 缺失或为空,取消切换"
exit 1
fi
missing=""
for ref in $(grep -oE '/assets/[A-Za-z0-9._-]+\.(js|css)' index.html | sort -u || true); do
[ -f ".$ref" ] || missing="$missing $ref"
done
if [ -n "$missing" ]; then
echo "❌ 新版本缺少以下资源,取消切换:$missing"
exit 1
fi
# 4.3 补齐旧版本静态资源(无感切换的关键)
# 把最近几个历史版本中、本版本缺失的文件(旧 chunk、图片等)合并进新版本,
# 保证切换后正在使用旧版本页面的用户,动态 import 旧资源依然能找到,不会 404。
for src in $(ls -td "$BASE"/releases/*/ 2>/dev/null | head -n "$((KEEP + 1))" || true); do
[ -d "$src" ] || continue
[ "$(readlink -f "$src" 2>/dev/null)" = "$(pwd)" ] && continue
cp -rn "$src/." "$RELEASE/" 2>/dev/null || true
done
# 4.4 原子切换软链接(先建临时链接再改名,切换瞬间服务不中断)
ln -sfn "$RELEASE" "$BASE/current_new"
mv -Tf "$BASE/current_new" "$BASE/current"
# 4.5 健康检查(仅提示,不阻断发布)
if command -v curl >/dev/null 2>&1; then
code="$(curl -skL -o /dev/null -w '%{http_code}' -H "Host: $HOST" "https://127.0.0.1/" 2>/dev/null || true)"
echo "ℹ️ 新版本首页 HTTP 状态码: ${code:-未知}"
fi
# 4.6 清理旧版本:只保留最近 KEEP 个,且绝不删除 current 指向的版本
CURRENT_TARGET="$(readlink -f "$BASE/current" 2>/dev/null || true)"
count=0
for d in $(ls -t "$BASE/releases" 2>/dev/null || true); do
count=$((count+1))
[ "$count" -le "$KEEP" ] && continue
target="$(readlink -f "$BASE/releases/$d" 2>/dev/null || echo "$BASE/releases/$d")"
[ "$target" = "$CURRENT_TARGET" ] && continue
rm -rf "$BASE/releases/$d"
done