docker-build.yaml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #
  2. name: Create and publish a Docker image
  3. # Configures this workflow to run every time a change is pushed to the branch called `release`.
  4. on:
  5. push:
  6. branches:
  7. - main
  8. - dev
  9. tags:
  10. - v*
  11. # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
  12. env:
  13. REGISTRY: ghcr.io
  14. IMAGE_NAME: ${{ github.repository }}
  15. # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
  16. jobs:
  17. build-and-push-image:
  18. runs-on: ubuntu-latest
  19. # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
  20. permissions:
  21. contents: read
  22. packages: write
  23. #
  24. steps:
  25. - name: Checkout repository
  26. uses: actions/checkout@v4
  27. # Required for multi architecture build
  28. - name: Set up QEMU
  29. uses: docker/setup-qemu-action@v3
  30. # Required for multi architecture build
  31. - name: Set up Docker Buildx
  32. uses: docker/setup-buildx-action@v3
  33. # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
  34. - name: Log in to the Container registry
  35. uses: docker/login-action@v3
  36. with:
  37. registry: ${{ env.REGISTRY }}
  38. username: ${{ github.actor }}
  39. password: ${{ secrets.GITHUB_TOKEN }}
  40. - name: Extract metadata for Docker images
  41. id: meta
  42. uses: docker/metadata-action@v5
  43. with:
  44. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  45. # This configuration dynamically generates tags based on the branch, tag, commit, and custom suffix for lite version.
  46. tags: |
  47. type=ref,event=branch
  48. type=ref,event=tag
  49. type=sha,prefix=git-
  50. type=semver,pattern={{version}}
  51. type=semver,pattern={{major}}.{{minor}}
  52. flavor: |
  53. latest=${{ github.ref == 'refs/heads/main' }}
  54. - name: Build and push Docker image
  55. uses: docker/build-push-action@v5
  56. with:
  57. context: .
  58. push: true
  59. platforms: linux/amd64,linux/arm64
  60. tags: ${{ steps.meta.outputs.tags }}
  61. labels: ${{ steps.meta.outputs.labels }}