Files
blog/infra/deploy/build.sh
T
wait4xandGLM-5.3 bb29c8abaf fix(deploy): 构建抓取通道可配+构建日志落盘——ESA 522 事故双根治
- build.sh:BLOG_GIT_URL 环境变量(默认公网,同机构建可指内网
  http://127.0.0.1:13020);每次构建 remote set-url 后 fetch——
  2026-10-26 事故:ESA 边缘对 git.wait4x.online 522 时公网 fetch
  set -e 静默死,staging 冻结 150s+ 无痕
- webhook_receiver.py:构建输出落盘 ~/docker_apps/blog/build.log
  (capture_output 丢弃=黑洞,本次事故"构建为何没跑"零证据);
  与运行副本双同步纪律维持
- 宿主 unit 补 BLOG_GIT_URL 内网通道(配置在 unit 不在仓——主机
  特定值不污染仓库默认)

验证: 手动构建实测 stamp=19b2390+robots.txt 352B 上线;18743 测试
      床恢复 200;smoke 对 staging 软门容忍符合 T1 转硬门前设计

Spec: none (发布链通道与可观测性修复,事故驱动)

Co-authored-by: GLM-5.3
2026-11-01 09:58:47 +08:00

56 lines
3.2 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.
#!/bin/sh
# 构建管线(Phase 5c 裸 clone 改造):构建源 = origin/main 硬跟,非本地工作树。
#
# 为什么:此前直接构建 ~/Code/Github/my-blog 工作树——分支/未提交状态会
# 意外上线(Sveltia 冒烟期实测发生过);且 Sveltia 的 main 提交无法自动
# 发布。改为独立构建仓 fetch+reset 硬跟 main:线上=远端 main,确定性闭环。
# blog 仓已公开,匿名 fetch 无需凭据。
set -e
# 抓取 URL:默认公网;同机构建可由宿主环境变量覆盖为内网
# (2026-10-26 事故:ESA 边缘对 git.wait4x.online 522 时公网 fetch 失败,
# set -e 下静默死、staging 冻结——内网通道必须可用)
BLOG_GIT_URL="${BLOG_GIT_URL:-https://git.wait4x.online/wait4x/blog.git}"
BUILD_REPO="$HOME/docker_apps/blog/build-repo"
STAGING="$HOME/docker_apps/blog/www-staging"
if [ ! -d "$BUILD_REPO/.git" ]; then
echo "[build] 首次克隆构建仓"
git clone "$BLOG_GIT_URL" "$BUILD_REPO"
fi
cd "$BUILD_REPO"
# 每次构建把 origin 指向配置的 URL(同机构建走内网通道;公网 522 时仍可发布)
git remote set-url origin "$BLOG_GIT_URL"
git fetch origin main
git reset --hard origin/main
git clean -fd --exclude node_modules
SHA=$(git rev-parse --short HEAD)
echo "[build] 构建源: origin/main @ $SHA"
pnpm install --frozen-lockfile >/dev/null
pnpm astro build
# 按页字体 CSS 子集化(车道 A 任务 1):裁 @font-face 声明数,构建仓与本地同链;
# 存在性守卫:新文件未推送到 main 前构建仓无此脚本,绝不让发布链因车道在途文件断掉
[ -f scripts/build-perf/subset-font-css.mjs ] && node scripts/build-perf/subset-font-css.mjs dist || echo "[build] subset 脚本未就绪,跳过"
# 首页阻塞 CSS 内联(车道 D):守卫先行同上——脚本未到 main 前绝不炸链
[ -f scripts/build-perf/gen-sw-precache.mjs ] && node scripts/build-perf/gen-sw-precache.mjs dist || echo "[build] sw-precache 生成器未就绪,跳过"
[ -f scripts/build-perf/inline-home-css.mjs ] && node scripts/build-perf/inline-home-css.mjs || echo "[build] inline-home 脚本未就绪,跳过"
# 内容 lint(T3):断链/缺图在部署前拦截;CONTENT_LINT=skip|warn 逃生门见脚本头注
[ -f scripts/build-perf/content-lint.mjs ] && node scripts/build-perf/content-lint.mjs dist || echo "[build] content-lint 未就绪,跳过"
echo "[build] rsync -> $STAGING"
mkdir -p "$STAGING"
rsync -a --delete "$BUILD_REPO/dist/" "$STAGING/"
ORIG="$HOME/docker_apps/blog/photos-originals"
if [ -d "$ORIG" ]; then rsync -a "$ORIG/" "$STAGING/photos-originals/"; fi
printf 'built %s at %s\n' "$SHA" "$(date -Is)" > "$STAGING/.build-stamp"
echo "[build] done: $(find "$STAGING" -name '*.html' | wc -l) html files @ $SHA"
# 生产冒烟(T3):staging 三断言。首版容忍失败(robots 待 T1 落地,smoke FAIL 属预期),
# T1 收编后改硬门:去掉 `|| echo` 让断言失败直接炸构建
if [ -f scripts/build-perf/prod-smoke.sh ] && [ "${SMOKE_BASE:-http://127.0.0.1:18743}" != "off" ]; then
bash scripts/build-perf/prod-smoke.sh "${SMOKE_BASE:-http://127.0.0.1:18743}" || echo "[build] prod-smoke 未过(见上;T1 robots 落地后转硬门)"
fi