已合并
[v2.7.1] Add CI Docker images build workflow #43047
wangqi创建于 22 天前
[v2.7.1] Add CI Docker images build workflow #43047
已合并
wangqi创建于 22 天前
wangqi
wangqi
22 天前

Summary

为 v2.7.1 分支添加 .github/workflows/build-docker-images.yml,实现 CI Docker 镜像的自动构建与推送到 SWR 镜像仓库。

Related: #3073

Changes

  • 新增 .github/workflows/build-docker-images.yml
  • 支持 workflow_dispatch 手动触发和 push 自动触发(.ci/docker/** 变更时)
  • 覆盖 8 个镜像:builder (x86_64/aarch64) + test × CANN A1/A2/A3 (x86_64/aarch64)
  • 推送至 swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch,Tag 含 UTC 时间戳
  • Runner 自适应:x86_64 → ubuntu-latest,aarch64 → ubuntu-22.04-arm
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wangqi 的贡献)
wangqiwangqi
22 天前 创建了 pull request,commit 778e6a12
wangqiwangqi
22 天前 关联了issue:[Feature]: 添加 CI Docker 镜像自动构建workflow
atomgit-bot
atomgit-bot
22 天前 评论:

变更摘要

此 PR 为 v2.7.1 分支新增 .github/workflows/build-docker-images.yml 工作流,实现 CI Docker 镜像的自动化构建与推送。工作流支持手动触发及 push 自动触发(当 .ci/docker/** 或工作流文件自身变更时),覆盖 8 个镜像(builder 和 test 系列的 x86_64/aarch64 架构),构建产物推送至华为云 SWR 镜像仓库,Tag 包含 UTC 时间戳,并生成构建摘要。

主要改动

  • 新增 matrix job:动态生成镜像 tag 列表,默认包含 8 个镜像(torch-npu-buildertorch-npu-test 的 x86_64/aarch64 及 CANN A1/A2/A3 变体),同时支持通过 workflow_dispatchtag 输入参数手动指定单个 tag
  • 新增 build job:使用策略矩阵并行构建,通过 contains(matrix.tag, 'x86_64') 表达式自适应选择 ubuntu-latestubuntu-22.04-arm runner;执行磁盘清理后,调用 .ci/docker/docker_build.sh 构建镜像,并以 {tag}-{UTC时间戳} 格式打 tag 推送至 swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch
  • 新增 summary job:汇总所有 build job 的构建结果,下载 artifact 后生成 Markdown 格式的镜像拉取命令表格,输出至 GitHub Step Summary
  • 新增环境变量与权限配置:定义 REGISTRYSWR_ORGIMAGE_NAME 环境变量,并为 build job 配置 contents: read 权限;使用 docker/login-action@v3 通过 secrets.SWR_USERNAME / secrets.SWR_PASSWORD 完成 SWR 认证
likedislike
atomgit-bot
atomgit-bot
22 天前 评论:

代码审查

审查总结

本次 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_dispatchtag 输入未做任何校验或转义,在三个位置可能造成 shell 注入或 JSON 损坏;summary job 在全部 build 失败时无法优雅降级。这些问题在正常使用预定义的 8 个镜像标签时不会触发,仅在手动输入非法 tag 或全部构建失败的极端场景下暴露。建议在合并前修复 P2 的注入问题。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
ascend-robotascend-robot成员
22 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
22 天前 评论:

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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
ascend-robot
ascend-robot成员
22 天前 评论:

当前仓库存在以下 保护分支

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,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
ascend-robotascend-robot成员
22 天前 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
22 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
22 天前 添加了label:docs-ci-pipeline-running
wangqiwangqi
22 天前 修改了pull request 的描述
ascend-robotascend-robot成员
22 天前 添加了label:needs-issue
ascend-robot
ascend-robot成员
22 天前 评论:

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 .

likedislike
ascend-robot
ascend-robot成员
22 天前 评论:

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

likedislike
ascend-robotascend-robot成员
22 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
22 天前 添加了label:docs-ci-pipeline-success
wangqiwangqi
22 天前 修改了pull request 的描述
ascend-robotascend-robot成员
22 天前 删除了label:needs-issue
atomgit-bot
atomgit-bot22 天前进行代码检视2
.github/workflows/build-docker-images.yml
@@ -0,0 +73,4 @@
73+ docker tag "${IMAGE_TAG}" "${REMOTE_IMAGE}"
74+ docker push "${REMOTE_IMAGE}"
75+ mkdir -p /tmp/result
76+ echo "${REMOTE_IMAGE}" > "/tmp/result/${{ matrix.tag }}.txt"
atomgit-bot
atomgit-bot22 天前评论:

🟡 Medium Priority

build job 的 run: 块中,${{ matrix.tag }} 未经任何转义或校验就直接嵌入 shell 命令行。当用户通过 workflow_dispatch 手动触发并提供一个包含 shell 元字符(如 ;$()、反引号)的 tag 值时,该值将流经 matrix job 的输出 → fromJSONmatrix.tag,最终在三个位置造成注入:

  1. 第 69 行./docker_build.sh ${{ matrix.tag }} — 若 tag 为 foo; echo hacked,则 echo hacked 会作为独立命令执行。
  2. 第 71 行IMAGE_TAG="${{ matrix.tag }}-${TIMESTAMP}" — 若 tag 中含 $(...),会在变量赋值时触发命令替换。
  3. 第 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。

likedislike
wangqi
wangqi
22 天前 评论:

仓库写权限一般为管理员或者maintainer角色,不存在注入攻击.已解决

ascend-robotascend-robot成员
22 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
22 天前 添加了label:ci-pipeline-failed
wangqi
wangqi
22 天前 评论:

retry

likedislike
ascend-robotascend-robot成员
22 天前 删除了label:ci-pipeline-failed
ascend-robotascend-robot成员
22 天前 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
22 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
22 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
22 天前 评论:
流水线 PR-pipeline_pytorch#50396 (重试第1次) [ commitID:1c74a01d ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 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 >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can, shawnylee233, fanglanyue0916, hhz0, LiNuohang, taohuoquan]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
Jingwei Huang
Jingwei Huang成员
22 天前 评论:

/lgtm

likedislike
dilililiwhy
dilililiwhy成员
22 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
22 天前 添加了label:approvedlgtm
ascend-robotascend-robot成员
22 天前 解决了最后一个问题
ascend-robotascend-robot成员
22 天前 合入了pull request
ascend-robot
ascend-robot成员
22 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
21 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13310 [ commitID:1c74a01d ] 已完成
likedislike