mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
按发布纪律回流。**注意这是内容对齐而非 merge**,理由与依据:
1. 纪律禁止 merge 回主干,因为 merge 会把发布分支的**版本号变更**带进 main。
本项目版本号**只由 `git describe --tags` 推导**(Makefile VERSION),
仓库里没有任何文件存放版本号 ⇒ 回流不存在版本污染风险。
2. 逐项核对确认 **main 是 release 的内容严格子集**:
- `main` 独有的**文件**:0 个;
- `internal/lua/plugins.go` / `internal/core/kernel_actions.go` 等内核文件
main 独有行数:0;
- `deploy.sh` 那 14 行只是 emoji 清理(release 刻意去掉了 emoji);
- `channels.lua` 那 333 行是**旧版内容**(旧 exports 表、旧模型名单)。
- main 独有的 9 个提交按 patch-id **全部已在 release 中等效存在**
(`git cherry` 逐条列出均为 `-`,即已合入)。
3. 故回流 = 把 release 的内容带到 main,等价于"只捡拾修复、不带版本号",
且不会丢任何 main 独有的修复。
本次带回 v2.0.12 的全部内容(37 个提交):
- 源串行 + 按模型节流(照 model-gate)
- 已失效模型存储 + 远端目录闸门
- 余额分档选号
- 模型能力元数据(models.dev,isFree 权威判定)
- **凭据续期修复**(此前恒报 ok:true 却一个请求都不发)
- 通用件 TTL 缓存 + 串行锁;account_test/account_adopt/account_delete 修正
- 内核级:出站授权持久化重启后不生效、`__llmsproxy_plugin_dir` ground truth
校验:`git diff release/v2.0.x` = 0 行;`go build -tags luajit ./...` 通过。
149 lines
6.9 KiB
Bash
Executable File
149 lines
6.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build the llmsproxy CORE distribution packages (deb + rpm + tar.gz).
|
|
#
|
|
# Unlike the GUI packages (Electron), the core is a single static-ish binary
|
|
# that server admins install with dpkg/rpm. The systemd unit bakes in the
|
|
# memory tuning (GOGC=50, MALLOC_ARENA_MAX=2) measured on the production box.
|
|
#
|
|
# Requires: go, nfpm (PATH), dpkg-deb/rpmbuild for verification
|
|
# Outputs: cmd/build/dist/llmsproxy_<ver>_amd64.deb
|
|
# cmd/build/dist/llmsproxy-<ver>.x86_64.rpm
|
|
# cmd/build/dist/llmsproxy-<ver>-linux-amd64.tar.gz
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
VERSION="${1:-$(git describe --tags --dirty 2>/dev/null | sed 's/^v//' || echo 0.1.0)}"
|
|
DIST="$ROOT/cmd/build/dist"
|
|
BUILD_BIN="$ROOT/cmd/build/llmsproxy"
|
|
|
|
log() { printf '\033[1;34m[core-dist]\033[0m %s\n' "$*"; }
|
|
|
|
# nfpm is installed via `go install` -> lives in GOPATH/bin, which may not be
|
|
# on the caller's PATH (non-interactive shells, cron). Resolve it explicitly.
|
|
NFPM_BIN="$(command -v nfpm || true)"
|
|
[ -z "$NFPM_BIN" ] && [ -n "$(go env GOPATH)" ] && {
|
|
[ -x "$(go env GOPATH)/bin/nfpm" ] && NFPM_BIN="$(go env GOPATH)/bin/nfpm"
|
|
}
|
|
[ -n "$NFPM_BIN" ] || {
|
|
echo "[core-dist] nfpm missing. Install: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.41.2"
|
|
exit 1
|
|
}
|
|
|
|
mkdir -p "$DIST"
|
|
|
|
# 1) build the core binary (luajit tag, -s -w like deploy.sh)
|
|
log "building core binary (luajit, stripped)..."
|
|
CGO_ENABLED=1 go build -tags luajit -trimpath -ldflags="-s -w" -o "$BUILD_BIN" ./cmd/llmsproxy
|
|
|
|
# 2) sanity gates: binary must contain the expected symbols and not be degenerate.
|
|
# NOTE under `set -o pipefail`, `strings | grep -q` is BROKEN: grep -q exits
|
|
# on first hit and closes the pipe, strings gets SIGPIPE -> pipeline returns
|
|
# 141 -> the check spuriously fails. Stage strings output in a temp file.
|
|
SYMS_TMP="$(mktemp)"
|
|
strings "$BUILD_BIN" > "$SYMS_TMP"
|
|
for sym in ProbeSlots reqRing shrinkStepLocked mergeUsage; do
|
|
grep -qF "$sym" "$SYMS_TMP" || {
|
|
echo "[core-dist] FATAL: binary missing expected symbol '$sym'"; rm -f "$SYMS_TMP"; exit 1
|
|
}
|
|
done
|
|
rm -f "$SYMS_TMP"
|
|
[ "$(stat -c%s "$BUILD_BIN")" -gt 5000000 ] || {
|
|
echo "[core-dist] FATAL: core binary implausibly small"; exit 1
|
|
}
|
|
log " ok: $(stat -c%s "$BUILD_BIN") bytes, symbols present"
|
|
|
|
# 3) deb + rpm via nfpm. nfpm v2 here does not render {{ .Env.VERSION }}, so
|
|
# stamp the version into a throwaway copy of the config; -t places the
|
|
# generated package in the dist dir.
|
|
log "packaging deb + rpm (v$VERSION)..."
|
|
NFPM_CFG="$(mktemp)" && sed "s/__VERSION__/$VERSION/g" "$ROOT/packaging/nfpm.yaml" > "$NFPM_CFG"
|
|
"$NFPM_BIN" package --config "$NFPM_CFG" --packager deb -t "$DIST"
|
|
"$NFPM_BIN" package --config "$NFPM_CFG" --packager rpm -t "$DIST"
|
|
rm -f "$NFPM_CFG"
|
|
|
|
# 4) tar.gz
|
|
log "packaging tar.gz..."
|
|
TAR_DIR="$DIST/llmsproxy-$VERSION-linux-amd64"
|
|
rm -rf "$TAR_DIR"; mkdir -p "$TAR_DIR"
|
|
cp "$BUILD_BIN" "$TAR_DIR/llmsproxy"
|
|
# Use the tracked sanitised template, NOT the local config.yaml: that file is
|
|
# gitignored and carries the operator's real gateway_keys / upstream keys. It
|
|
# was previously copied verbatim as config.example.yaml, which shipped a real,
|
|
# working admin key (sk-gw-local-0001) to every install — and postinst.sh copies
|
|
# the example to /etc when none exists, so it ended up live in production.
|
|
cp "$ROOT/packaging/config.example.yaml" "$TAR_DIR/config.example.yaml"
|
|
cp "$ROOT/packaging/llmsproxy.service" "$TAR_DIR/llmsproxy.service"
|
|
mkdir -p "$TAR_DIR/adapters"
|
|
cp "$ROOT"/internal/lua/adapters/*.lua "$TAR_DIR/adapters/"
|
|
|
|
# The shipped plugins go into the archive too, not just into the binary's
|
|
# embedded FS.
|
|
#
|
|
# Seeding works without them (internal/lua/vm.go embeds plugins/*.lua and
|
|
# writeBundledPlugins materialises them on first start — verified: a fresh
|
|
# plugin_dir gains billing.lua, 70031 bytes, and the plugin loads), so this is
|
|
# not a functional fix. It is a contents/claim mismatch: the v1.8.0 release
|
|
# notes tell the operator the billing plugin ships with the core, and this
|
|
# archive — the artefact they unpack and inspect — did not contain it. Shipping
|
|
# the file also means an operator can read and adapt it before installing,
|
|
# instead of only discovering it after the first boot writes it out.
|
|
mkdir -p "$TAR_DIR/plugins"
|
|
cp "$ROOT"/internal/lua/plugins/*.lua "$TAR_DIR/plugins/"
|
|
|
|
tar -C "$DIST" -czf "$DIST/llmsproxy-$VERSION-linux-amd64.tar.gz" \
|
|
"$(basename "$TAR_DIR")"
|
|
rm -rf "$TAR_DIR"
|
|
|
|
# 5) verify artifacts are healthy (the same gate that would have caught the
|
|
# 264KB exe fiasco)
|
|
log "verifying packages..."
|
|
for f in "$DIST"/llmsproxy_*.deb "$DIST"/llmsproxy-*.rpm "$DIST"/*.tar.gz; do
|
|
[ -f "$f" ] || continue
|
|
sz=$(stat -c%s "$f")
|
|
[ "$sz" -gt 100000 ] || { echo "[core-dist] FATAL: $f suspiciously small ($sz B)"; exit 1; }
|
|
log " OK $f ($((sz/1024)) KB)"
|
|
done
|
|
# dpkg-deb takes ONE archive; every extra argument is read as an additional
|
|
# control-component name. With the glob unquoted this used to expand to three
|
|
# .deb files (1.5.9 / 1.6.0 / the one just built) and dpkg-deb exited 2 — under
|
|
# `set -e` that aborted the script right here, so the "done" line never printed
|
|
# and NO content verification below ever ran. The size gate above was the only
|
|
# check that ever executed. Pick the newest deb explicitly.
|
|
newest_deb=$(ls -t "$DIST"/llmsproxy_*.deb 2>/dev/null | head -1 || true)
|
|
if [ -n "$newest_deb" ]; then
|
|
dpkg-deb -I "$newest_deb" 2>/dev/null | grep -E 'Package|Version' | head -2 || true
|
|
fi
|
|
|
|
# 6) the archive must actually carry what the release notes promise.
|
|
#
|
|
# A size floor alone cannot catch this: a tar.gz missing all 70KB of plugins
|
|
# still clears the 100KB threshold easily, and the seeded-on-first-boot
|
|
# behaviour hides it at runtime — the operator sees a working billing plugin and
|
|
# concludes the package is complete. Assert the file is in the archive.
|
|
log "verifying archive contents..."
|
|
TARBALL="$DIST/llmsproxy-$VERSION-linux-amd64.tar.gz"
|
|
[ -f "$TARBALL" ] || { echo "[core-dist] FATAL: $TARBALL missing"; exit 1; }
|
|
listing=$(tar tzf "$TARBALL" 2>/dev/null || true)
|
|
[ -n "$listing" ] || { echo "[core-dist] FATAL: cannot list $TARBALL"; exit 1; }
|
|
for want in llmsproxy config.example.yaml llmsproxy.service plugins/billing.lua; do
|
|
if ! printf '%s\n' "$listing" | grep -q "/$want\$"; then
|
|
echo "[core-dist] FATAL: archive is missing $want"
|
|
echo " (release notes claim the billing plugin ships with the core)"
|
|
exit 1
|
|
fi
|
|
log " OK archive contains $want"
|
|
done
|
|
# Directories are matched by their CONTENTS, not by name: tar written with
|
|
# `tar -czf` from a populated tree lists "…/adapters/openai.lua" and never a bare
|
|
# "…/adapters" entry, so an earlier version of this check that grepped for
|
|
# "/adapters$" reported a complete archive as broken.
|
|
n_adapters=$(printf '%s\n' "$listing" | grep -c "/adapters/.*\.lua\$" || true)
|
|
if [ "$n_adapters" -lt 10 ]; then
|
|
echo "[core-dist] FATAL: archive has only $n_adapters adapters (expected >= 10)"
|
|
exit 1
|
|
fi
|
|
log " OK archive contains $n_adapters adapters"
|
|
|
|
log "done: $DIST" |