Files
agent-safe-middleware/scripts/wait_ready.sh
T
chenleixu b82e44ec32 feat: Docker 打包、交付链路与命名脱敏
镜像与构建
- 六阶段 Dockerfile(base/wheels/deps/manifest/core|guard),core 不含 torch
- 构建期自证:gen_manifest --strict 拦未登记模块,core 阶段重算 sha256
- compose 四服务 host 网络(llm.url 强制回环),config.core/local 可挂载覆盖

无 docker 环境的四段链路
- pull_oci_image.py      直拉 OCI 镜像 rootfs(纯标准库,走加速器)
- replay_image_build.sh  按 stage chroot 重放 Dockerfile
- run_image_chroot.sh    等价 docker run(uid 10001 + 入口 + host 网络)
- pack_image.py          封成 docker save 格式包,自带 diff_id 校验

交付
- make_package.sh 生成自包含目录:镜像包 + 溯源清单 + 构建输入 + 脚本 + 源码快照
- 文档:从零复现指南、docker 打包方案、镜像构建限制与替代方案、交付包 README

命名
- Qwen 品牌名统一替换为 large_model / small_model / large_model_guard,
  覆盖 vLLM 服务名、模型目录、配置、脚本、测试与文档
- 模型架构字段(architectures / model_type / tokenizer_class)属上游定义,
  改名会导致加载失败,保留原值;check_local_model.py 的架构判断同理

验证:smoke 6/6;test.py 20 通过 0 失败 1 警告;gen --strict 67 文件 / 22 进镜像
2026-11-27 18:20:16 +00:00

105 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.
#!/usr/bin/env bash
# 等待一组 HTTP 端点就绪,替代"起完就 curl、失败就以为坏了"。
#
# vLLM 加载 8B 权重需要 60–180 s,中间层要等上游;固定 sleep 不是快了就是慢了,
# 这里改成轮询 + 截止时间,并把每个端点的首字节耗时打出来。
#
# 用法:
# bash scripts/wait_ready.sh --timeout 300 \
# upstream=http://127.0.0.1:8001/v1/models \
# guard06=http://127.0.0.1:8003/v1/models \
# guard8=http://127.0.0.1:8005/v1/models \
# middleware=http://127.0.0.1:8080/readyz
#
# # 只等中间层,10 秒
# bash scripts/wait_ready.sh --timeout 10 middleware=http://127.0.0.1:8080/readyz
#
# 退出码:0 全部就绪;1 有端点超时(并打印最后一次的响应片段)。
set -u
TIMEOUT=180
INTERVAL=2
while [ $# -gt 0 ]; do
case "$1" in
--timeout) TIMEOUT="$2"; shift 2 ;;
--interval) INTERVAL="$2"; shift 2 ;;
-h|--help) sed -n '2,18p' "$0"; exit 0 ;;
*=*) break ;;
*) echo "未知参数:$1(需要 NAME=URL 形式)" >&2; exit 2 ;;
esac
done
[ $# -gt 0 ] || { echo "至少给一个 NAME=URL" >&2; exit 2; }
TOTAL=$#
declare -A STATE CODE LAST_BODY WAIT_S
NAMES=()
for pair in "$@"; do
name=${pair%%=*}
url=${pair#*=}
NAMES+=("$name")
STATE[$name]=wait
CODE[$name]="-"
LAST_BODY[$name]=""
WAIT_S[$name]=0
done
printf '%-12s %-6s %-9s %s\n' "端点" "状态" "耗时" "地址"
START=$(date +%s)
DEADLINE=$((START + TIMEOUT))
while :; do
DONE=0
for pair in "$@"; do
name=${pair%%=*}; url=${pair#*=}
[ "${STATE[$name]}" = "ok" ] && { DONE=$((DONE + 1)); continue; }
T0=$(date +%s%N)
BODY=$(curl -sS --max-time 10 -o /tmp/.wr_body.$$ -w '%{http_code}' "$url" 2>/dev/null) || BODY="000"
T1=$(date +%s%N)
MS=$(( (T1 - T0) / 1000000 ))
LAST_BODY[$name]=$(head -c 160 /tmp/.wr_body.$$ 2>/dev/null | tr -d '\n')
rm -f /tmp/.wr_body.$$
# vLLM /v1/models 与中间层 /readyz 正常都返回 200
if [ "$BODY" = "200" ]; then
STATE[$name]=ok
WAIT_S[$name]=$(( $(date +%s) - START ))
printf '%-12s %-6s %-9s %s\n' "$name" "OK" "${WAIT_S[$name]}s" "$url"
DONE=$((DONE + 1))
else
CODE[$name]=$BODY
if [ -t 1 ]; then
printf '%-12s %-6s %-9s %s\r' "$name" "wait" "${MS}ms" "$url"
else
# 非 tty 不能靠回车覆盖,改成每 15 秒一行心跳,免得看着像卡死
NOW=$(date +%s)
if [ $((NOW - ${LAST_BEAT:-0})) -ge 15 ]; then
LAST_BEAT=$NOW
printf '[%3ss] 仍在等待 %s(最后 http=%s)\n' \
"$((NOW - START))" "$name" "$BODY"
fi
fi
fi
done
[ "$DONE" -ge "$TOTAL" ] && break
if [ "$(date +%s)" -ge "$DEADLINE" ]; then
echo
echo "超时 ${TIMEOUT}s,仍未就绪的端点:"
for pair in "$@"; do
name=${pair%%=*}; url=${pair#*=}
[ "${STATE[$name]}" = "ok" ] && continue
printf ' %-12s http=%s %s\n 最后响应:%s\n' \
"$name" "${CODE[$name]}" "$url" "${LAST_BODY[$name]:-<空>}"
done
echo
echo "对照检查:docker compose ps / docker compose logs --tail=50 <服务名>"
exit 1
fi
sleep "$INTERVAL"
done
echo
echo "全部就绪,用时 $(( $(date +%s) - START ))s。"