push-docker-image.yaml 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. name: Push to Docker Hub
  2. on:
  3. push:
  4. branches: [ main ]
  5. tags:
  6. - "*.*.*"
  7. pull_request:
  8. branches: [ main ]
  9. jobs:
  10. build:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout
  14. uses: actions/checkout@v3
  15. - name: Docker meta
  16. id: meta
  17. uses: crazy-max/ghaction-docker-meta@v2
  18. with:
  19. # list of Docker images to use as base name for tags
  20. images: |
  21. learningathome/petals
  22. # generate Docker tags based on the following events/attributes
  23. tags: |
  24. type=ref,event=branch
  25. type=ref,event=pr
  26. type=semver,pattern={{version}}
  27. type=semver,pattern={{major}}.{{minor}}
  28. type=semver,pattern={{major}}
  29. - name: Set up Docker Buildx
  30. id: buildx
  31. uses: docker/setup-buildx-action@v1
  32. - name: Login to Docker Hub
  33. if: github.event_name != 'pull_request'
  34. uses: docker/login-action@v1
  35. with:
  36. username: ${{ secrets.DOCKER_HUB_USERNAME }}
  37. password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
  38. - name: Build and push
  39. id: docker_build
  40. uses: docker/build-push-action@v2
  41. with:
  42. context: .
  43. push: ${{ github.event_name != 'pull_request' }}
  44. tags: ${{ steps.meta.outputs.tags }}
  45. - name: Image digest
  46. run: echo ${{ steps.docker_build.outputs.digest }}