Skip to content

Ascend Docker Implementation — CANN #2

Ascend Docker Implementation — CANN

Ascend Docker Implementation — CANN #2

Workflow file for this run

name: Build and Push Docker Image
on:
workflow_dispatch:
push:
branches:
- 'main'
tags:
- 'v*'
paths:
- '.github/workflows/docker.yml'
- '**/Dockerfile*'
- '**/*.sh'
pull_request:
branches:
- 'main'
paths:
- '.github/workflows/ci_docker.yml'
- '**/Dockerfile*'
- '**/*.sh'
release:
types:
- 'published'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ !contains(github.ref, 'release/')}}
jobs:
docker:
name: build-and-push-image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
registry:
- name: Docker Hub
url: docker.io
owner: cosdt
- name: GHCR
url: ghcr.io
owner: ${{ github.repository_owner }}
platform:
- linux/amd64
- linux/arm64
image:
- 'cann/ubuntu'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ matrix.registry.url }}/${{ matrix.registry.owner }}/${{ matrix.image }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.title=${{ matrix.image }}
org.opencontainers.image.description=${{ matrix.image }} built by ${{ matrix.registry.url }}/${{ matrix.registry.owner }}
org.opencontainers.image.vendor=${{ matrix.registry.owner }}
- name: Show image metadata
run: |
echo "version: ${{ steps.meta.outputs.version }}"
echo "tags: ${{ steps.meta.outputs.tags }}"
echo "labels: ${{ steps.meta.outputs.labels }}"
echo "annotations: ${{ steps.meta.outputs.annotations }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to the Docker Hub
if: ${{ github.event_name != 'pull_request' && matrix.registry.name == 'Docker Hub' }}
uses: docker/login-action@v3
with:
registry: ${{ matrix.registry.url }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to the GitHub Container
if: ${{ github.event_name != 'pull_request' && matrix.registry.name == 'GHCR' }}
uses: docker/login-action@v3
with:
registry: ${{ matrix.registry.url }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.image }}
file: ${{ matrix.image }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platform }}
build-args: |
PLATFORM=${{ matrix.platform }}