docker-publish.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. strategy:
  26. fail-fast: false
  27. matrix:
  28. include:
  29. - dockerfile: ./Dockerfile
  30. image: ghcr.io/${{ github.repository }}
  31. flavour: ""
  32. - dockerfile: ./Dockerfile.alpine
  33. image: ghcr.io/${{ github.repository }}
  34. flavour: "-alpine"
  35. permissions:
  36. contents: read
  37. packages: write
  38. # This is used to complete the identity challenge
  39. # with sigstore/fulcio when running outside of PRs.
  40. id-token: write
  41. steps:
  42. - name: Checkout repository
  43. uses: actions/checkout@v4
  44. # Set up BuildKit Docker container builder to be able to build
  45. # multi-platform images and export cache
  46. # https://github.com/docker/setup-buildx-action
  47. - name: Set up Docker Buildx
  48. uses: docker/setup-buildx-action@v3
  49. # Login against a Docker registry except on PR
  50. # https://github.com/docker/login-action
  51. - name: Log into registry ${{ env.REGISTRY }}
  52. if: github.event_name != 'pull_request'
  53. uses: docker/login-action@v3
  54. with:
  55. registry: ${{ env.REGISTRY }}
  56. username: ${{ github.actor }}
  57. password: ${{ secrets.GITHUB_TOKEN }}
  58. # Extract metadata (tags, labels) for Docker
  59. # https://github.com/docker/metadata-action
  60. - name: Extract Docker metadata
  61. id: meta
  62. uses: docker/metadata-action@v5
  63. with:
  64. images: ${{ matrix.image }}
  65. tags: |
  66. # set latest tag for default branch
  67. type=raw,value=latest${{ matrix.flavour }},enable={{is_default_branch}}
  68. type=semver,pattern={{major}}${{ matrix.flavour }}
  69. type=semver,pattern={{major}}.{{minor}}${{ matrix.flavour }}
  70. type=semver,pattern={{major}}.{{minor}}.{{patch}}${{ matrix.flavour }}
  71. # Build and push Docker image with Buildx (don't push on PR)
  72. # https://github.com/docker/build-push-action
  73. - name: Build and push Docker image
  74. id: build-and-push
  75. uses: docker/build-push-action@v5
  76. with:
  77. context: .
  78. file: ${{ matrix.dockerfile }}
  79. platforms: linux/amd64,linux/arm64
  80. push: ${{ github.event_name != 'pull_request' }}
  81. tags: ${{ steps.meta.outputs.tags }}
  82. labels: ${{ steps.meta.outputs.labels }}
  83. cache-from: type=gha
  84. cache-to: type=gha,mode=max