docker-build.yaml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
  41. - name: Extract metadata (tags, labels) for Docker
  42. id: meta
  43. uses: docker/metadata-action@v5
  44. with:
  45. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  46. # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
  47. # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
  48. # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
  49. - name: Build and push Docker image
  50. uses: docker/build-push-action@v5
  51. with:
  52. context: .
  53. push: true
  54. platforms: linux/amd64,linux/arm64
  55. tags: ${{ steps.meta.outputs.tags }}
  56. labels: ${{ steps.meta.outputs.labels }}