docker-publish.yml 2.6 KB

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