Optimize multi-arch Docker images #14
Workflow file for this run
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
| --- | |
| 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 }} | |
| provenance: false | |
| build-args: | | |
| PYTORCH_VARIANT=${{ matrix.variant }} | |
| 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: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver-opts: | | |
| image=moby/buildkit:latest | |
| network=host | |
| - 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 | |
| run: | | |
| # Create and push multi-architecture manifest for CPU variant | |
| docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cpu \ | |
| ghcr.io/${{ github.repository }}:cpu-amd64 \ | |
| ghcr.io/${{ github.repository }}:cpu-arm64 | |
| # If on main branch, also tag as latest | |
| if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:latest \ | |
| ghcr.io/${{ github.repository }}:cpu-amd64 \ | |
| ghcr.io/${{ github.repository }}:cpu-arm64 | |
| fi | |
| # If this is a tag, add version tag for CPU | |
| if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then | |
| docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cpu-${{ github.ref_name }} \ | |
| ghcr.io/${{ github.repository }}:cpu-amd64 \ | |
| ghcr.io/${{ github.repository }}:cpu-arm64 | |
| fi | |
| - name: Create and push CUDA manifest | |
| run: | | |
| # Create and push multi-architecture manifest for CUDA variant | |
| docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cuda \ | |
| ghcr.io/${{ github.repository }}:cuda-amd64 \ | |
| ghcr.io/${{ github.repository }}:cuda-arm64 | |
| # If this is a tag, add version tag for CUDA | |
| if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then | |
| docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:cuda-${{ github.ref_name }} \ | |
| ghcr.io/${{ github.repository }}:cuda-amd64 \ | |
| ghcr.io/${{ github.repository }}:cuda-arm64 | |
| fi |