build_packages.yaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. name: Cross build packages
  2. concurrency:
  3. group: build-${{ github.event_name }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. schedule:
  7. - cron: '0 */6 * * *'
  8. push:
  9. branches:
  10. - 'ci/**'
  11. tags:
  12. - v*
  13. - e*
  14. workflow_dispatch:
  15. inputs:
  16. which_branch:
  17. required: false
  18. jobs:
  19. prepare:
  20. runs-on: ubuntu-20.04
  21. # prepare source with any OTP version, no need for a matrix
  22. container: "ghcr.io/emqx/emqx-builder/5.0-16:1.13.4-24.2.1-1-ubuntu20.04"
  23. outputs:
  24. BUILD_PROFILES: ${{ steps.get_profiles.outputs.BUILD_PROFILES }}
  25. steps:
  26. - uses: actions/checkout@v2
  27. with:
  28. ref: ${{ github.event.inputs.which_branch }}
  29. path: source
  30. fetch-depth: 0
  31. - name: Get profiles to build
  32. id: get_profiles
  33. run: |
  34. tag=${{ github.ref }}
  35. case $tag in
  36. refs/tags/v*)
  37. echo "::set-output name=BUILD_PROFILES::[\"emqx\"]"
  38. ;;
  39. refs/tags/e*)
  40. echo "::set-output name=BUILD_PROFILES::[\"emqx-enterprise\"]"
  41. ;;
  42. *)
  43. # this is for testing ?
  44. echo "::set-output name=BUILD_PROFILES::[\"emqx\",\"emqx-enterprise\"]"
  45. ;;
  46. esac
  47. - name: get_all_deps
  48. run: |
  49. make -C source deps-all
  50. zip -ryq source.zip source/* source/.[^.]*
  51. - uses: actions/upload-artifact@v2
  52. with:
  53. name: source
  54. path: source.zip
  55. windows:
  56. runs-on: windows-2019
  57. needs: prepare
  58. strategy:
  59. fail-fast: false
  60. matrix:
  61. profile: # for now only CE for windows
  62. - emqx
  63. otp:
  64. - 24.2.1
  65. steps:
  66. - uses: actions/download-artifact@v2
  67. with:
  68. name: source
  69. path: .
  70. - name: unzip source code
  71. run: Expand-Archive -Path source.zip -DestinationPath ./
  72. - uses: ilammy/msvc-dev-cmd@v1
  73. - uses: erlef/setup-beam@v1
  74. with:
  75. otp-version: ${{ matrix.otp }}
  76. - name: build
  77. env:
  78. PYTHON: python
  79. DIAGNOSTIC: 1
  80. working-directory: source
  81. run: |
  82. # ensure crypto app (openssl)
  83. erl -eval "erlang:display(crypto:info_lib())" -s init stop
  84. make ${{ matrix.profile }}-tgz
  85. - name: run emqx
  86. timeout-minutes: 5
  87. working-directory: source
  88. run: |
  89. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  90. Start-Sleep -s 5
  91. echo "EMQX started"
  92. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  93. echo "EMQX stopped"
  94. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  95. echo "EMQX installed"
  96. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  97. echo "EMQX uninstalled"
  98. - uses: actions/upload-artifact@v1
  99. with:
  100. name: ${{ matrix.profile }}-windows
  101. path: source/_packages/${{ matrix.profile }}/.
  102. mac:
  103. needs: prepare
  104. strategy:
  105. fail-fast: false
  106. matrix:
  107. profile: ${{ fromJson(needs.prepare.outputs.BUILD_PROFILES) }}
  108. otp:
  109. - 24.2.1-1
  110. os:
  111. - macos-11
  112. - macos-10.15
  113. runs-on: ${{ matrix.os }}
  114. steps:
  115. - uses: actions/download-artifact@v2
  116. with:
  117. name: source
  118. path: .
  119. - name: unzip source code
  120. run: unzip -q source.zip
  121. - name: prepare
  122. run: |
  123. brew update
  124. brew install curl zip unzip kerl coreutils
  125. echo "/usr/local/opt/bison/bin" >> $GITHUB_PATH
  126. echo "/usr/local/bin" >> $GITHUB_PATH
  127. git config --global credential.helper store
  128. - uses: actions/cache@v2
  129. id: cache
  130. with:
  131. path: ~/.kerl/${{ matrix.otp }}
  132. key: otp-install-${{ matrix.otp }}-${{ matrix.os }}
  133. - name: build erlang
  134. if: steps.cache.outputs.cache-hit != 'true'
  135. timeout-minutes: 60
  136. env:
  137. KERL_BUILD_BACKEND: git
  138. OTP_GITHUB_URL: https://github.com/emqx/otp
  139. run: |
  140. kerl update releases
  141. kerl build ${{ matrix.otp }}
  142. kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
  143. - name: build
  144. working-directory: source
  145. env:
  146. AUTO_INSTALL_BUILD_DEPS: 1
  147. run: |
  148. . $HOME/.kerl/${{ matrix.otp }}/activate
  149. make ensure-rebar3
  150. sudo cp rebar3 /usr/local/bin/rebar3
  151. rm -rf _build/${{ matrix.profile }}/lib
  152. make ${{ matrix.profile }}-tgz
  153. - name: test
  154. working-directory: source
  155. run: |
  156. pkg_name=$(find _packages/${{ matrix.profile }} -mindepth 1 -maxdepth 1 -iname \*.tar.gz)
  157. mkdir -p emqx
  158. tar -C emqx -zxf $pkg_name
  159. # gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  160. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  161. ready='no'
  162. for i in {1..10}; do
  163. if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then
  164. ready='yes'
  165. break
  166. fi
  167. sleep 1
  168. done
  169. if [ "$ready" != "yes" ]; then
  170. echo "Timed out waiting for emqx to be ready"
  171. cat emqx/log/erlang.log.1
  172. exit 1
  173. fi
  174. ./emqx/bin/emqx_ctl status
  175. ./emqx/bin/emqx stop
  176. rm -rf emqx
  177. - uses: actions/upload-artifact@v1
  178. with:
  179. name: ${{ matrix.profile }}-${{ matrix.otp }}
  180. path: source/_packages/${{ matrix.profile }}/.
  181. linux:
  182. needs: prepare
  183. runs-on: ${{ matrix.build_machine }}
  184. container:
  185. image: "ghcr.io/emqx/emqx-builder/5.0-16:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
  186. strategy:
  187. fail-fast: false
  188. matrix:
  189. profile: ${{ fromJson(needs.prepare.outputs.BUILD_PROFILES) }}
  190. otp:
  191. - 24.2.1-1 # we test with OTP 23, but only build package on OTP 24 versions
  192. elixir:
  193. - 1.13.4
  194. # used to split elixir packages into a separate job, since the
  195. # entire job may take a lot of time, especially on arm64
  196. # emulation.
  197. # we only want to build ubuntu and centos with elixir for the
  198. # time being, so it's easier to just include those with
  199. # `with_elixir` set.
  200. build_elixir:
  201. # - with_elixir
  202. - no_elixir
  203. arch:
  204. - amd64
  205. - arm64
  206. os:
  207. - ubuntu20.04
  208. - ubuntu18.04
  209. - ubuntu16.04
  210. - debian11
  211. - debian10
  212. - debian9
  213. - el8
  214. - el7
  215. - raspbian10
  216. build_machine:
  217. - aws-arm64
  218. - ubuntu-20.04
  219. exclude:
  220. - arch: arm64
  221. build_machine: ubuntu-20.04
  222. - arch: amd64
  223. build_machine: aws-arm64
  224. - os: raspbian9
  225. arch: amd64
  226. - os: raspbian10
  227. arch: amd64
  228. - os: raspbian10 # we only have arm32 image
  229. arch: arm64
  230. - os: raspbian9
  231. profile: emqx
  232. - os: raspbian10
  233. profile: emqx
  234. - os: raspbian9
  235. profile: emqx-enterprise
  236. - os: raspbian10
  237. profile: emqx-enterprise
  238. include:
  239. - profile: emqx
  240. otp: 24.2.1-1
  241. elixir: 1.13.4
  242. build_elixir: with_elixir
  243. arch: amd64
  244. os: ubuntu20.04
  245. build_machine: ubuntu-20.04
  246. - profile: emqx
  247. otp: 24.2.1-1
  248. elixir: 1.13.4
  249. build_elixir: with_elixir
  250. arch: amd64
  251. os: el7
  252. build_machine: ubuntu-20.04
  253. defaults:
  254. run:
  255. shell: bash
  256. steps:
  257. - uses: AutoModality/action-clean@v1
  258. if: matrix.build_machine == 'aws-arm64'
  259. - uses: actions/download-artifact@v2
  260. with:
  261. name: source
  262. path: .
  263. - name: unzip source code
  264. run: unzip -q source.zip
  265. - name: build emqx packages
  266. working-directory: source
  267. env:
  268. OTP: ${{ matrix.otp }}
  269. ELIXIR: ${{ matrix.elixir }}
  270. PROFILE: ${{ matrix.profile }}
  271. ARCH: ${{ matrix.arch }}
  272. SYSTEM: ${{ matrix.os }}
  273. run: |
  274. set -eu
  275. git config --global --add safe.directory "/__w/emqx/emqx"
  276. # Align path for CMake caches
  277. if [ ! "$PWD" = "/emqx" ]; then
  278. ln -s $PWD /emqx
  279. cd /emqx
  280. fi
  281. echo "pwd is $PWD"
  282. PkgTypes="tgz pkg"
  283. IsElixir="no"
  284. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  285. PkgTypes="tgz"
  286. # set Elixir build flag
  287. IsElixir="yes"
  288. fi
  289. for PKGTYPE in ${PkgTypes};
  290. do
  291. ./scripts/buildx.sh \
  292. --profile "${PROFILE}" \
  293. --pkgtype "${PKGTYPE}" \
  294. --arch "${ARCH}" \
  295. --elixir "${IsElixir}" \
  296. --builder "ghcr.io/emqx/emqx-builder/5.0-16:${ELIXIR}-${OTP}-${SYSTEM}"
  297. done
  298. - uses: actions/upload-artifact@v1
  299. with:
  300. name: ${{ matrix.profile }}-${{ matrix.otp }}
  301. path: source/_packages/${{ matrix.profile }}/.
  302. docker:
  303. runs-on: ${{ matrix.build_machine }}
  304. needs: prepare
  305. strategy:
  306. fail-fast: false
  307. matrix:
  308. os:
  309. - [alpine3.15.1, "alpine:3.15.1", "deploy/docker/Dockerfile.alpine"]
  310. - [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
  311. profile: ${{ fromJson(needs.prepare.outputs.BUILD_PROFILES) }}
  312. # NOTE: for docker, only support latest otp and elixir
  313. # versions, not a matrix
  314. otp:
  315. - 24.2.1-1 # update to latest
  316. elixir:
  317. - 1.13.4 # update to latest
  318. arch:
  319. - amd64
  320. - arm64
  321. build_elixir:
  322. - no_elixir
  323. build_machine:
  324. - aws-arm64
  325. - ubuntu-20.04
  326. registry:
  327. - docker.io
  328. exclude:
  329. - arch: arm64
  330. build_machine: ubuntu-20.04
  331. - arch: amd64
  332. build_machine: aws-arm64
  333. include:
  334. - os: [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
  335. profile: emqx
  336. otp: 24.2.1-1
  337. elixir: 1.13.4
  338. arch: amd64
  339. build_elixir: no_elixir
  340. build_machine: ubuntu-20.04
  341. registry: public.ecr.aws
  342. - os: [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
  343. profile: emqx
  344. otp: 24.2.1-1
  345. elixir: 1.13.4
  346. arch: amd64
  347. build_elixir: with_elixir
  348. build_machine: ubuntu-20.04
  349. steps:
  350. - uses: AutoModality/action-clean@v1
  351. if: matrix.build_machine == 'aws-arm64'
  352. - uses: actions/download-artifact@v2
  353. with:
  354. name: source
  355. path: .
  356. - name: unzip source code
  357. run: unzip -q source.zip
  358. - uses: docker/setup-buildx-action@v1
  359. - name: Login for docker.
  360. uses: docker/login-action@v1
  361. if: matrix.arch == 'amd64' && matrix.registry == 'docker.io'
  362. with:
  363. username: ${{ secrets.DOCKER_HUB_USER }}
  364. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  365. - name: Login for AWS ECR
  366. uses: docker/login-action@v1
  367. if: matrix.profile == 'emqx' && matrix.arch == 'amd64' && matrix.registry == 'public.ecr.aws'
  368. with:
  369. registry: public.ecr.aws
  370. username: ${{ secrets.AWS_ACCESS_KEY_ID }}
  371. password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  372. ecr: true
  373. - name: prepare for docker-action-parms
  374. id: pre-meta
  375. run: |
  376. emqx_name=${{ matrix.profile }}
  377. img_suffix=${{ matrix.arch }}
  378. img_labels="org.opencontainers.image.otp.version=${{ matrix.otp }}"
  379. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  380. emqx_name="emqx-elixir"
  381. img_suffix="elixir-${{ matrix.arch }}"
  382. img_labels="org.opencontainers.image.elixir.version=${{ matrix.elixir }}\n${img_labels}"
  383. fi
  384. if [[ ${{ matrix.os[0] }} =~ "alpine" ]]; then
  385. img_suffix="${img_suffix}-alpine"
  386. fi
  387. echo "::set-output name=emqx_name::${emqx_name}"
  388. echo "::set-output name=img_suffix::${img_suffix}"
  389. echo "::set-output name=img_labels::${img_labels}"
  390. # NOTE, Pls make sure this is identical as the one in job 'docker-push-multi-arch-manifest'
  391. - uses: docker/metadata-action@v3
  392. id: meta
  393. with:
  394. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  395. flavor: |
  396. latest=${{ github.event_name == 'release' && !github.event.release.prerelease }}
  397. suffix=-${{ steps.pre-meta.outputs.img_suffix }}
  398. tags: |
  399. type=ref,event=branch
  400. type=ref,event=pr
  401. type=ref,event=tag
  402. type=semver,pattern={{version}}
  403. labels:
  404. ${{ steps.pre-meta.outputs.img_labels }}
  405. - uses: docker/build-push-action@v2
  406. with:
  407. push: >
  408. ${{ (github.event_name == 'release' && !github.event.release.prerelease)
  409. || (github.event.repository.owner != 'emqx' && startsWith(github.ref_name, 'ci/')) }}
  410. pull: true
  411. no-cache: true
  412. platforms: linux/${{ matrix.arch }}
  413. tags: ${{ steps.meta.outputs.tags }}
  414. labels: ${{ steps.meta.outputs.labels }}
  415. build-args: |
  416. BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-16:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os[0] }}
  417. RUN_FROM=${{ matrix.os[1] }}
  418. EMQX_NAME=${{ steps.pre-meta.outputs.emqx_name }}
  419. file: source/${{ matrix.os[2] }}
  420. context: source
  421. docker-push-multi-arch-manifest:
  422. # note, we only run on amd64
  423. if: >
  424. (github.event_name == 'release' && !github.event.release.prerelease)
  425. || (github.event.repository.owner != 'emqx' && startsWith(github.ref_name, 'ci/'))
  426. needs:
  427. - prepare
  428. - docker
  429. runs-on: ubuntu-latest
  430. strategy:
  431. fail-fast: false
  432. matrix:
  433. os:
  434. - [alpine3.15.1, "alpine:3.15.1", "deploy/docker/Dockerfile.alpine"]
  435. - [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
  436. profile: ${{ fromJson(needs.prepare.outputs.BUILD_PROFILES) }}
  437. # NOTE: for docker, only support latest otp version, not a matrix
  438. otp:
  439. - 24.2.1-1 # update to latest
  440. #
  441. elixir:
  442. - 1.13.4 # update to latest
  443. arch:
  444. - amd64
  445. - arm64
  446. build_elixir:
  447. - no_elixir
  448. build_machine:
  449. - aws-arm64
  450. - ubuntu-20.04
  451. registries:
  452. - docker.io
  453. exclude:
  454. - arch: arm64
  455. build_machine: ubuntu-20.04
  456. - arch: amd64
  457. build_machine: aws-arm64
  458. include:
  459. - os: [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
  460. profile: emqx
  461. otp: 24.2.1-1
  462. elixir: 1.13.4
  463. arch: amd64
  464. build_elixir: no_elixir
  465. build_machine: ubuntu-20.04
  466. registry: public.ecr.aws
  467. - os: [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
  468. profile: emqx
  469. otp: 24.2.1-1
  470. elixir: 1.13.4
  471. arch: amd64
  472. build_elixir: with_elixir
  473. build_machine: ubuntu-20.04
  474. registry: docker.io
  475. steps:
  476. - uses: actions/download-artifact@v2
  477. if: matrix.arch == 'amd64'
  478. with:
  479. name: source
  480. path: .
  481. - name: unzip source code
  482. if: matrix.arch == 'amd64'
  483. run: unzip -q source.zip
  484. - uses: docker/login-action@v1
  485. if: matrix.arch == 'amd64' && matrix.registry == 'docker.io'
  486. with:
  487. username: ${{ secrets.DOCKER_HUB_USER }}
  488. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  489. - uses: docker/login-action@v1
  490. if: matrix.profile == 'emqx' && matrix.arch == 'amd64' && matrix.registry == 'public.ecr.aws'
  491. with:
  492. registry: public.ecr.aws
  493. username: ${{ secrets.AWS_ACCESS_KEY_ID }}
  494. password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  495. ecr: true
  496. - name: prepare for docker-action-parms
  497. id: pre-meta
  498. run: |
  499. emqx_name=${{ matrix.profile }}
  500. img_suffix=${{ matrix.arch }}
  501. img_labels="org.opencontainers.image.otp.version=${{ matrix.otp }}"
  502. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  503. emqx_name="emqx-elixir"
  504. img_suffix="elixir-${{ matrix.arch }}"
  505. img_labels="org.opencontainers.image.elixir.version=${{ matrix.elixir }}\n$img_labels"
  506. fi
  507. if [[ ${{ matrix.os[0] }} =~ "alpine" ]]; then
  508. img_suffix="${img_suffix}-alpine"
  509. fi
  510. echo "::set-output name=img::${img}"
  511. echo "::set-output name=emqx_name::${emqx_name}"
  512. echo "::set-output name=img_suffix::${img_suffix}"
  513. echo "::set-output name=img_labels::${img_labels}"
  514. # NOTE, Pls make sure this is identical as the one in job 'docker'
  515. - uses: docker/metadata-action@v3
  516. if: matrix.arch == 'amd64'
  517. id: meta
  518. with:
  519. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  520. flavor: |
  521. latest=false
  522. suffix=-${{ steps.pre-meta.outputs.img_suffix }}
  523. tags: |
  524. type=ref,event=branch
  525. type=ref,event=pr
  526. type=ref,event=tag
  527. type=semver,pattern={{version}}
  528. labels:
  529. ${{ steps.pre-meta.outputs.img_labels }}
  530. - name: update manifest for multiarch image
  531. if: matrix.arch == 'amd64'
  532. working-directory: source
  533. run: |
  534. IsPushLatest=${{ github.event_name == 'release' && !github.event.release.prerelease }};
  535. scripts/docker-create-push-manifests.sh "${{ steps.meta.outputs.tags }}" "$IsPushLatest"
  536. publish_artifacts:
  537. runs-on: ubuntu-20.04
  538. if: startsWith(github.ref, 'refs/tags/')
  539. needs: [prepare, mac, linux, docker]
  540. strategy:
  541. fail-fast: false
  542. matrix:
  543. profile: ${{ fromJson(needs.prepare.outputs.BUILD_PROFILES) }}
  544. otp:
  545. - 24.2.1-1
  546. include:
  547. - profile: emqx
  548. otp: windows # otp version on windows is rather fixed
  549. steps:
  550. - uses: actions/download-artifact@v2
  551. with:
  552. name: ${{ matrix.profile }}-${{ matrix.otp }}
  553. path: packages/${{ matrix.profile }}
  554. - name: install dos2unix
  555. run: sudo apt-get update && sudo apt install -y dos2unix
  556. - name: get packages
  557. run: |
  558. set -e -u
  559. cd packages/${{ matrix.profile }}
  560. for var in $( ls |grep emqx |grep -v sha256); do
  561. dos2unix $var.sha256
  562. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  563. done
  564. cd -
  565. - uses: aws-actions/configure-aws-credentials@v1
  566. with:
  567. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  568. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  569. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  570. - name: upload to aws s3
  571. env:
  572. PROFILE: ${{ matrix.profile }}
  573. run: |
  574. set -e -u
  575. if [ $PROFILE = 'emqx' ]; then
  576. s3dir='emqx-ce'
  577. elif [ $PROFILE = 'emqx-enterprise' ]; then
  578. s3dir='emqx-ee'
  579. else
  580. echo "unknown profile $PROFILE"
  581. exit 1
  582. fi
  583. aws s3 cp --recursive packages/$PROFILE s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ github.ref_name }}
  584. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ github.ref_name }}/*"