Optimize multi-arch Docker images #13
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: 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) || '' }} | |
| outputs: type=image,name=ghcr.io/${{ github.repository }},annotation-index.org.opencontainers.image.title=Python Tutorial,annotation-index.org.opencontainers.image.description=A containerized Python tutorial environment with Jupyter Lab. | |
| - 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) || '' }} | |
| outputs: type=image,name=ghcr.io/${{ github.repository }},annotation-index.org.opencontainers.image.title=Python Tutorial,annotation-index.org.opencontainers.image.description=A containerized Python tutorial environment with Jupyter Lab. |