Skip to content

[feature] Support multi-arch docker images of AISBench/benchmark#332

Merged
Keithwwa merged 4 commits into
AISBench:masterfrom
SJTUyh:docker_dev
Jun 15, 2026
Merged

[feature] Support multi-arch docker images of AISBench/benchmark#332
Keithwwa merged 4 commits into
AISBench:masterfrom
SJTUyh:docker_dev

Conversation

@SJTUyh

@SJTUyh SJTUyh commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

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类型

  • Feature(功能新增)
  • Bugfix(Bug 修复)
  • Docs(文档更新)
  • CI/CD(持续集成/持续部署)
  • Refactor(代码重构)
  • Perf(性能优化)
  • Dependency(依赖项更新)
  • Test-Cases(测试用例更新)
  • Other(其他)

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

  • 统一的 Docker 镜像构建脚本,支持通过命令行参数灵活配置
  • 支持的参数:--tag(必填)、--os--py-version--hub-repo--image-output-dir--obs-path--push--upload--use-cache
  • 构建后自动进行镜像功能验证(执行 ais_bench 命令并校验输出关键内容)
  • 支持推送到远程镜像仓库(--push 1)和上传离线包到 OBS(--upload 1
  • 支持缓存构建加速(--use-cache 1

2. Dockerfile(4 个,覆盖 2 种 OS × 3 个 Python 版本)

Dockerfile 基础镜像 Python 路径
Dockerfile.py310.ubuntu22.04 ubuntu:22.04 3.10 docker/ubuntu/
Dockerfile.py312.ubuntu24.04 ubuntu:24.04 3.12 docker/ubuntu/
Dockerfile.py310.openeuler22.03 openeuler/openeuler:22.03-lts 3.10 docker/openeuler/
Dockerfile.py311.openeuler24.03 openeuler/openeuler:24.03-lts 3.11 docker/openeuler/

所有 Dockerfile 均采用多阶段构建模式:

  • builder 阶段:克隆仓库(支持指定 GIT_TAG 版本)、安装系统依赖、安装 Python 依赖(torch、rouge_chinese、nltk 等)、安装 benchmark 包、离线配置 NLTK punkt 数据
  • runtime 阶段:从 builder 复制产物,生成精简运行镜像,最终镜像仅包含运行时必需组件

3. 文档 — OVERVIEW.en.md / OVERVIEW.zh_cn.md

  • 中英文双语 Docker 镜像概览文档
  • 涵盖:快速参考、镜像 Tag 命名规范、Dockerfile 清单、镜像拉取与导入方式、容器启动与使用指南、本地构建方法、构建脚本参数一览、二次开发指引

📐 Associated Test Results / 关联测试结果

(待填写 CI 管道或测试报告链接)
x86_64构建镜像(构建脚本中有基本检查)
image

aarch64构建镜像

image

架构归一后效果:
image
image

https://github.com/orgs/AISBench/packages/container/aisbench_benchmark/versions

⚠️ BC-breaking (Optional) / 向后不兼容变更(可选)

无。本次新增为独立的 docker/ 目录,不影响现有代码。


⚠️ Performance degradation (Optional) / 性能下降(可选)

无。


🌟 Use cases (Optional) / 使用案例(可选)

  1. 快速拉取官方镜像使用

    docker pull ghcr.io/aisbench/aisbench_benchmark:v3.1-20260522-master-ubuntu22.04-py310-x86_64
    docker run --name ais_bench_container -it -d --net=host -w /benchmark --ipc=host -v /data/datasets:/datasets <IMAGE_ID> bash
  2. 本地构建自定义镜像

    bash docker/build_image.sh --tag v1.0.0 --os openeuler24.03 --py-version py311
  3. 构建并推送 + 上传离线包

    bash docker/build_image.sh --tag v1.0.0 --push 1 --upload 1

✅ Checklist / 检查列表

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues. / 使用预提交或其他 linting 工具来修复潜在的 lint 问题。
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests. / 修复的 Bug 已完全由单元测试覆盖,导致 Bug 的情况应在单元测试中添加。
  • The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness. / 此拉取请求中的修改已完全由单元测试覆盖。如果不是,请添加更多单元测试以确保正确性。
  • All relevant documentation (API docs, docstrings, example tutorials) has been updated to reflect these changes. / 所有相关文档(API 文档、文档字符串、示例教程)已更新以反映这些更改。

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects. / 如果此拉取请求对下游或其他相关项目有潜在影响,应在那些项目中测试此 PR。
  • CLA has been signed and all committers have signed the CLA in this PR. / CLA 已签署,且本 PR 中的所有提交者均已签署 CLA。

👥 Collaboration Info / 协作信息

  • Suggested Reviewers / 建议审核人: @xxx
  • Relevant Module Owners / 相关模块负责人: @xxx
  • Other Collaboration Notes / 其他协作说明:

以上是根据 PR 模板生成的完整描述。其中 Related Issue、测试结果链接和建议审核人等字段需要你根据实际情况补充填写。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

在多阶段构建的 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

Comment thread docker/build_image.sh
fi

echo "开始清理本地旧资源..."
if docker images -q ${image_name} > /dev/null 2>&1; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在 Bash 中,docker images -q 命令无论是否找到匹配的镜像,其退出状态码(exit status)始终为 0。因此,if docker images -q ${image_name} > /dev/null 2>&1 条件判断将永远评估为真(true),导致每次运行脚本时都会执行 docker rmi -f,即使本地并没有该镜像。\n\n建议通过检查命令输出是否为空来判断镜像是否存在。

Suggested change
if docker images -q ${image_name} > /dev/null 2>&1; then
if [ -n "$(docker images -q "${image_name}" 2>/dev/null)" ]; then

Comment thread docker/build_image.sh
Comment on lines +203 to +206
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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了防止路径或镜像名称中包含空格或特殊字符时导致脚本解析错误,建议对变量 ${image_output_dir}${image_name}${offline_pkg_full_path} 进行双引号包裹。

Suggested change
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}"

Comment thread docker/build_image.sh
Comment on lines +213 to +214
cd ${obsutils_path}
./obsutil cp ${offline_pkg_full_path} obs://aisbench/images/benchmark/github/${offline_pkg_name} -f

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

使用 cd 改变当前工作目录可能会影响脚本后续的相对路径解析(如果以后添加了其他步骤)。此外,如果 cd 失败,脚本仍会继续执行,导致在错误的目录下运行 ./obsutil。\n\n建议直接使用绝对或相对路径调用 obsutil,避免使用 cd。同时,对变量进行双引号包裹以确保路径安全。

Suggested change
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

Comment on lines +53 to +57
RUN pip install --no-cache-dir \
-i https://repo.huaweicloud.com/repository/pypi/simple \
--trusted-host repo.huaweicloud.com \
--use-pep517 \
rouge_chinese

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在 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

Comment on lines +52 to +56
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在 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

@SJTUyh SJTUyh changed the title Docker dev [feature] Offically support docker images of AISBench/benchmark Jun 10, 2026
@SJTUyh SJTUyh changed the title [feature] Offically support docker images of AISBench/benchmark [feature] Officially support docker images of AISBench/benchmark Jun 10, 2026
Comment thread docker/OVERVIEW.en.md Outdated

| Dockerfile | Base Image | Python | Path |
| --- | --- | --- | --- |
| `Dockerfile.py310.ubuntu22.04` | `ubuntu:22.04` | 3.10 | `docker/ubuntu/` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dockerfile建议直接提供完整的URL地址

@SJTUyh SJTUyh changed the title [feature] Officially support docker images of AISBench/benchmark [feature] Support multi-arch docker images of AISBench/benchmark Jun 15, 2026
Comment thread docker/build_image.sh
echo " docker buildx imagetools inspect ${manifest_image_name}"
fi
fi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

镜像构建成功后,是否有可用性检查,如镜像制品大小,简单的可用性验证等等,否则如何保证镜像的功能正常?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reply] 在脚本中构建完镜像后会临时起容器进入后验证--search命令。--search命令执行后会遍历工具涉及的主要依赖,同时search命令得到的路径也可以判断源码安装是否成功

@Keithwwa Keithwwa merged commit 7f8f95f into AISBench:master Jun 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants