docker-publish.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. name: Docker
  2. # This workflow uses actions that are not certified by GitHub.
  3. # They are provided by a third-party and are governed by
  4. # separate terms of service, privacy policy, and support
  5. # documentation.
  6. on:
  7. # schedule:
  8. # - cron: '30 20 * * *'
  9. push:
  10. branches: ["*"]
  11. # Publish semver tags as releases.
  12. tags: ["v*.*.*"]
  13. pull_request:
  14. branches: ["{{is_default_branch}}"]
  15. env:
  16. # Use docker.io for Docker Hub if empty
  17. REGISTRY: ghcr.io
  18. # github.repository as <account>/<repo>
  19. IMAGE_NAME: ${{ github.repository }}
  20. jobs:
  21. build:
  22. runs-on: ubuntu-latest
  23. permissions:
  24. contents: read
  25. packages: write
  26. # This is used to complete the identity challenge
  27. # with sigstore/fulcio when running outside of PRs.
  28. id-token: write
  29. steps:
  30. - name: Checkout repository
  31. uses: actions/checkout@v3
  32. # Set up BuildKit Docker container builder to be able to build
  33. # multi-platform images and export cache
  34. # https://github.com/docker/setup-buildx-action
  35. - name: Set up Docker Buildx
  36. uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
  37. # Login against a Docker registry except on PR
  38. # https://github.com/docker/login-action
  39. - name: Log into registry ${{ env.REGISTRY }}
  40. if: github.event_name != 'pull_request'
  41. uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
  42. with:
  43. registry: ${{ env.REGISTRY }}
  44. username: ${{ github.actor }}
  45. password: ${{ secrets.GITHUB_TOKEN }}
  46. # Extract metadata (tags, labels) for Docker
  47. # https://github.com/docker/metadata-action
  48. - name: Extract Docker metadata
  49. id: meta
  50. uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
  51. with:
  52. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  53. tags: |
  54. type=ref,event=branch
  55. type=ref,event=pr
  56. # set latest tag for default branch
  57. type=raw,value=latest,enable={{is_default_branch}}
  58. type=semver,pattern={{version}}
  59. type=semver,pattern={{major}}.{{minor}}
  60. # Build and push Docker image with Buildx (don't push on PR)
  61. # https://github.com/docker/build-push-action
  62. - name: Build and push Docker image
  63. id: build-and-push
  64. uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
  65. with:
  66. context: .
  67. push: ${{ github.event_name != 'pull_request' }}
  68. tags: ${{ steps.meta.outputs.tags }}
  69. labels: ${{ steps.meta.outputs.labels }}
  70. cache-from: type=gha
  71. cache-to: type=gha,mode=max