use cann image #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow will build a golang project | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
| name: CI | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: | |
| - v[0-9]+.[0-9]+.[0-9]+.[0-9]+ | |
| - v[0-9]+.[0-9]+.[0-9]+ | |
| - v[0-9]+.[0-9]+ | |
| pull_request: | |
| branches: [ "main" ] | |
| env: | |
| GO_VERSION: "1.22.5" | |
| jobs: | |
| build-vnpu: | |
| strategy: | |
| matrix: | |
| platform: | |
| - { runner: "ubuntu-22.04-arm", arch: "arm64", target: "aarch64-unknown-linux-gnu"} | |
| - { runner: "ubuntu-22.04", arch: "amd64", target: "x86_64-unknown-linux-gnu"} | |
| runs-on: ${{ matrix.platform.runner }} | |
| container: | |
| image: ascendai/cann:8.3.rc2 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Build for ${{ matrix.platform.arch }} | |
| run: cargo build --release --target ${{ matrix.platform.target }} | |
| working-directory: ./libvnpu | |
| - name: Prepare artifacts for upload | |
| run: | | |
| mkdir -p ./artifacts | |
| cp libvnpu/target/${{ matrix.platform.target }}/release/limiter ./artifacts/ | |
| cp libvnpu/target/${{ matrix.platform.target }}/release/libvnpu.so ./artifacts/ | |
| echo "/usr/local/hami-vnpu-core-assets/libvnpu.so" > ./artifacts/ld.so.preload | |
| - name: upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifacts-${{ matrix.platform.arch }} | |
| if-no-files-found: error | |
| path: ./artifacts/* | |
| build: | |
| env: | |
| IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'projecthami/ascend-device-plugin' }} | |
| runs-on: ubuntu-latest | |
| needs: ["build-vnpu"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| submodules: true | |
| - name: Get branch names. | |
| id: branch-names | |
| uses: tj-actions/branch-names@v8 | |
| - name: Download ARM64 Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-artifacts-arm64 | |
| path: ./lib/hami-vnpu-core/arm64/ | |
| - name: Download AMD64 Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-artifacts-amd64 | |
| path: ./lib/hami-vnpu-core/amd64/ | |
| - name: Docker Login | |
| if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }} | |
| uses: docker/login-action@v3.6.0 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_TOKEN }} | |
| password: ${{ secrets.DOCKERHUB_PASSWD }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Extract tag name | |
| id: tag | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| TAG_NAME="${GITHUB_REF#refs/tags/}" | |
| echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT | |
| echo "Extracted version: ${VERSION}" | |
| else | |
| echo "VERSION=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }} | |
| build-args: | | |
| BASE_IMAGE=ubuntu:20.04 | |
| GO_VERSION=${{ env.GO_VERSION }} | |
| VERSION=${{ steps.branch-names.outputs.current_branch || steps.branch-names.outputs.tag }}-${{ github.sha }} | |
| tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.VERSION }} |