build_and_push_docker_images.yaml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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-5'
  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 }}-debian12"
  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@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
  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 }}", "${{ inputs.profile == 'emqx' && 'docker.io,public.ecr.aws' || 'docker.io' }}"]
  108. - ["${{ inputs.profile }}-elixir", "${{ inputs.profile == 'emqx' && 'docker.io,public.ecr.aws' || 'docker.io' }}"]
  109. steps:
  110. - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
  111. with:
  112. ref: ${{ github.event.inputs.ref }}
  113. - uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
  114. with:
  115. pattern: "${{ matrix.profile[0] }}-*.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@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0
  131. - name: Login to hub.docker.com
  132. uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.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@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.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[0] }}
  148. DOCKER_REGISTRY: ${{ matrix.profile[1] }}
  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:12-slim'
  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. echo "Built tags:"
  165. echo "==========="
  166. cat .emqx_docker_image_tags
  167. echo "==========="
  168. echo "_EMQX_DOCKER_IMAGE_TAG=$(head -n 1 .emqx_docker_image_tags)" >> $GITHUB_ENV
  169. - name: smoke test
  170. timeout-minutes: 1
  171. run: |
  172. for tag in $(cat .emqx_docker_image_tags); do
  173. CID=$(docker run -d -P $tag)
  174. HTTP_PORT=$(docker inspect --format='{{(index (index .NetworkSettings.Ports "18083/tcp") 0).HostPort}}' $CID)
  175. ./scripts/test/emqx-smoke-test.sh localhost $HTTP_PORT
  176. docker rm -f $CID
  177. done
  178. - name: dashboard tests
  179. working-directory: ./scripts/ui-tests
  180. timeout-minutes: 5
  181. run: |
  182. set -eu
  183. docker compose up --abort-on-container-exit --exit-code-from selenium
  184. docker compose rm -fsv
  185. - name: test node_dump
  186. run: |
  187. CID=$(docker run -d -P $_EMQX_DOCKER_IMAGE_TAG)
  188. docker exec -t -u root -w /root $CID bash -c 'apt-get -y update && apt-get -y install net-tools'
  189. docker exec -t -u root $CID node_dump
  190. docker rm -f $CID
  191. - name: Push docker image
  192. if: inputs.publish || github.repository_owner != 'emqx'
  193. env:
  194. PROFILE: ${{ matrix.profile[0] }}
  195. DOCKER_REGISTRY: ${{ matrix.profile[1] }}
  196. DOCKER_ORG: ${{ github.repository_owner }}
  197. DOCKER_LATEST: ${{ inputs.latest }}
  198. DOCKER_PUSH: true
  199. DOCKER_BUILD_NOCACHE: false
  200. DOCKER_PLATFORMS: linux/amd64,linux/arm64
  201. DOCKER_LOAD: false
  202. EMQX_RUNNER: 'public.ecr.aws/debian/debian:12-slim'
  203. EMQX_DOCKERFILE: 'deploy/docker/Dockerfile'
  204. PKG_VSN: ${{ needs.build.outputs.PKG_VSN }}
  205. EMQX_BUILDER_VERSION: ${{ inputs.builder_vsn }}
  206. EMQX_BUILDER_OTP: ${{ inputs.otp_vsn }}
  207. EMQX_BUILDER_ELIXIR: ${{ inputs.elixir_vsn }}
  208. EMQX_SOURCE_TYPE: tgz
  209. run: |
  210. ./build ${PROFILE} docker