[feature] Support multi-arch docker images of AISBench/benchmark#332
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces Docker support for the AISBench benchmark, adding multi-stage Dockerfiles for Ubuntu and openEuler environments, comprehensive documentation, and a build_image.sh script to automate the build, validation, and upload processes. The review feedback highlights several critical improvements: fixing an incorrect conditional check on docker images -q in the build script, securing variable expansions with double quotes, avoiding directory changes with cd when calling obsutil, ensuring site-packages directories exist in the builder stage to prevent copy failures, and using explicit python3.x -m pip commands in the Ubuntu Dockerfiles to guarantee the correct Python version is targeted.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| unzip -q /tmp/punkt.zip -d /usr/share/nltk_data/tokenizers && \ | ||
| rm /tmp/punkt.zip | ||
|
|
||
| RUN python3.11 -c "import nltk; from nltk.tokenize import word_tokenize; tokens = word_tokenize('Hello World! 测试NLTK 3.8离线安装'); print('分词结果:', tokens)" |
There was a problem hiding this comment.
在多阶段构建的 runtime 阶段中,使用了 COPY --from=builder 来复制多个 site-packages 目录(第 102-105 行)。如果 builder 阶段中某些目录(例如 /usr/local/lib64/python3.11/site-packages)因为没有安装相应的包而未被创建,Docker 构建将会报错并中断。\n\n为了确保构建的鲁棒性,建议在 builder 阶段结束前,显式创建这些目录,确保它们一定存在。
RUN python3.11 -c "import nltk; from nltk.tokenize import word_tokenize; tokens = word_tokenize('Hello World! 测试NLTK 3.8离线安装'); print('分词结果:', tokens)" && \
mkdir -p /usr/local/lib64/python3.11/site-packages \
/usr/local/lib/python3.11/site-packages \
/usr/lib64/python3.11/site-packages \
/usr/lib/python3.11/site-packages
| fi | ||
|
|
||
| echo "开始清理本地旧资源..." | ||
| if docker images -q ${image_name} > /dev/null 2>&1; then |
There was a problem hiding this comment.
在 Bash 中,docker images -q 命令无论是否找到匹配的镜像,其退出状态码(exit status)始终为 0。因此,if docker images -q ${image_name} > /dev/null 2>&1 条件判断将永远评估为真(true),导致每次运行脚本时都会执行 docker rmi -f,即使本地并没有该镜像。\n\n建议通过检查命令输出是否为空来判断镜像是否存在。
| if docker images -q ${image_name} > /dev/null 2>&1; then | |
| if [ -n "$(docker images -q "${image_name}" 2>/dev/null)" ]; then |
| mkdir -p ${image_output_dir} | ||
| docker save ${image_name} | gzip -9 > ${offline_pkg_full_path} | ||
| echo "离线包已生成:${offline_pkg_full_path}" | ||
| chmod 640 ${offline_pkg_full_path} |
There was a problem hiding this comment.
为了防止路径或镜像名称中包含空格或特殊字符时导致脚本解析错误,建议对变量 ${image_output_dir}、${image_name} 和 ${offline_pkg_full_path} 进行双引号包裹。
| mkdir -p ${image_output_dir} | |
| docker save ${image_name} | gzip -9 > ${offline_pkg_full_path} | |
| echo "离线包已生成:${offline_pkg_full_path}" | |
| chmod 640 ${offline_pkg_full_path} | |
| mkdir -p "${image_output_dir}"\n docker save "${image_name}" | gzip -9 > "${offline_pkg_full_path}"\n echo "离线包已生成:${offline_pkg_full_path}"\n chmod 640 "${offline_pkg_full_path}" |
| cd ${obsutils_path} | ||
| ./obsutil cp ${offline_pkg_full_path} obs://aisbench/images/benchmark/github/${offline_pkg_name} -f |
There was a problem hiding this comment.
使用 cd 改变当前工作目录可能会影响脚本后续的相对路径解析(如果以后添加了其他步骤)。此外,如果 cd 失败,脚本仍会继续执行,导致在错误的目录下运行 ./obsutil。\n\n建议直接使用绝对或相对路径调用 obsutil,避免使用 cd。同时,对变量进行双引号包裹以确保路径安全。
| cd ${obsutils_path} | |
| ./obsutil cp ${offline_pkg_full_path} obs://aisbench/images/benchmark/github/${offline_pkg_name} -f | |
| "${obsutils_path}/obsutil" cp "${offline_pkg_full_path}" "obs://aisbench/images/benchmark/github/${offline_pkg_name}" -f |
| RUN pip install --no-cache-dir \ | ||
| -i https://repo.huaweicloud.com/repository/pypi/simple \ | ||
| --trusted-host repo.huaweicloud.com \ | ||
| --use-pep517 \ | ||
| rouge_chinese |
There was a problem hiding this comment.
在 Dockerfile 中,直接使用 pip 可能会因为环境变量或 PATH 顺序问题指向错误的 Python 版本。为了确保一致性并避免潜在的版本冲突,建议使用显式的 python3.10 -m pip,这与第 47 行的写法以及 openEuler Dockerfile 中的最佳实践保持一致。请对该文件中后续的其他 pip install 命令也进行类似的修改。
RUN python3.10 -m pip install --no-cache-dir \
-i https://repo.huaweicloud.com/repository/pypi/simple \
--trusted-host repo.huaweicloud.com \
--use-pep517 \
rouge_chinese
| RUN pip install --no-cache-dir --break-system-packages \ | ||
| -i https://repo.huaweicloud.com/repository/pypi/simple \ | ||
| --trusted-host repo.huaweicloud.com \ | ||
| --use-pep517 \ | ||
| rouge_chinese |
There was a problem hiding this comment.
在 Dockerfile 中,直接使用 pip 可能会因为环境变量或 PATH 顺序问题指向错误的 Python 版本。为了确保一致性并避免潜在的版本冲突,建议使用显式的 python3.12 -m pip,这与第 46 行的写法以及 openEuler Dockerfile 中的最佳实践保持一致。请对该文件中后续的其他 pip install 命令也进行类似的修改。
RUN python3.12 -m pip install --no-cache-dir --break-system-packages \
-i https://repo.huaweicloud.com/repository/pypi/simple \
--trusted-host repo.huaweicloud.com \
--use-pep517 \
rouge_chinese
|
|
||
| | Dockerfile | Base Image | Python | Path | | ||
| | --- | --- | --- | --- | | ||
| | `Dockerfile.py310.ubuntu22.04` | `ubuntu:22.04` | 3.10 | `docker/ubuntu/` | |
| echo " docker buildx imagetools inspect ${manifest_image_name}" | ||
| fi | ||
| fi | ||
|
|
There was a problem hiding this comment.
镜像构建成功后,是否有可用性检查,如镜像制品大小,简单的可用性验证等等,否则如何保证镜像的功能正常?
There was a problem hiding this comment.
[reply] 在脚本中构建完镜像后会临时起容器进入后验证--search命令。--search命令执行后会遍历工具涉及的主要依赖,同时search命令得到的路径也可以判断源码安装是否成功
Thanks for your contribution; we appreciate it a lot. The following instructions will make your pull request healthier and help you get feedback more easily. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
感谢您的贡献,我们非常重视。以下说明将使您的拉取请求更健康,更易于获得反馈。如果您不理解某些项目,请不要担心,只需提交拉取请求并从维护人员那里寻求帮助即可。
PR Type / PR类型
Related Issue | 关联 Issue
Fixes #(issue ID / issue 编号) / Relates to #(issue ID / issue 编号)
NA
🔍 Motivation / 变更动机
为 AISBench Benchmark 项目新增 Docker 镜像构建支持(额外进行多架构归一的支持),方便用户通过容器化方式快速部署和运行 AISBench 测评工具。通过提供预配置的 Docker 镜像,降低环境搭建门槛,同时支持 Ubuntu 和 openEuler 两大主流操作系统,覆盖 Python 3.10 / 3.11 / 3.12 多个版本,满足不同场景下的部署需求。
📝 Modification / 修改内容
新增
docker/目录,包含以下文件:1. 构建脚本 —
build_image.sh--tag(必填)、--os、--py-version、--hub-repo、--image-output-dir、--obs-path、--push、--upload、--use-cacheais_bench命令并校验输出关键内容)--push 1)和上传离线包到 OBS(--upload 1)--use-cache 1)2. Dockerfile(4 个,覆盖 2 种 OS × 3 个 Python 版本)
Dockerfile.py310.ubuntu22.04ubuntu:22.04docker/ubuntu/Dockerfile.py312.ubuntu24.04ubuntu:24.04docker/ubuntu/Dockerfile.py310.openeuler22.03openeuler/openeuler:22.03-ltsdocker/openeuler/Dockerfile.py311.openeuler24.03openeuler/openeuler:24.03-ltsdocker/openeuler/所有 Dockerfile 均采用多阶段构建模式:
GIT_TAG版本)、安装系统依赖、安装 Python 依赖(torch、rouge_chinese、nltk 等)、安装 benchmark 包、离线配置 NLTK punkt 数据3. 文档 —
OVERVIEW.en.md/OVERVIEW.zh_cn.md📐 Associated Test Results / 关联测试结果
(待填写 CI 管道或测试报告链接)

x86_64构建镜像(构建脚本中有基本检查)
aarch64构建镜像
架构归一后效果:


https://github.com/orgs/AISBench/packages/container/aisbench_benchmark/versions
无。本次新增为独立的
docker/目录,不影响现有代码。无。
🌟 Use cases (Optional) / 使用案例(可选)
快速拉取官方镜像使用:
本地构建自定义镜像:
构建并推送 + 上传离线包:
✅ Checklist / 检查列表
Before PR:
After PR:
👥 Collaboration Info / 协作信息
以上是根据 PR 模板生成的完整描述。其中
Related Issue、测试结果链接和建议审核人等字段需要你根据实际情况补充填写。