Build SciCode sandbox image from local wheels to avoid PyPI timeouts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
sora 2026-09-02 08:08:46 +00:00
parent 13274243a0
commit 70fe0c1d95
2 changed files with 48 additions and 4 deletions

View File

@ -7,11 +7,40 @@
# 注意: # 注意:
# - 评测仍在 evalscope 容器里跑,沙箱是宿主机 Docker 再起的子容器 # - 评测仍在 evalscope 容器里跑,沙箱是宿主机 Docker 再起的子容器
# - SciCode 首次运行还会按内容哈希打 tag有本地层缓存就不会再拉 Hub # - SciCode 首次运行还会按内容哈希打 tag有本地层缓存就不会再拉 Hub
# - 构建时不访问 PyPI先在宿主机用国内镜像下载 cp311 wheel再离线 pip install
set -euo pipefail set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SCICODE_DIR="$PROJECT_ROOT/evalscope/evalscope/benchmarks/scicode/docker" 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" 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" echo "==> 检查基座镜像(已有则跳过 pull"
if docker image inspect python:3.11-slim >/dev/null 2>&1; then if docker image inspect python:3.11-slim >/dev/null 2>&1; then
@ -28,8 +57,21 @@ if [ ! -f "$SCICODE_DIR/test_data.h5" ]; then
fi fi
ls -lh "$SCICODE_DIR/test_data.h5" ls -lh "$SCICODE_DIR/test_data.h5"
echo "==> docker build scicode-benchmark:latest" echo "==> SciCode: 确保离线 wheel避免构建时访问 files.pythonhosted.org 超时)"
docker build -t scicode-benchmark:latest "$SCICODE_DIR" 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 ""
echo "完成。本地镜像:" echo "完成。本地镜像:"

View File

@ -1,9 +1,11 @@
FROM python:3.11-slim FROM python:3.11-slim
COPY docker_requirements.txt . COPY docker_requirements.txt .
RUN pip install --no-cache-dir -r docker_requirements.txt COPY wheels /wheels
RUN pip install --no-cache-dir --no-index --find-links=/wheels -r docker_requirements.txt \
&& rm -rf /wheels
WORKDIR /workspace WORKDIR /workspace
COPY process_data.py test_util.py test_data.h5 /workspace/ COPY process_data.py test_util.py test_data.h5 /workspace/
ENV PYTHONPATH="/workspace:${PYTHONPATH}" ENV PYTHONPATH="/workspace"