evalstone/bash/images_load/preload_k3_sandbox_images.sh
sora 70fe0c1d95 Build SciCode sandbox image from local wheels to avoid PyPI timeouts.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 08:08:46 +00:00

82 lines
2.9 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/bash
# 在宿主机本地构建 SciCode 沙箱镜像(不从 Docker Hub 拉 scicode-benchmark
# 用法与 Terminal Bench 预加载相同:先在宿主机准备好镜像,再 docker run 评测容器并挂 docker.sock。
#
# bash bash/images_load/preload_k3_sandbox_images.sh
#
# 注意:
# - 评测仍在 evalscope 容器里跑,沙箱是宿主机 Docker 再起的子容器
# - SciCode 首次运行还会按内容哈希打 tag有本地层缓存就不会再拉 Hub
# - 构建时不访问 PyPI先在宿主机用国内镜像下载 cp311 wheel再离线 pip install
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SCICODE_DIR="$PROJECT_ROOT/evalscope/evalscope/benchmarks/scicode/docker"
WHEEL_DIR="$SCICODE_DIR/wheels"
H5_URL="https://modelscope.cn/datasets/evalscope/SciCode/resolve/master/test_data.h5"
PIP_INDEXES=(
"https://mirrors.aliyun.com/pypi/simple/"
"https://pypi.tuna.tsinghua.edu.cn/simple"
)
download_wheels() {
mkdir -p "$WHEEL_DIR"
local index
for index in "${PIP_INDEXES[@]}"; do
echo " pip download via $index"
if python3 -m pip download \
-d "$WHEEL_DIR" \
-r "$SCICODE_DIR/docker_requirements.txt" \
--python-version 3.11 \
--implementation cp \
--abi cp311 \
--platform manylinux2014_x86_64 \
--only-binary=:all: \
-i "$index" \
--default-timeout=120; then
return 0
fi
echo " 该源失败,尝试下一个..."
done
echo "ERROR: 无法下载 SciCode 构建所需的 wheel"
return 1
}
echo "==> 检查基座镜像(已有则跳过 pull"
if docker image inspect python:3.11-slim >/dev/null 2>&1; then
echo " ok python:3.11-slim"
else
echo " docker pull python:3.11-slim"
docker pull python:3.11-slim
fi
echo "==> SciCode: 确保 test_data.h5"
if [ ! -f "$SCICODE_DIR/test_data.h5" ]; then
echo " downloading test_data.h5 ..."
curl -L --fail -o "$SCICODE_DIR/test_data.h5" "$H5_URL"
fi
ls -lh "$SCICODE_DIR/test_data.h5"
echo "==> SciCode: 确保离线 wheel避免构建时访问 files.pythonhosted.org 超时)"
need_wheels=0
if [ ! -d "$WHEEL_DIR" ] || [ -z "$(ls -A "$WHEEL_DIR"/*.whl 2>/dev/null || true)" ]; then
need_wheels=1
else
echo " 已有 wheel跳过下载"
ls -lh "$WHEEL_DIR"
fi
if [ "$need_wheels" -eq 1 ]; then
download_wheels
ls -lh "$WHEEL_DIR"
fi
echo "==> docker build scicode-benchmark:latest离线安装 wheel"
docker build --network=host -t scicode-benchmark:latest "$SCICODE_DIR"
echo ""
echo "完成。本地镜像:"
docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.Size}}' | grep -E 'REPOSITORY|scicode-benchmark|python'
echo ""
echo "下一步docker run 评测镜像,挂 -v /var/run/docker.sock:/var/run/docker.sock"
echo "SciCode 需要 run.py 打开 sandbox已加入 SANDBOX_DATASETS。"