|
| 1 | +--- |
| 2 | +name: Build Tutorial Container |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths-ignore: |
| 9 | + - "*.md" |
| 10 | + - slides/** |
| 11 | + - images/** |
| 12 | + - .gitignore |
| 13 | + tags: |
| 14 | + - "v*.*" |
| 15 | + - "v*.*.*" |
| 16 | + pull_request: |
| 17 | + paths-ignore: |
| 18 | + - "*.md" |
| 19 | + - slides/** |
| 20 | + - images/** |
| 21 | + - .gitignore |
| 22 | + workflow_dispatch: |
| 23 | + |
| 24 | +jobs: |
| 25 | + build-and-push: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + packages: write |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + arch: [amd64, arm64] |
| 32 | + variant: [cpu, cuda] |
| 33 | + fail-fast: false |
| 34 | + steps: |
| 35 | + - name: Checkout code |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set up QEMU |
| 39 | + uses: docker/setup-qemu-action@v3 |
| 40 | + |
| 41 | + - name: Setup Docker Buildx |
| 42 | + uses: docker/setup-buildx-action@v3 |
| 43 | + |
| 44 | + - name: Log in to GHCR |
| 45 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 46 | + uses: docker/login-action@v3 |
| 47 | + with: |
| 48 | + registry: ghcr.io |
| 49 | + username: ${{ github.actor }} |
| 50 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Docker meta |
| 53 | + id: meta |
| 54 | + uses: docker/metadata-action@v5 |
| 55 | + with: |
| 56 | + images: ghcr.io/${{ github.repository }} |
| 57 | + tags: | |
| 58 | + type=raw,value=${{ matrix.variant }}-${{ matrix.arch }},enable=${{ github.ref == 'refs/heads/main' }} |
| 59 | + type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-pr-${{ github.event.pull_request.number }},enable=${{ github.event_name == 'pull_request' }} |
| 60 | + type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }} |
| 61 | + type=raw,value=${{ matrix.variant }}-${{ matrix.arch }}-sha-${{ github.sha }} |
| 62 | +
|
| 63 | + - name: Build and push |
| 64 | + uses: docker/build-push-action@v6 |
| 65 | + with: |
| 66 | + context: . |
| 67 | + platforms: linux/${{ matrix.arch }} |
| 68 | + push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + provenance: false |
| 71 | + build-args: | |
| 72 | + PYTORCH_VARIANT=${{ matrix.variant }} |
| 73 | +
|
| 74 | + create-manifests: |
| 75 | + needs: build-and-push |
| 76 | + runs-on: ubuntu-latest |
| 77 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 78 | + permissions: |
| 79 | + packages: write |
| 80 | + steps: |
| 81 | + - name: Set up QEMU |
| 82 | + uses: docker/setup-qemu-action@v3 |
| 83 | + |
| 84 | + - name: Setup Docker Buildx |
| 85 | + uses: docker/setup-buildx-action@v3 |
| 86 | + with: |
| 87 | + driver-opts: | |
| 88 | + image=moby/buildkit:latest |
| 89 | + network=host |
| 90 | +
|
| 91 | + - name: Log in to GHCR |
| 92 | + uses: docker/login-action@v3 |
| 93 | + with: |
| 94 | + registry: ghcr.io |
| 95 | + username: ${{ github.actor }} |
| 96 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + |
| 98 | + - name: Create and push CPU manifest |
| 99 | + run: | |
| 100 | + # Determine the correct tag suffixes based on the event type |
| 101 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 102 | + # PR build - use the commit SHA for more predictable references |
| 103 | + AMD64_TAG="cpu-amd64-sha-${{ github.sha }}" |
| 104 | + ARM64_TAG="cpu-arm64-sha-${{ github.sha }}" |
| 105 | + TARGET_TAG="cpu-sha-${{ github.sha }}" |
| 106 | + elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then |
| 107 | + # Tag build - use tag version in the name |
| 108 | + AMD64_TAG="cpu-amd64-${{ github.ref_name }}" |
| 109 | + ARM64_TAG="cpu-arm64-${{ github.ref_name }}" |
| 110 | + TARGET_TAG="cpu-${{ github.ref_name }}" |
| 111 | + else |
| 112 | + # Main branch build - use simple arch tags |
| 113 | + AMD64_TAG="cpu-amd64" |
| 114 | + ARM64_TAG="cpu-arm64" |
| 115 | + TARGET_TAG="cpu" |
| 116 | + fi |
| 117 | +
|
| 118 | + # Create the manifest with the correct tag names |
| 119 | + echo "Creating CPU manifest using $AMD64_TAG and $ARM64_TAG" |
| 120 | + docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:${TARGET_TAG} \ |
| 121 | + ghcr.io/${{ github.repository }}:${AMD64_TAG} \ |
| 122 | + ghcr.io/${{ github.repository }}:${ARM64_TAG} |
| 123 | +
|
| 124 | + # If on main branch, also tag as latest |
| 125 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 126 | + docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:latest \ |
| 127 | + ghcr.io/${{ github.repository }}:${AMD64_TAG} \ |
| 128 | + ghcr.io/${{ github.repository }}:${ARM64_TAG} |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Create and push CUDA manifest |
| 132 | + run: | |
| 133 | + # Determine the correct tag suffixes based on the event type |
| 134 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 135 | + # PR build - use the commit SHA for more predictable references |
| 136 | + AMD64_TAG="cuda-amd64-sha-${{ github.sha }}" |
| 137 | + ARM64_TAG="cuda-arm64-sha-${{ github.sha }}" |
| 138 | + TARGET_TAG="cuda-sha-${{ github.sha }}" |
| 139 | + elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then |
| 140 | + # Tag build - use tag version in the name |
| 141 | + AMD64_TAG="cuda-amd64-${{ github.ref_name }}" |
| 142 | + ARM64_TAG="cuda-arm64-${{ github.ref_name }}" |
| 143 | + TARGET_TAG="cuda-${{ github.ref_name }}" |
| 144 | + else |
| 145 | + # Main branch build - use simple arch tags |
| 146 | + AMD64_TAG="cuda-amd64" |
| 147 | + ARM64_TAG="cuda-arm64" |
| 148 | + TARGET_TAG="cuda" |
| 149 | + fi |
| 150 | +
|
| 151 | + # Create the manifest with the correct tag names |
| 152 | + echo "Creating CUDA manifest using $AMD64_TAG and $ARM64_TAG" |
| 153 | + docker buildx imagetools create --tag ghcr.io/${{ github.repository }}:${TARGET_TAG} \ |
| 154 | + ghcr.io/${{ github.repository }}:${AMD64_TAG} \ |
| 155 | + ghcr.io/${{ github.repository }}:${ARM64_TAG} |
0 commit comments