build_and_push_docker_images.yaml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. name: Build and push docker images
  2. concurrency:
  3. group: docker-build-${{ github.event_name }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. workflow_call:
  7. inputs:
  8. profile:
  9. required: true
  10. type: string
  11. latest:
  12. required: true
  13. type: string
  14. publish:
  15. required: true
  16. type: boolean
  17. otp_vsn:
  18. required: true
  19. type: string
  20. elixir_vsn:
  21. required: true
  22. type: string
  23. builder_vsn:
  24. required: true
  25. type: string
  26. secrets:
  27. DOCKER_HUB_USER:
  28. required: true
  29. DOCKER_HUB_TOKEN:
  30. required: true
  31. AWS_ACCESS_KEY_ID:
  32. required: true
  33. AWS_SECRET_ACCESS_KEY:
  34. required: true
  35. workflow_dispatch:
  36. inputs:
  37. ref:
  38. required: false
  39. profile:
  40. required: false
  41. type: string
  42. default: 'emqx'
  43. latest:
  44. required: false
  45. type: boolean
  46. default: false
  47. publish:
  48. required: false
  49. type: boolean
  50. default: false
  51. otp_vsn:
  52. required: false
  53. type: string
  54. default: '25.3.2-2'
  55. elixir_vsn:
  56. required: false
  57. type: string
  58. default: '1.15.7'
  59. builder_vsn:
  60. required: false
  61. type: string
  62. default: '5.3-2'
  63. permissions:
  64. contents: read
  65. jobs:
  66. build:
  67. runs-on: ${{ github.repository_owner == 'emqx' && fromJSON(format('["self-hosted","ephemeral","linux","{0}"]', matrix.arch)) || 'ubuntu-22.04' }}
  68. container: "ghcr.io/emqx/emqx-builder/${{ inputs.builder_vsn }}:${{ inputs.elixir_vsn }}-${{ inputs.otp_vsn }}-debian11"
  69. outputs:
  70. PKG_VSN: ${{ steps.build.outputs.PKG_VSN }}
  71. strategy:
  72. fail-fast: false
  73. matrix:
  74. profile:
  75. - ${{ inputs.profile }}
  76. - ${{ inputs.profile }}-elixir
  77. arch:
  78. - x64
  79. - arm64
  80. steps:
  81. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  82. with:
  83. ref: ${{ github.event.inputs.ref }}
  84. - run: git config --global --add safe.directory "$PWD"
  85. - name: build release tarball
  86. id: build
  87. run: |
  88. make ${{ matrix.profile }}-tgz
  89. - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
  90. with:
  91. name: "${{ matrix.profile }}-${{ matrix.arch }}.tar.gz"
  92. path: "_packages/emqx*/emqx-*.tar.gz"
  93. retention-days: 7
  94. overwrite: true
  95. if-no-files-found: error
  96. docker:
  97. runs-on: ${{ endsWith(github.repository, '/emqx') && 'ubuntu-22.04' || fromJSON('["self-hosted","ephemeral","linux","x64"]') }}
  98. needs:
  99. - build
  100. defaults:
  101. run:
  102. shell: bash
  103. strategy:
  104. fail-fast: false
  105. matrix:
  106. profile:
  107. - ${{ inputs.profile }}
  108. - ${{ inputs.profile }}-elixir
  109. steps:
  110. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  111. with:
  112. ref: ${{ github.event.inputs.ref }}
  113. - uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
  114. with:
  115. pattern: "${{ matrix.profile }}-*.tar.gz"
  116. path: _packages
  117. merge-multiple: true
  118. - name: Move artifacts to root directory
  119. env:
  120. PROFILE: ${{ inputs.profile }}
  121. run: |
  122. ls -lR _packages/$PROFILE
  123. mv _packages/$PROFILE/*.tar.gz ./
  124. - name: Enable containerd image store on Docker Engine
  125. run: |
  126. echo "$(jq '. += {"features": {"containerd-snapshotter": true}}' /etc/docker/daemon.json)" > daemon.json
  127. sudo mv daemon.json /etc/docker/daemon.json
  128. sudo systemctl restart docker
  129. - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
  130. - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
  131. - name: Login to hub.docker.com
  132. uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
  133. if: inputs.publish || github.repository_owner != 'emqx'
  134. with:
  135. username: ${{ secrets.DOCKER_HUB_USER }}
  136. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  137. - name: Login to AWS ECR
  138. uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
  139. if: inputs.publish || github.repository_owner != 'emqx'
  140. with:
  141. registry: public.ecr.aws
  142. username: ${{ secrets.AWS_ACCESS_KEY_ID }}
  143. password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  144. ecr: true
  145. - name: Build docker image
  146. env:
  147. PROFILE: ${{ matrix.profile }}
  148. DOCKER_REGISTRY: 'docker.io,public.ecr.aws'
  149. DOCKER_ORG: ${{ github.repository_owner }}
  150. DOCKER_LATEST: ${{ inputs.latest }}
  151. DOCKER_PUSH: false
  152. DOCKER_BUILD_NOCACHE: true
  153. DOCKER_PLATFORMS: linux/amd64,linux/arm64
  154. DOCKER_LOAD: true
  155. EMQX_RUNNER: 'public.ecr.aws/debian/debian:11-slim@sha256:22cfb3c06a7dd5e18d86123a73405664475b9d9fa209cbedcf4c50a25649cc74'
  156. EMQX_DOCKERFILE: 'deploy/docker/Dockerfile'
  157. PKG_VSN: ${{ needs.build.outputs.PKG_VSN }}
  158. EMQX_BUILDER_VERSION: ${{ inputs.builder_vsn }}
  159. EMQX_BUILDER_OTP: ${{ inputs.otp_vsn }}
  160. EMQX_BUILDER_ELIXIR: ${{ inputs.elixir_vsn }}
  161. EMQX_SOURCE_TYPE: tgz
  162. run: |
  163. ./build ${PROFILE} docker
  164. cat .emqx_docker_image_tags
  165. echo "_EMQX_DOCKER_IMAGE_TAG=$(head -n 1 .emqx_docker_image_tags)" >> $GITHUB_ENV
  166. - name: smoke test
  167. timeout-minutes: 1
  168. run: |
  169. for tag in $(cat .emqx_docker_image_tags); do
  170. CID=$(docker run -d -P $tag)
  171. HTTP_PORT=$(docker inspect --format='{{(index (index .NetworkSettings.Ports "18083/tcp") 0).HostPort}}' $CID)
  172. ./scripts/test/emqx-smoke-test.sh localhost $HTTP_PORT
  173. docker rm -f $CID
  174. done
  175. - name: dashboard tests
  176. working-directory: ./scripts/ui-tests
  177. timeout-minutes: 5
  178. run: |
  179. set -eu
  180. docker compose up --abort-on-container-exit --exit-code-from selenium
  181. docker compose rm -fsv
  182. - name: test node_dump
  183. run: |
  184. CID=$(docker run -d -P $_EMQX_DOCKER_IMAGE_TAG)
  185. docker exec -t -u root -w /root $CID bash -c 'apt-get -y update && apt-get -y install net-tools'
  186. docker exec -t -u root $CID node_dump
  187. docker rm -f $CID
  188. - name: push images
  189. if: inputs.publish || github.repository_owner != 'emqx'
  190. run: |
  191. for tag in $(cat .emqx_docker_image_tags); do
  192. docker push $tag
  193. done