build_packages.yaml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. name: Cross build packages
  2. on:
  3. schedule:
  4. - cron: '0 */6 * * *'
  5. release:
  6. types:
  7. - published
  8. workflow_dispatch:
  9. jobs:
  10. prepare:
  11. strategy:
  12. matrix:
  13. otp:
  14. - "23.2.7.2-emqx-2"
  15. - "24.0.5-emqx-1"
  16. runs-on: ubuntu-20.04
  17. container: "ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-ubuntu20.04"
  18. outputs:
  19. profiles: ${{ steps.set_profile.outputs.profiles }}
  20. old_vsns: ${{ steps.set_profile.outputs.old_vsns }}
  21. steps:
  22. - uses: actions/checkout@v2
  23. with:
  24. path: source
  25. fetch-depth: 0
  26. - name: set profile
  27. id: set_profile
  28. shell: bash
  29. working-directory: source
  30. run: |
  31. vsn="$(./pkg-vsn.sh)"
  32. pre_vsn="$(echo $vsn | grep -oE '^[0-9]+.[0-9]')"
  33. if make emqx-ee --dry-run > /dev/null 2>&1; then
  34. old_vsns="$(git tag -l "e$pre_vsn.[0-9]" | xargs echo -n | sed "s/e$vsn//")"
  35. echo "::set-output name=old_vsns::$old_vsns"
  36. echo "::set-output name=profiles::[\"emqx-ee\"]"
  37. else
  38. old_vsns="$(git tag -l "v$pre_vsn.[0-9]" | xargs echo -n | sed "s/v$vsn//")"
  39. echo "::set-output name=old_vsns::$old_vsns"
  40. echo "::set-output name=profiles::[\"emqx\", \"emqx-edge\"]"
  41. fi
  42. - name: get otp version
  43. id: get_otp_version
  44. run: |
  45. otp="$(erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell)"
  46. echo "::set-output name=otp::$otp"
  47. - name: set get token
  48. if: endsWith(github.repository, 'enterprise')
  49. run: |
  50. echo "https://ci%40emqx.io:${{ secrets.CI_GIT_TOKEN }}@github.com" > $HOME/.git-credentials
  51. git config --global credential.helper store
  52. - name: get deps
  53. working-directory: source
  54. run: |
  55. make ensure-rebar3
  56. ./rebar3 as default get-deps
  57. rm -rf rebar.lock
  58. - name: gen zip file
  59. run: zip -ryq source-${{ steps.get_otp_version.outputs.otp }}.zip source/* source/.[^.]*
  60. - uses: actions/upload-artifact@v2
  61. with:
  62. name: source-${{ steps.get_otp_version.outputs.otp }}
  63. path: source-${{ steps.get_otp_version.outputs.otp }}.zip
  64. windows:
  65. runs-on: windows-2019
  66. needs: prepare
  67. if: endsWith(github.repository, 'emqx')
  68. strategy:
  69. fail-fast: false
  70. matrix:
  71. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  72. exclude:
  73. - profile: emqx-edge
  74. steps:
  75. - uses: actions/download-artifact@v2
  76. with:
  77. name: source-23.2.7.2-emqx-2
  78. path: .
  79. - name: unzip source code
  80. run: Expand-Archive -Path source-23.2.7.2-emqx-2.zip -DestinationPath ./
  81. - uses: ilammy/msvc-dev-cmd@v1
  82. - uses: gleam-lang/setup-erlang@v1.1.2
  83. id: install_erlang
  84. ## gleam-lang/setup-erlang does not yet support the installation of otp24 on windows
  85. with:
  86. otp-version: 23.2
  87. - name: build
  88. env:
  89. PYTHON: python
  90. DIAGNOSTIC: 1
  91. working-directory: source
  92. run: |
  93. $env:PATH = "${{ steps.install_erlang.outputs.erlpath }}\bin;$env:PATH"
  94. $version = $( "${{ github.ref }}" -replace "^(.*)/(.*)/" )
  95. if ($version -match "^v[0-9]+\.[0-9]+(\.[0-9]+)?") {
  96. $regex = "[0-9]+\.[0-9]+(-alpha|-beta|-rc)?\.[0-9]+"
  97. $pkg_name = "${{ matrix.profile }}-windows-$([regex]::matches($version, $regex).value).zip"
  98. }
  99. else {
  100. $pkg_name = "${{ matrix.profile }}-windows-$($version -replace '/').zip"
  101. }
  102. ## We do not build/release bcrypt and quic for windows package
  103. Remove-Item -Recurse -Force -Path _build/default/lib/bcrypt/
  104. Remove-Item -Recurse -Force -Path _build/default/lib/quicer/
  105. if (Test-Path rebar.lock) {
  106. Remove-Item -Force -Path rebar.lock
  107. }
  108. make ensure-rebar3
  109. copy rebar3 "${{ steps.install_erlang.outputs.erlpath }}\bin"
  110. ls "${{ steps.install_erlang.outputs.erlpath }}\bin"
  111. rebar3 --help
  112. make ${{ matrix.profile }}
  113. mkdir -p _packages/${{ matrix.profile }}
  114. Compress-Archive -Path _build/${{ matrix.profile }}/rel/emqx -DestinationPath _build/${{ matrix.profile }}/rel/$pkg_name
  115. mv _build/${{ matrix.profile }}/rel/$pkg_name _packages/${{ matrix.profile }}
  116. Get-FileHash -Path "_packages/${{ matrix.profile }}/$pkg_name" | Format-List | grep 'Hash' | awk '{print $3}' > _packages/${{ matrix.profile }}/$pkg_name.sha256
  117. - name: run emqx
  118. timeout-minutes: 1
  119. working-directory: source
  120. run: |
  121. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  122. Start-Sleep -s 5
  123. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  124. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  125. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  126. - uses: actions/upload-artifact@v1
  127. if: startsWith(github.ref, 'refs/tags/')
  128. with:
  129. name: ${{ matrix.profile }}-23.2.7.2-emqx-2
  130. path: source/_packages/${{ matrix.profile }}/.
  131. mac:
  132. runs-on: macos-10.15
  133. needs: prepare
  134. strategy:
  135. fail-fast: false
  136. matrix:
  137. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  138. otp:
  139. - 24.0.5-emqx-1
  140. exclude:
  141. - profile: emqx-edge
  142. steps:
  143. - uses: actions/download-artifact@v2
  144. with:
  145. name: source-${{ matrix.otp }}
  146. path: .
  147. - name: unzip source code
  148. run: unzip -q source-${{ matrix.otp }}.zip
  149. - name: prepare
  150. run: |
  151. brew update
  152. brew install curl zip unzip gnu-sed kerl unixodbc freetds
  153. echo "/usr/local/bin" >> $GITHUB_PATH
  154. git config --global credential.helper store
  155. - uses: actions/cache@v2
  156. id: cache
  157. with:
  158. path: ~/.kerl
  159. key: erl${{ matrix.otp }}-macos10.15
  160. - name: build erlang
  161. if: steps.cache.outputs.cache-hit != 'true'
  162. timeout-minutes: 60
  163. env:
  164. KERL_BUILD_BACKEND: git
  165. OTP_GITHUB_URL: https://github.com/emqx/otp
  166. run: |
  167. kerl update releases
  168. kerl build ${{ matrix.otp }}
  169. kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
  170. - name: build
  171. working-directory: source
  172. run: |
  173. . $HOME/.kerl/${{ matrix.otp }}/activate
  174. make ensure-rebar3
  175. sudo cp rebar3 /usr/local/bin/rebar3
  176. make ${{ matrix.profile }}-zip
  177. - name: test
  178. working-directory: source
  179. run: |
  180. pkg_name=$(basename _packages/${{ matrix.profile }}/${{ matrix.profile }}-*.zip)
  181. unzip -q _packages/${{ matrix.profile }}/$pkg_name
  182. # gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  183. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  184. ready='no'
  185. for i in {1..10}; do
  186. if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then
  187. ready='yes'
  188. break
  189. fi
  190. sleep 1
  191. done
  192. if [ "$ready" != "yes" ]; then
  193. echo "Timed out waiting for emqx to be ready"
  194. cat emqx/log/erlang.log.1
  195. exit 1
  196. fi
  197. ./emqx/bin/emqx_ctl status
  198. ./emqx/bin/emqx stop
  199. rm -rf emqx
  200. openssl dgst -sha256 ./_packages/${{ matrix.profile }}/$pkg_name | awk '{print $2}' > ./_packages/${{ matrix.profile }}/$pkg_name.sha256
  201. - uses: actions/upload-artifact@v1
  202. if: startsWith(github.ref, 'refs/tags/')
  203. with:
  204. name: ${{ matrix.profile }}-${{ matrix.otp }}
  205. path: source/_packages/${{ matrix.profile }}/.
  206. linux:
  207. runs-on: ubuntu-20.04
  208. needs: prepare
  209. strategy:
  210. fail-fast: false
  211. matrix:
  212. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  213. os:
  214. - ubuntu20.04
  215. - ubuntu18.04
  216. - ubuntu16.04
  217. - debian10
  218. - debian9
  219. # - opensuse
  220. - centos8
  221. - centos7
  222. - centos6
  223. - raspbian10
  224. # - raspbian9
  225. arch:
  226. - amd64
  227. - arm64
  228. otp:
  229. - 23.2.7.2-emqx-2
  230. - 24.0.5-emqx-1
  231. exclude:
  232. - os: centos6
  233. arch: arm64
  234. - os: raspbian9
  235. arch: amd64
  236. - os: raspbian10
  237. arch: amd64
  238. - os: raspbian9
  239. profile: emqx
  240. - os: raspbian10
  241. profile: emqx
  242. - os: raspbian9
  243. profile: emqx-ee
  244. - os: raspbian10
  245. profile: emqx-ee
  246. defaults:
  247. run:
  248. shell: bash
  249. steps:
  250. - uses: docker/setup-buildx-action@v1
  251. - uses: docker/setup-qemu-action@v1
  252. with:
  253. image: tonistiigi/binfmt:latest
  254. platforms: all
  255. - uses: actions/download-artifact@v2
  256. with:
  257. name: source-${{ matrix.otp }}
  258. path: .
  259. - name: unzip source code
  260. run: unzip -q source-${{ matrix.otp }}.zip
  261. - name: downloads old emqx zip packages
  262. env:
  263. PROFILE: ${{ matrix.profile }}
  264. ARCH: ${{ matrix.arch }}
  265. SYSTEM: ${{ matrix.os }}
  266. OLD_VSNS: ${{ needs.prepare.outputs.old_vsns }}
  267. working-directory: source
  268. run: |
  269. set -e -x -u
  270. broker=$PROFILE
  271. if [ $PROFILE = "emqx" ];then
  272. broker="emqx-ce"
  273. fi
  274. if [ ! -z "$(echo $SYSTEM | grep -oE 'raspbian')" ]; then
  275. export ARCH="arm"
  276. fi
  277. mkdir -p _upgrade_base
  278. cd _upgrade_base
  279. old_vsns=($(echo $OLD_VSNS | tr ' ' ' '))
  280. for tag in ${old_vsns[@]}; do
  281. if [ ! -z "$(echo $(curl -I -m 10 -o /dev/null -s -w %{http_code} https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip) | grep -oE "^[23]+")" ];then
  282. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip
  283. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip.sha256
  284. echo "$(cat $PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip.sha256) $PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip" | sha256sum -c || exit 1
  285. fi
  286. done
  287. - name: build emqx packages
  288. env:
  289. OTP: ${{ matrix.otp }}
  290. PROFILE: ${{ matrix.profile }}
  291. ARCH: ${{ matrix.arch }}
  292. SYSTEM: ${{ matrix.os }}
  293. working-directory: source
  294. run: |
  295. docker run -i --rm \
  296. -v $(pwd):/emqx \
  297. --workdir /emqx \
  298. --platform linux/$ARCH \
  299. ghcr.io/emqx/emqx-builder-helper/5.0:$OTP-$SYSTEM \
  300. bash -euc "make $PROFILE-zip || cat rebar3.crashdump; \
  301. make $PROFILE-pkg || cat rebar3.crashdump; \
  302. EMQX_NAME=$PROFILE && .ci/build_packages/tests.sh"
  303. - name: create sha256
  304. env:
  305. PROFILE: ${{ matrix.profile}}
  306. working-directory: source
  307. run: |
  308. if [ -d _packages/$PROFILE ]; then
  309. cd _packages/$PROFILE
  310. for var in $(ls emqx-* ); do
  311. sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  312. done
  313. cd -
  314. fi
  315. - uses: actions/upload-artifact@v1
  316. if: startsWith(github.ref, 'refs/tags/')
  317. with:
  318. name: ${{ matrix.profile }}-${{ matrix.otp }}
  319. path: source/_packages/${{ matrix.profile }}/.
  320. docker:
  321. runs-on: ubuntu-20.04
  322. needs: prepare
  323. strategy:
  324. fail-fast: false
  325. matrix:
  326. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  327. otp:
  328. - 24.0.5-emqx-1
  329. steps:
  330. - uses: actions/download-artifact@v2
  331. with:
  332. name: source-${{ matrix.otp }}
  333. path: .
  334. - name: unzip source code
  335. run: unzip -q source-${{ matrix.otp }}.zip
  336. - name: get version
  337. id: version
  338. working-directory: source
  339. run: echo "::set-output name=version::$(./pkg-vsn.sh)"
  340. - uses: docker/setup-buildx-action@v1
  341. - uses: docker/setup-qemu-action@v1
  342. with:
  343. image: tonistiigi/binfmt:latest
  344. platforms: all
  345. - uses: docker/build-push-action@v2
  346. if: github.event_name != 'release'
  347. with:
  348. push: false
  349. pull: true
  350. no-cache: true
  351. platforms: linux/amd64,linux/arm64
  352. tags: emqx/${{ matrix.profile }}:${{ steps.version.outputs.version }}
  353. build-args: |
  354. PKG_VSN=${{ steps.version.outputs.version }}
  355. BUILD_FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14
  356. RUN_FROM=alpine:3.14
  357. EMQX_NAME=${{ matrix.profile }}
  358. file: source/deploy/docker/Dockerfile
  359. context: source
  360. - uses: docker/login-action@v1
  361. if: github.event_name == 'release'
  362. with:
  363. username: ${{ secrets.DOCKER_HUB_USER }}
  364. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  365. - uses: docker/build-push-action@v2
  366. if: github.event_name == 'release'
  367. with:
  368. push: true
  369. pull: true
  370. no-cache: true
  371. platforms: linux/amd64,linux/arm64
  372. tags: emqx/${{ matrix.profile }}:${{ steps.version.outputs.version }}
  373. build-args: |
  374. PKG_VSN=${{ steps.version.outputs.version }}
  375. BUILD_FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14
  376. RUN_FROM=alpine:3.14
  377. EMQX_NAME=${{ matrix.profile }}
  378. file: source/deploy/docker/Dockerfile
  379. context: source
  380. delete-artifact:
  381. runs-on: ubuntu-20.04
  382. strategy:
  383. matrix:
  384. otp:
  385. - 23.2.7.2-emqx-2
  386. - 24.0.5-emqx-1
  387. needs: [prepare, mac, linux, docker]
  388. steps:
  389. - uses: geekyeggo/delete-artifact@v1
  390. with:
  391. name: source-${{ matrix.otp }}
  392. upload:
  393. runs-on: ubuntu-20.04
  394. if: startsWith(github.ref, 'refs/tags/')
  395. needs: [prepare, mac, linux, docker]
  396. strategy:
  397. matrix:
  398. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  399. otp:
  400. - 24.0.5-emqx-1
  401. steps:
  402. - uses: actions/checkout@v2
  403. - name: get_version
  404. run: |
  405. echo 'version<<EOF' >> $GITHUB_ENV
  406. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  407. echo 'EOF' >> $GITHUB_ENV
  408. - uses: actions/download-artifact@v2
  409. with:
  410. name: ${{ matrix.profile }}-${{ matrix.otp }}
  411. path: ./_packages/${{ matrix.profile }}
  412. - name: install dos2unix
  413. run: sudo apt-get update && sudo apt install -y dos2unix
  414. - name: get packages
  415. run: |
  416. set -e -u
  417. cd _packages/${{ matrix.profile }}
  418. for var in $( ls |grep emqx |grep -v sha256); do
  419. dos2unix $var.sha256
  420. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  421. done
  422. cd -
  423. - name: upload aws s3
  424. run: |
  425. set -e -u
  426. if [ "${{ matrix.profile }}" == "emqx" ];then
  427. broker="emqx-ce"
  428. else
  429. broker=${{ matrix.profile }}
  430. fi
  431. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  432. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  433. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  434. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  435. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  436. - uses: Rory-Z/upload-release-asset@v1
  437. if: github.event_name == 'release' && matrix.profile != 'emqx-ee'
  438. with:
  439. repo: emqx
  440. path: "_packages/${{ matrix.profile }}/emqx-*"
  441. token: ${{ github.token }}
  442. - uses: Rory-Z/upload-release-asset@v1
  443. if: github.event_name == 'release' && matrix.profile == 'emqx-ee'
  444. with:
  445. repo: emqx-enterprise
  446. path: "_packages/${{ matrix.profile }}/emqx-*"
  447. token: ${{ github.token }}
  448. - name: update to emqx.io
  449. if: github.event_name == 'release'
  450. run: |
  451. set -e -x -u
  452. curl -w %{http_code} \
  453. --insecure \
  454. -H "Content-Type: application/json" \
  455. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  456. -X POST \
  457. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  458. ${{ secrets.EMQX_IO_RELEASE_API }}
  459. - name: push docker image to docker hub
  460. if: github.event_name == 'release'
  461. run: |
  462. set -e -x -u
  463. sudo make docker-prepare
  464. cd _packages/${{ matrix.profile }} && for var in $(ls |grep docker |grep -v sha256); do unzip $var; sudo docker load < ${var%.*}; rm -f ${var%.*}; done && cd -
  465. echo ${{ secrets.DOCKER_HUB_TOKEN }} |sudo docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin
  466. sudo TARGET=emqx/${{ matrix.profile }} make docker-push
  467. sudo TARGET=emqx/${{ matrix.profile }} make docker-manifest-list
  468. - name: update repo.emqx.io
  469. if: github.event_name == 'release' && endsWith(github.repository, 'enterprise') && matrix.profile == 'emqx-ee'
  470. run: |
  471. curl --silent --show-error \
  472. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  473. -H "Accept: application/vnd.github.v3+json" \
  474. -X POST \
  475. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ee\": \"true\"}}" \
  476. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  477. - name: update repo.emqx.io
  478. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  479. run: |
  480. curl --silent --show-error \
  481. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  482. -H "Accept: application/vnd.github.v3+json" \
  483. -X POST \
  484. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ce\": \"true\"}}" \
  485. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  486. - name: update homebrew packages
  487. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  488. run: |
  489. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  490. curl --silent --show-error \
  491. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  492. -H "Accept: application/vnd.github.v3+json" \
  493. -X POST \
  494. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  495. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  496. fi
  497. - uses: geekyeggo/delete-artifact@v1
  498. with:
  499. name: ${{ matrix.profile }}