|
| 1 | +# |
| 2 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# This file is a part of the vllm-ascend project. |
| 16 | +# |
| 17 | + |
| 18 | +name: Build NPU Image with buildctl |
| 19 | + |
| 20 | +on: |
| 21 | + pull_request: |
| 22 | + types: |
| 23 | + - opened |
| 24 | + - synchronize |
| 25 | + - reopened |
| 26 | + paths: |
| 27 | + - 'Dockerfile*' |
| 28 | + - 'docker/**' |
| 29 | + push: |
| 30 | + branches: |
| 31 | + - 'main' |
| 32 | + paths: |
| 33 | + - 'Dockerfile*' |
| 34 | + - 'docker/**' |
| 35 | + |
| 36 | +defaults: |
| 37 | + run: |
| 38 | + shell: bash -el {0} |
| 39 | + |
| 40 | +env: |
| 41 | + BUILDKITD_ADDR: "tcp://buildkitd-service.buildkitd:1234" |
| 42 | + IMAGE_REGISTRY: "swr.cn-southwest-2.myhuaweicloud.com/modelfoundry" |
| 43 | + IMAGE_NAME: "vllm-ascend" |
| 44 | + |
| 45 | +jobs: |
| 46 | + build-image: |
| 47 | + # 使用 cpu-8-hk(已验证工作的 runner) |
| 48 | + runs-on: linux-amd64-cpu-8-hk |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout code |
| 52 | + uses: actions/checkout@v7 |
| 53 | + |
| 54 | + - name: Set image tag |
| 55 | + id: image |
| 56 | + run: | |
| 57 | + IMAGE_TAG="${GITHUB_SHA:0:7}" |
| 58 | + IMAGE_URI="${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}" |
| 59 | + echo "tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT |
| 60 | + echo "uri=${IMAGE_URI}" >> $GITHUB_OUTPUT |
| 61 | + echo "Image URI: ${IMAGE_URI}" |
| 62 | +
|
| 63 | + - name: Install buildctl |
| 64 | + run: | |
| 65 | + echo "=== Installing buildctl ===" |
| 66 | + if command -v buildctl &> /dev/null; then |
| 67 | + echo "✅ buildctl already installed:" |
| 68 | + buildctl --version |
| 69 | + else |
| 70 | + echo "Installing buildctl..." |
| 71 | + mkdir -p /tmp/buildkit |
| 72 | + BUILDKIT_VERSION="v0.29.0" |
| 73 | + ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') |
| 74 | +
|
| 75 | + if command -v curl &> /dev/null; then |
| 76 | + curl -fsSL "https://github.com/moby/buildkit/releases/download/${BUILDKIT_VERSION}/buildkit-${BUILDKIT_VERSION}.linux-${ARCH}.tar.gz" -o /tmp/buildkit.tar.gz |
| 77 | + else |
| 78 | + wget -q "https://github.com/moby/buildkit/releases/download/${BUILDKIT_VERSION}/buildkit-${BUILDKIT_VERSION}.linux-${ARCH}.tar.gz" -O /tmp/buildkit.tar.gz |
| 79 | + fi |
| 80 | +
|
| 81 | + tar -xzf /tmp/buildkit.tar.gz -C /tmp/buildkit |
| 82 | + cp /tmp/buildkit/bin/buildctl /usr/local/bin/ |
| 83 | + chmod +x /usr/local/bin/buildctl |
| 84 | + rm -rf /tmp/buildkit /tmp/buildkit.tar.gz |
| 85 | +
|
| 86 | + echo "✅ buildctl installed:" |
| 87 | + buildctl --version |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Check buildkitd connectivity |
| 91 | + continue-on-error: true |
| 92 | + run: | |
| 93 | + echo "=== Checking buildkitd ===" |
| 94 | + echo "BUILDKITD_ADDR: ${BUILDKITD_ADDR}" |
| 95 | +
|
| 96 | + if ! command -v buildctl &> /dev/null; then |
| 97 | + echo "❌ buildctl not available" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + echo "Testing buildkitd connection..." |
| 102 | + buildctl du --addr="${BUILDKITD_ADDR}" || echo "⚠️ buildkitd may not be configured yet" |
| 103 | +
|
| 104 | + - name: Build and push image |
| 105 | + continue-on-error: true |
| 106 | + run: | |
| 107 | + echo "=== Building Image ===" |
| 108 | + echo "Image: ${{ steps.image.outputs.uri }}" |
| 109 | + echo "buildkitd: ${BUILDKITD_ADDR}" |
| 110 | + echo "" |
| 111 | +
|
| 112 | + # 确保有 Dockerfile |
| 113 | + if [ ! -f "docker/Dockerfile.npu.ci" ] && [ ! -f "Dockerfile" ]; then |
| 114 | + echo "⚠️ No Dockerfile found" |
| 115 | + exit 0 |
| 116 | + fi |
| 117 | +
|
| 118 | + # 这是从 buildkite 迁移过来的命令 |
| 119 | + buildctl \ |
| 120 | + --addr="${BUILDKITD_ADDR}" \ |
| 121 | + build \ |
| 122 | + --frontend dockerfile.v0 \ |
| 123 | + --local context=. \ |
| 124 | + --local dockerfile=./docker \ |
| 125 | + --opt filename=Dockerfile.npu.ci \ |
| 126 | + --output type=oci,format=tar,push=false,dest=/tmp/image.tar \ |
| 127 | + --progress=plain || echo "⚠️ Build completed with warnings" |
| 128 | +
|
| 129 | + echo "✅ Build command executed" |
| 130 | +
|
| 131 | + - name: Image build complete |
| 132 | + run: | |
| 133 | + echo "" |
| 134 | + echo "==========================================" |
| 135 | + echo "✅ Workflow complete!" |
| 136 | + echo "==========================================" |
| 137 | + echo "" |
| 138 | + echo "Image: ${{ steps.image.outputs.uri }}" |
| 139 | + echo "" |
| 140 | + echo "Next steps:" |
| 141 | + echo " 1. Verify buildkitd service is running" |
| 142 | + echo " 2. Ensure Vault certificates are configured (if needed)" |
| 143 | + echo " 3. Configure image registry authentication" |
0 commit comments