|
| 1 | +name: Publish Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + push_to_registry: |
| 11 | + name: Push Docker image to Docker Hub |
| 12 | + if: github.event.pull_request.draft == false |
| 13 | + |
| 14 | + runs-on: ubuntu-latest |
| 15 | + env: |
| 16 | + COMMIT_SHA: ${{ github.sha }} |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + config: |
| 20 | + - { tag: "main", dockerfile: ".devops/main.Dockerfile", platform: "linux/amd64,linux/arm64" } |
| 21 | + - { tag: "main-cuda", dockerfile: ".devops/main-cuda.Dockerfile", platform: "linux/amd64" } |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Check out the repo |
| 25 | + uses: actions/checkout@v3 |
| 26 | + |
| 27 | + - name: Set up QEMU |
| 28 | + uses: docker/setup-qemu-action@v3 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Log in to Docker Hub |
| 34 | + uses: docker/login-action@v3 |
| 35 | + with: |
| 36 | + registry: ghcr.io |
| 37 | + username: ${{ github.repository_owner }} |
| 38 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Build and push Docker image (versioned) |
| 41 | + if: github.event_name == 'push' |
| 42 | + uses: docker/build-push-action@v5 |
| 43 | + with: |
| 44 | + context: . |
| 45 | + push: true |
| 46 | + platforms: ${{ matrix.config.platforms }} |
| 47 | + tags: "ghcr.io/${{ github.repository }}:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }}" |
| 48 | + file: ${{ matrix.config.dockerfile }} |
| 49 | + |
| 50 | + - name: Build and push Docker image (tagged) |
| 51 | + uses: docker/build-push-action@v4 |
| 52 | + with: |
| 53 | + context: . |
| 54 | + push: ${{ github.event_name == 'push' }} |
| 55 | + platforms: ${{ matrix.config.platforms }} |
| 56 | + tags: "ghcr.io/${{ github.repository }}:${{ matrix.config.tag }}" |
| 57 | + file: ${{ matrix.config.dockerfile }} |
0 commit comments