Files
TorchNPU/.github/workflows/build-docker-images.yml
T
ascend-robot 5ce235ccaf Add CI Docker images build workflow
Co-authored-by: wangqi<2801406898@qq.com>



# message auto-generated for no-merge-commit merge:
!43071 merge master into master

Add CI Docker images build workflow

Created-by: wangqi0808
Commit-by: wangqi
Merged-by: ascend-robot
Description: ## Summary

添加 `.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`

See merge request: Ascend/pytorch!43071
2026-07-29 15:06:27 +08:00

119 lines
3.9 KiB
YAML

name: Build build/test Docker Images
on:
workflow_dispatch:
inputs:
tag:
description: 'Single image tag to build (without timestamp). Leave empty to build all.'
required: false
type: string
push:
paths:
- .ci/docker/**
- .github/workflows/build-docker-images.yml
env:
REGISTRY: swr.cn-north-4.myhuaweicloud.com
SWR_ORG: frameworkptadapter
IMAGE_NAME: pytorch
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.set.outputs.tags }}
steps:
- id: set
run: |
if [ -n "${{ inputs.tag }}" ]; then
TAGS='["${{ inputs.tag }}"]'
else
TAGS='["torch-npu-builder-x86_64-torch-master","torch-npu-builder-aarch64-torch-master","torch-npu-test-x86_64-cann-a1-py3.10-torch-master","torch-npu-test-x86_64-cann-a2-py3.10-torch-master","torch-npu-test-x86_64-cann-a3-py3.10-torch-master","torch-npu-test-aarch64-cann-a1-py3.10-torch-master","torch-npu-test-aarch64-cann-a2-py3.10-torch-master","torch-npu-test-aarch64-cann-a3-py3.10-torch-master"]'
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
build:
needs: matrix
permissions:
contents: read
strategy:
fail-fast: false
matrix:
tag: ${{ fromJSON(needs.matrix.outputs.tags) }}
runs-on: ${{ contains(matrix.tag, 'x86_64') && 'ubuntu-latest' || 'ubuntu-22.04-arm' }}
steps:
- name: Free up disk space
run: |
sudo rm -rf /usr/local/lib/android /opt/ghc /usr/local/share/boost
sudo rm -rf /usr/share/dotnet /usr/local/share/powershell
sudo rm -rf /opt/hostedtoolcache
docker system prune -af
sudo apt clean && sudo apt autoremove -y
df -h
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to SWR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.SWR_USERNAME }}
password: ${{ secrets.SWR_PASSWORD }}
- name: Build and push image
run: |
TIMESTAMP=$(date -u +%Y%m%d%H%M)
cd .ci/docker
chmod +x ./docker_build.sh
TIMESTAMP=${TIMESTAMP} ./docker_build.sh ${{ matrix.tag }}
IMAGE_TAG="${{ matrix.tag }}-${TIMESTAMP}"
REMOTE_IMAGE="${{ env.REGISTRY }}/${{ env.SWR_ORG }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG}"
docker tag "${IMAGE_TAG}" "${REMOTE_IMAGE}"
docker push "${REMOTE_IMAGE}"
mkdir -p /tmp/result
echo "${REMOTE_IMAGE}" > "/tmp/result/${{ matrix.tag }}.txt"
echo "Pushed ${REMOTE_IMAGE}"
- name: Upload result
if: always()
uses: actions/upload-artifact@v4
with:
name: result-${{ matrix.tag }}
path: /tmp/result/${{ matrix.tag }}.txt
retention-days: 1
summary:
needs: [matrix, build]
runs-on: ubuntu-latest
if: always()
steps:
- name: Download results
uses: actions/download-artifact@v4
with:
pattern: result-*
path: /tmp/results
merge-multiple: true
- name: Generate summary
run: |
echo "## Docker Image Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| # | Image | Pull Command |" >> $GITHUB_STEP_SUMMARY
echo "|---|-------|-------------|" >> $GITHUB_STEP_SUMMARY
if [ -d /tmp/results ] && [ "$(ls -A /tmp/results 2>/dev/null)" ]; then
COUNT=1
for f in /tmp/results/*.txt; do
IMAGE=$(cat "$f")
echo "| ${COUNT} | \`${IMAGE##*:}\` | \`docker pull ${IMAGE}\` |" >> $GITHUB_STEP_SUMMARY
COUNT=$((COUNT + 1))
done
else
echo "| - | No images built | - |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** \`${{ env.REGISTRY }}/${{ env.SWR_ORG }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY