Skip to content

Optimize multi-arch Docker images #11

Optimize multi-arch Docker images

Optimize multi-arch Docker images #11

Workflow file for this run

---
name: Build Tutorial Container
on:
push:
branches:
- main
paths-ignore:
- "*.md"
- slides/**
- images/**
- .gitignore
tags:
- "v*.*"
- "v*.*.*"
pull_request:
paths-ignore:
- "*.md"
- slides/**
- images/**
- .gitignore
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
arch: [amd64, arm64]
variant: [cpu, cuda]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }},enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-pr-${{ github.event.pull_request.number }},enable=${{ github.event_name == 'pull_request' }}
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-sha-${{ github.sha }},prefix=
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/${{ matrix.arch }}
push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
build-args: |
PYTORCH_VARIANT=${{ matrix.variant }}
outputs: type=image,name=ghcr.io/${{ github.repository }},annotation-index.org.opencontainers.image.description=Python Tutorial ${{ matrix.variant }} variant, ${{ matrix.arch }} architecture
create-manifests:
needs: build-and-push
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
permissions:
packages: write
steps:
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push CPU manifest
uses: docker/build-push-action@v6
with:
context: .
target: builder
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: |
ghcr.io/${{ github.repository }}:cpu
${{ startsWith(github.ref, 'refs/tags/') && format('ghcr.io/{0}:cpu-{1}', github.repository, github.ref_name) || '' }}
${{ github.ref == 'refs/heads/main' && format('ghcr.io/{0}:latest', github.repository) || '' }}
- name: Create and push CUDA manifest
uses: docker/build-push-action@v6
with:
context: .
target: builder
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: |
ghcr.io/${{ github.repository }}:cuda
${{ startsWith(github.ref, 'refs/tags/') && format('ghcr.io/{0}:cuda-{1}', github.repository, github.ref_name) || '' }}