Pull Request已成功合入, 合并人@ascend-robot
(感谢 wangqi 的贡献)变更摘要
此 PR 为 v2.7.1 分支新增 .github/workflows/build-docker-images.yml 工作流,实现 CI Docker 镜像的自动化构建与推送。工作流支持手动触发及 push 自动触发(当 .ci/docker/** 或工作流文件自身变更时),覆盖 8 个镜像(builder 和 test 系列的 x86_64/aarch64 架构),构建产物推送至华为云 SWR 镜像仓库,Tag 包含 UTC 时间戳,并生成构建摘要。
主要改动
- 新增
matrixjob:动态生成镜像 tag 列表,默认包含 8 个镜像(torch-npu-builder和torch-npu-test的 x86_64/aarch64 及 CANN A1/A2/A3 变体),同时支持通过workflow_dispatch的tag输入参数手动指定单个 tag - 新增
buildjob:使用策略矩阵并行构建,通过contains(matrix.tag, 'x86_64')表达式自适应选择ubuntu-latest或ubuntu-22.04-armrunner;执行磁盘清理后,调用.ci/docker/docker_build.sh构建镜像,并以{tag}-{UTC时间戳}格式打 tag 推送至swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch - 新增
summaryjob:汇总所有buildjob 的构建结果,下载 artifact 后生成 Markdown 格式的镜像拉取命令表格,输出至 GitHub Step Summary - 新增环境变量与权限配置:定义
REGISTRY、SWR_ORG、IMAGE_NAME环境变量,并为buildjob 配置contents: read权限;使用docker/login-action@v3通过secrets.SWR_USERNAME/secrets.SWR_PASSWORD完成 SWR 认证


代码审查
审查总结
本次 diff 在 .github/workflows/build-docker-images.yml 中新增了完整的 CI Docker 镜像自动构建工作流,文件共计 118 行。
审查结果:共发现 3 个问题
| 优先级 | 数量 | 说明 |
|---|---|---|
| P2 | 1 | matrix.tag 未经转义直接嵌入 shell 命令,存在命令注入风险 |
| P3 | 2 | matrix job 中单引号破坏 JSON 输出;summary job 在全量失败时跳过摘要生成 |
审查文件清单:
.github/workflows/build-docker-images.yml— 3 个问题(详见上方)
整体风险评估:中低风险。 核心逻辑(镜像构建、标签匹配、推送流程)设计正确,与 docker_build.sh 脚本的契约一致。主要问题集中在输入校验缺失和边界异常处理上——workflow_dispatch 的 tag 输入未做任何校验或转义,在三个位置可能造成 shell 注入或 JSON 损坏;summary job 在全部 build 失败时无法优雅降级。这些问题在正常使用预定义的 8 个镜像标签时不会触发,仅在手动输入非法 tag 或全部构建失败的极端场景下暴露。建议在合并前修复 P2 的注入问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ 吴环宇, huangjingwei (2/2) | ✅ 吴环宇 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wangqi0808, thanks for your pull request. All authors of the commits have signed the CLA. 👍


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.10.0 | ||
| v2.7.1-26.1.0 | ||
| v2.12.0-26.1.0 | ||
| v2.7.1 | ||
| v2.9.0 | ||
| v2.12.0 | ||
| v2.11.0-26.1.0 | ||
| v2.11.0 | ||
| v2.10.0-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| ci-test |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


ascend docs pipeline is running...


Linking Issue Notice
@wangqi0808 , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .


✅ 跳过 docs ci 检查,没有需要检查的文档文件


🟡 Medium Priority
在 build job 的 run: 块中,${{ matrix.tag }} 未经任何转义或校验就直接嵌入 shell 命令行。当用户通过 workflow_dispatch 手动触发并提供一个包含 shell 元字符(如 ;、$()、反引号)的 tag 值时,该值将流经 matrix job 的输出 → fromJSON → matrix.tag,最终在三个位置造成注入:
- 第 69 行:
./docker_build.sh ${{ matrix.tag }}— 若 tag 为foo; echo hacked,则echo hacked会作为独立命令执行。 - 第 71 行:
IMAGE_TAG="${{ matrix.tag }}-${TIMESTAMP}"— 若 tag 中含$(...),会在变量赋值时触发命令替换。 - 第 76 行:
"/tmp/result/${{ matrix.tag }}.txt"— 若 tag 中含/,会导致文件路径错误、写入失败。
虽然只有具备仓库写权限的用户才能触发 workflow_dispatch,但作为纵深防御,不应信任该输入。这也会导致误输入特殊字符时工作流行为异常(而非给出清晰的报错)。
建议:将 matrix.tag 通过环境变量传入 shell,避免直接拼接。在 run: 块开头添加 MATRIX_TAG="${{ matrix.tag }}" 并用 shell 变量替换后续三处引用:第 69 行改为 ./docker_build.sh "${MATRIX_TAG}",第 71 行改为 IMAGE_TAG="${MATRIX_TAG}-${TIMESTAMP}",第 76 行改为 echo "${REMOTE_IMAGE}" > "/tmp/result/${MATRIX_TAG}.txt"。同时在 matrix job 中对 inputs.tag 做基本校验(如仅允许字母、数字、连字符、点号),对非法输入直接 fail-fast。


retry


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_ARM_A3_Part_01 | ✅ | >>> |
| UT_ARM_A3_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/lgtm


/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.




Summary
为 v2.7.1 分支添加
.github/workflows/build-docker-images.yml,实现 CI Docker 镜像的自动构建与推送到 SWR 镜像仓库。Related: #3073
Changes
.github/workflows/build-docker-images.ymlworkflow_dispatch手动触发和push自动触发(.ci/docker/**变更时)swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch,Tag 含 UTC 时间戳ubuntu-latest,aarch64 →ubuntu-22.04-arm