|
| 1 | +name: Docker |
| 2 | + |
| 3 | +# This workflow uses actions that are not certified by GitHub. |
| 4 | +# They are provided by a third-party and are governed by |
| 5 | +# separate terms of service, privacy policy, and support |
| 6 | +# documentation. |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: [ "PyTorch" ] |
| 11 | + # Publish semver tags as releases. |
| 12 | + tags: [ 'v*.*.*' ] |
| 13 | + pull_request: |
| 14 | + branches: [ "PyTorch" ] |
| 15 | + |
| 16 | +env: |
| 17 | + REGISTRY: |
| 18 | + IMAGE_NAME: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO }} |
| 19 | + |
| 20 | +jobs: |
| 21 | + build_latest: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@main |
| 27 | + |
| 28 | + - name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@v3 |
| 30 | + |
| 31 | + - name: Build image (without tag for pull request) |
| 32 | + if: github.event_name == 'pull_request' |
| 33 | + run: docker build -f Dockerfile . |
| 34 | + |
| 35 | + - name: Build image |
| 36 | + if: github.event_name == 'push' && github.ref == 'refs/heads/PyTorch' |
| 37 | + run: docker build -f Dockerfile --tag ${IMAGE_NAME}:pytorch . |
| 38 | + |
| 39 | + - name: Login to Dockerhub container registry |
| 40 | + if: github.event_name == 'push' && github.ref == 'refs/heads/PyTorch' |
| 41 | + run: docker login -u ${{ vars.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Push image |
| 44 | + if: github.event_name == 'push' && github.ref == 'refs/heads/PyTorch' |
| 45 | + run: docker push ${IMAGE_NAME}:pytorch |
| 46 | + |
| 47 | + build_release: |
| 48 | + # Build an extra image for tagged commits |
| 49 | + runs-on: ubuntu-latest |
| 50 | + if: startsWith(github.event.ref, 'refs/tags') |
| 51 | + steps: |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@main |
| 54 | + |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@v3 |
| 57 | + |
| 58 | + - name: Build image |
| 59 | + run: docker build -f Dockerfile --tag ${IMAGE_NAME}:${{ github.ref_name }} . |
| 60 | + |
| 61 | + - name: Login to Dockerhub container registry |
| 62 | + run: docker login -u ${{ vars.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} |
| 63 | + |
| 64 | + - name: Push image |
| 65 | + run: docker push ${IMAGE_NAME}:${{ github.ref_name }} |
0 commit comments