docker-publish.yml 2.8 KB

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