build_and_push_docker_images.yaml 6.8 KB

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