push-docker-image.yaml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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: Free disk space on Ubuntu runner
  39. uses: kfir4444/free-disk-space@main
  40. with:
  41. # found in: https://github.com/docker/build-push-action/issues/968
  42. tool-cache: false
  43. android: true
  44. dotnet: true
  45. haskell: true
  46. large-packages: true
  47. swap-storage: true
  48. - name: Build and push
  49. id: docker_build
  50. uses: docker/build-push-action@v2
  51. with:
  52. context: .
  53. push: ${{ github.event_name != 'pull_request' }}
  54. tags: ${{ steps.meta.outputs.tags }}
  55. - name: Image digest
  56. run: echo ${{ steps.docker_build.outputs.digest }}