From 44ccb69ca59568a1b52edf072fa3161073051d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=94=AF?= Date: Wed, 14 Oct 2026 03:44:39 +0800 Subject: [PATCH] =?UTF-8?q?chore(deploy):=20deploy.sh=20=E5=8A=A0=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=89=8D=E6=B4=81=E5=87=80=E6=A3=80=E6=9F=A5=20+=20ig?= =?UTF-8?q?nore=20=E6=8E=A2=E9=92=88=E6=AE=8B=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 起因(2026-10-14 当晚三次同族事故): ① f8ffcde 把另一任务在途的 server.go 布线一起提交 ⇒ HEAD 编译不过; ② deploy.sh 原先直接从**工作树**构建 ⇒ 任一 worker 在途改动会被顺手编进**生产二进制**, 且部署后『运行二进制校验和 == 本次构建』仍然通过 —— 校验和只能证明『跑的是本次构建』,不能证明『本次构建来自已提交代码』。这是验证链的洞。 改动: - preflight_clean_tree(): git status --porcelain(含未跟踪)非空则拒绝构建; 显式 --allow-dirty 可覆盖(风险自负,须在卡上记原因)。 含未跟踪是刻意的:internal/peer 那类事故正是『已提交代码引用未跟踪文件』。 - .gitignore: /go/*-probe(清 17MB 残留 rulefirst-probe) 验证:闸门在 build 前 die(rc=1),生产未动(两服务仍 active、二进制时间戳不变); --verify-only 不受影响。 --- .gitignore | 4 ++++ scripts/deploy.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/.gitignore b/.gitignore index ea6e472..d9be014 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,7 @@ cron_raw.txt # 改动前备份快照不进 git(git 本身就是版本历史) *.bak.* + +# 探针/临时构建产物(2026-10-14 t_3e98b65a 调查时发现 17MB 残留未清) +/go/*-probe +/go/rulefirst-probe diff --git a/scripts/deploy.sh b/scripts/deploy.sh index a9fbe1d..fe5eb49 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -11,6 +11,10 @@ set -euo pipefail REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" BIN_DIR="${BIN_DIR:-/home/muc/bin}" +# --allow-dirty:显式承担「把在途改动编进生产二进制」的风险(默认拒绝) +ALLOW_DIRTY=0 +for _a in "$@"; do [ "$_a" = "--allow-dirty" ] && ALLOW_DIRTY=1; done + # 构建产物(持久路径,均已 gitignore) BUILD_GO="$REPO_DIR/go/cmd/zhiyid/zhiyid" BUILD_RUST="$REPO_DIR/rust/target/release/zhiyi-consolidate" @@ -56,7 +60,31 @@ verify_health() { log "✔ /health = $code" } +# 🔴 构建前洁净检查(2026-10-14 加)。起因(当晚三次同族事故): +# ① c345ed5 把另一任务在途的 server.go 布线一起提交 ⇒ HEAD 直接编译不过 +# ② 本脚本原先**直接从工作树构建** ⇒ 任一 worker 的在途改动会被顺手编进**生产二进制**, +# 而且部署后「运行二进制校验和匹配」会通过 —— 校验和只能证明「跑的是本次构建」, +# **不能证明「本次构建来自已提交的代码」**。这是验证链上的一个洞。 +# 判据:`git status --porcelain`(含未跟踪,不含已忽略)必须为空。 +# 未跟踪文件也要拦:`internal/peer` 那类事故正是「已提交代码引用了未跟踪文件」—— +# 反之未跟踪的新源文件被编进去,二进制就与 commit 不一致。 +preflight_clean_tree() { + if [ "$ALLOW_DIRTY" = "1" ]; then + log "⚠️ --allow-dirty:跳过洁净检查(本次构建含未提交改动,风险自负)" + return 0 + fi + local dirty + dirty="$(git -C "$REPO_DIR" status --porcelain 2>/dev/null || true)" + if [ -n "$dirty" ]; then + printf '%s\n' "$dirty" | sed 's/^/ /' >&2 + die "工作树不洁净 → 拒绝构建(会把在途改动编进生产二进制,部署后校验和仍会通过,无法事后察觉)。 + 处置:先提交/收工;确需带脏部署则显式加 --allow-dirty 并在卡上记录原因。" + fi + log "✔ 洁净检查通过(含未跟踪文件:无残留)" +} + do_build() { + preflight_clean_tree log "构建 Go → $BUILD_GO" ( cd "$REPO_DIR/go" && CGO_ENABLED=1 go build -o cmd/zhiyid/zhiyid ./cmd/zhiyid ) log "构建 Rust → $BUILD_RUST"