docker-publish.yml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. # Install the cosign tool except on PR
  33. # https://github.com/sigstore/cosign-installer
  34. - name: Install cosign
  35. if: github.event_name != 'pull_request'
  36. uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
  37. with:
  38. cosign-release: "v2.1.1"
  39. # Set up BuildKit Docker container builder to be able to build
  40. # multi-platform images and export cache
  41. # https://github.com/docker/setup-buildx-action
  42. - name: Set up Docker Buildx
  43. uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
  44. # Login against a Docker registry except on PR
  45. # https://github.com/docker/login-action
  46. - name: Log into registry ${{ env.REGISTRY }}
  47. if: github.event_name != 'pull_request'
  48. uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
  49. with:
  50. registry: ${{ env.REGISTRY }}
  51. username: ${{ github.actor }}
  52. password: ${{ secrets.GITHUB_TOKEN }}
  53. # Extract metadata (tags, labels) for Docker
  54. # https://github.com/docker/metadata-action
  55. - name: Extract Docker metadata
  56. id: meta
  57. uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
  58. with:
  59. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  60. tags: |
  61. type=ref,event=branch
  62. type=ref,event=pr
  63. # set latest tag for default branch
  64. type=raw,value=latest,enable={{is_default_branch}}
  65. type=semver,pattern={{version}}
  66. type=semver,pattern={{major}}.{{minor}}
  67. # Build and push Docker image with Buildx (don't push on PR)
  68. # https://github.com/docker/build-push-action
  69. - name: Build and push Docker image
  70. id: build-and-push
  71. uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
  72. with:
  73. context: .
  74. push: ${{ github.event_name != 'pull_request' }}
  75. tags: ${{ steps.meta.outputs.tags }}
  76. labels: ${{ steps.meta.outputs.labels }}
  77. cache-from: type=gha
  78. cache-to: type=gha,mode=max