AgentEvalTool/scripts/deploy-t480.sh
sinohqb a77cd83e6a v0.2.0-dev: 文件管理 + 页面布局统一 + 6 个 bug 修复
## 新增功能
- 文件管理模块:分类树 + 文件上传/下载/删除
- 文件上传支持拖拽(Dragger)+ 手动上传(customRequest 模式)

## 页面布局统一(参照评测执行页)
- 仪表盘/评测对象/评测场景/评测报告 全部改为全高 flex 布局
- 统一内联页头样式(h2 + 竖线分隔 + 描述)
- 表格撑满高度、overflow 处理
- 每页添加刷新按钮

## Bug 修复
- 分类树操作按钮 hover 不可见(CSS 规则缺失)
- 文件上传失败(multipart boundary 缺失)
- LLM API 响应 content blocks 数组格式支持(_extract_content_from_api_response)
- response_time_max_ms 被静默忽略(隐式规则传空 params)
- 空 messages 导致 IndexError 崩溃
- poll_reply 异常中止整个 run(缺 try/catch)
- engine finally 未关闭 session
- 3 个页面 UTC 时间戳解析偏差 8 小时

## 后端
- EvalEngine: poll_reply 异常保护、空 dialog 保护、session 关闭
- LLM API 响应解析支持 content-block-array 格式
- 隐式 response_time 规则正确传递 max_ms 参数

## 前端
- api.ts: 移除手动 Content-Type(让浏览器自动添加 boundary)
- Files.tsx: customRequest 替代 beforeUpload、布局优化
- index.css: 分类树 hover 规则
- Targets/Scenarios/Home/Reports: 全高布局改造
- 3 个页面时间戳改用 formatDateTime()(修复 UTC 偏差)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-16 15:25:22 +08:00

137 lines
5.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy AgentEvalTool to the t480 development server.
#
# Single entry point that guarantees the right order:
# 1. sync version (pyproject.toml → package.json)
# 2. build frontend
# 3. rsync code + dist to t480
# 4. rebuild image with version metadata (git SHA + build time)
# 5. restart containers (runs alembic upgrade head automatically)
# 6. verify /api/health reports the expected version
#
# Usage:
# scripts/deploy-t480.sh # full deploy
# scripts/deploy-t480.sh --skip-build # skip image rebuild (code-only hot reload)
# scripts/deploy-t480.sh --dry-run # print commands, don't run them
#
# The t480 host is configured in ~/.ssh/config as "sola-t480".
# Remote path: /opt/agenteval/
set -euo pipefail
HOST="${AGENTEVAL_DEPLOY_HOST:-sola-t480}"
REMOTE_DIR="${AGENTEVAL_DEPLOY_DIR:-/opt/agenteval}"
IMAGE_NAME="t480-agenteval"
COMPOSE_FILE="deploy/t480/docker-compose.yml"
SKIP_BUILD=0
DRY_RUN=0
for arg in "$@"; do
case "$arg" in
--skip-build) SKIP_BUILD=1 ;;
--dry-run) DRY_RUN=1 ;;
-h|--help) sed -n '2,18p' "$0"; exit 0 ;;
*) echo "unknown arg: $arg" >&2; exit 2 ;;
esac
done
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
log() { printf '\033[1;36m>> %s\033[0m\n' "$*"; }
warn() { printf '\033[1;33m!! %s\033[0m\n' "$*" >&2; }
die() { printf '\033[1;31m!! %s\033[0m\n' "$*" >&2; exit 1; }
run() {
if [[ "$DRY_RUN" == "1" ]]; then
printf '\033[2m[dry-run] %s\033[0m\n' "$*"
else
"$@"
fi
}
# ── pre-flight ─────────────────────────────────────────────────────────
log "pre-flight: ssh connectivity"
run ssh -o ConnectTimeout=5 "$HOST" "echo ok >/dev/null" \
|| die "cannot reach $HOST via ssh"
log "pre-flight: sync version (pyproject.toml → package.json)"
run python3 scripts/sync_version.py
VERSION=$(python3 -c "import re; print(re.search(r'^version\s*=\s*\"([^\"]+)\"', open('pyproject.toml').read(), re.M).group(1))")
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "no-git")
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
log "version=$VERSION commit=$COMMIT built_at=$BUILD_TIME"
# ── frontend build ─────────────────────────────────────────────────────
if [[ ! -d frontend/web/node_modules ]]; then
log "frontend: npm install"
run bash -c "cd frontend/web && npm install --silent"
fi
log "frontend: npm run build"
run bash -c "cd frontend/web && npm run build"
# Sanity check: dist must contain the chunk referenced by index.html.
CHUNK=$(grep -oE '/assets/[^"]+\.js' frontend/web/dist/index.html | head -1 | sed 's|^/assets/||')
[[ -n "$CHUNK" && -f "frontend/web/dist/assets/$CHUNK" ]] \
|| die "frontend build produced no chunk (dist stale?)"
log "frontend: OK (chunk=$CHUNK)"
# ── rsync ──────────────────────────────────────────────────────────────
log "rsync → $HOST:$REMOTE_DIR"
run rsync -az --delete \
--exclude='.git' \
--exclude='node_modules' \
--exclude='.venv' \
--exclude='__pycache__' \
--exclude='.pytest_cache' \
--exclude='.ruff_cache' \
--exclude='data' \
--exclude='.env' \
--exclude='config/config.json' \
--exclude='*.db*' \
./ "$HOST:$REMOTE_DIR/"
# ── image rebuild ──────────────────────────────────────────────────────
if [[ "$SKIP_BUILD" == "1" ]]; then
warn "skipping image rebuild (--skip-build)"
else
log "docker build: $IMAGE_NAME:$VERSION"
run ssh "$HOST" \
"cd $REMOTE_DIR && docker compose -f $COMPOSE_FILE build \
--build-arg BUILD_COMMIT=$COMMIT \
--build-arg BUILD_TIME=$BUILD_TIME \
agenteval"
log "docker tag: $IMAGE_NAME:$VERSION + $IMAGE_NAME:latest"
run ssh "$HOST" "\
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$VERSION 2>/dev/null || true && \
docker tag $IMAGE_NAME:latest $IMAGE_NAME:latest"
fi
# ── restart ────────────────────────────────────────────────────────────
log "docker compose up -d"
run ssh "$HOST" "cd $REMOTE_DIR && docker compose -f $COMPOSE_FILE up -d"
# ── verify ─────────────────────────────────────────────────────────────
log "waiting for /api/health"
for i in $(seq 1 30); do
BODY=$(ssh "$HOST" "curl -sf http://localhost:8001/api/health 2>/dev/null" || true)
if [[ -n "$BODY" ]]; then break; fi
sleep 1
done
[[ -n "$BODY" ]] || die "/api/health did not respond after 30s"
log "/api/health: $BODY"
REMOTE_VERSION=$(echo "$BODY" | python3 -c "import sys, json; print(json.load(sys.stdin).get('version', ''))")
REMOTE_COMMIT=$(echo "$BODY" | python3 -c "import sys, json; print(json.load(sys.stdin).get('commit', ''))")
if [[ "$REMOTE_VERSION" != "$VERSION" ]]; then
die "version mismatch! local=$VERSION remote=$REMOTE_VERSION (stale image?)"
fi
if [[ "$REMOTE_COMMIT" != "$COMMIT" && "$COMMIT" != "no-git" ]]; then
die "commit mismatch! local=$COMMIT remote=$REMOTE_COMMIT (image not rebuilt?)"
fi
log "deploy OK: version=$VERSION commit=$COMMIT"
log "open http://192.168.8.145:8001 to verify"