build_packages.yaml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. needs: prepare
  133. strategy:
  134. fail-fast: false
  135. matrix:
  136. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  137. macos:
  138. - macos-11
  139. - macos-10.15
  140. otp:
  141. - 24.0.5-emqx-1
  142. exclude:
  143. - profile: emqx-edge
  144. runs-on: ${{ matrix.macos }}
  145. steps:
  146. - uses: actions/download-artifact@v2
  147. with:
  148. name: source-${{ matrix.otp }}
  149. path: .
  150. - name: unzip source code
  151. run: unzip -q source-${{ matrix.otp }}.zip
  152. - name: prepare
  153. run: |
  154. brew update
  155. brew install curl zip unzip gnu-sed kerl unixodbc freetds
  156. echo "/usr/local/bin" >> $GITHUB_PATH
  157. git config --global credential.helper store
  158. - uses: actions/cache@v2
  159. id: cache
  160. with:
  161. path: ~/.kerl
  162. key: otp-${{ matrix.otp }}-${{ matrix.macos }}
  163. - name: build erlang
  164. if: steps.cache.outputs.cache-hit != 'true'
  165. timeout-minutes: 60
  166. run: |
  167. kerl build git https://github.com/emqx/otp.git OTP-${{ matrix.otp }} ${{ matrix.otp }}
  168. kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
  169. - name: build
  170. working-directory: source
  171. run: |
  172. . $HOME/.kerl/${{ matrix.otp }}/activate
  173. make ensure-rebar3
  174. sudo cp rebar3 /usr/local/bin/rebar3
  175. make ${{ matrix.profile }}-zip
  176. - name: test
  177. working-directory: source
  178. run: |
  179. pkg_name=$(find _packages/${{ matrix.profile }} -mindepth 1 -maxdepth 1 -iname \*.zip | head)
  180. unzip -q $pkg_name
  181. # gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  182. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  183. ready='no'
  184. for i in {1..10}; do
  185. if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then
  186. ready='yes'
  187. break
  188. fi
  189. sleep 1
  190. done
  191. if [ "$ready" != "yes" ]; then
  192. echo "Timed out waiting for emqx to be ready"
  193. cat emqx/log/erlang.log.1
  194. exit 1
  195. fi
  196. ./emqx/bin/emqx_ctl status
  197. ./emqx/bin/emqx stop
  198. rm -rf emqx
  199. openssl dgst -sha256 $pkg_name | awk '{print $2}' > $pkg_name.sha256
  200. - uses: actions/upload-artifact@v1
  201. if: startsWith(github.ref, 'refs/tags/')
  202. with:
  203. name: ${{ matrix.profile }}-${{ matrix.otp }}
  204. path: source/_packages/${{ matrix.profile }}/.
  205. linux:
  206. runs-on: ubuntu-20.04
  207. needs: prepare
  208. strategy:
  209. fail-fast: false
  210. matrix:
  211. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  212. os:
  213. - ubuntu20.04
  214. - ubuntu18.04
  215. - ubuntu16.04
  216. - debian10
  217. - debian9
  218. # - opensuse
  219. - centos8
  220. - centos7
  221. - centos6
  222. - raspbian10
  223. # - raspbian9
  224. arch:
  225. - amd64
  226. - arm64
  227. otp:
  228. - 23.2.7.2-emqx-2
  229. - 24.0.5-emqx-1
  230. exclude:
  231. - os: centos6
  232. arch: arm64
  233. - os: raspbian9
  234. arch: amd64
  235. - os: raspbian10
  236. arch: amd64
  237. - os: raspbian9
  238. profile: emqx
  239. - os: raspbian10
  240. profile: emqx
  241. - os: raspbian9
  242. profile: emqx-ee
  243. - os: raspbian10
  244. profile: emqx-ee
  245. defaults:
  246. run:
  247. shell: bash
  248. steps:
  249. - uses: docker/setup-buildx-action@v1
  250. - uses: docker/setup-qemu-action@v1
  251. with:
  252. image: tonistiigi/binfmt:latest
  253. platforms: all
  254. - uses: actions/download-artifact@v2
  255. with:
  256. name: source-${{ matrix.otp }}
  257. path: .
  258. - name: unzip source code
  259. run: unzip -q source-${{ matrix.otp }}.zip
  260. - name: downloads old emqx zip packages
  261. env:
  262. PROFILE: ${{ matrix.profile }}
  263. ARCH: ${{ matrix.arch }}
  264. SYSTEM: ${{ matrix.os }}
  265. OLD_VSNS: ${{ needs.prepare.outputs.old_vsns }}
  266. working-directory: source
  267. run: |
  268. set -e -x -u
  269. broker=$PROFILE
  270. if [ $PROFILE = "emqx" ];then
  271. broker="emqx-ce"
  272. fi
  273. if [ ! -z "$(echo $SYSTEM | grep -oE 'raspbian')" ]; then
  274. export ARCH="arm"
  275. fi
  276. mkdir -p _upgrade_base
  277. cd _upgrade_base
  278. old_vsns=($(echo $OLD_VSNS | tr ' ' ' '))
  279. for tag in ${old_vsns[@]}; do
  280. 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
  281. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip
  282. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip.sha256
  283. echo "$(cat $PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip.sha256) $PROFILE-$SYSTEM-${tag#[e|v]}-$ARCH.zip" | sha256sum -c || exit 1
  284. fi
  285. done
  286. - name: build emqx packages
  287. env:
  288. OTP: ${{ matrix.otp }}
  289. PROFILE: ${{ matrix.profile }}
  290. ARCH: ${{ matrix.arch }}
  291. SYSTEM: ${{ matrix.os }}
  292. working-directory: source
  293. run: |
  294. docker run -i --rm \
  295. -v $(pwd):/emqx \
  296. --workdir /emqx \
  297. --platform linux/$ARCH \
  298. ghcr.io/emqx/emqx-builder-helper/5.0:$OTP-$SYSTEM \
  299. bash -euc "make $PROFILE-zip || cat rebar3.crashdump; \
  300. make $PROFILE-pkg || cat rebar3.crashdump; \
  301. EMQX_NAME=$PROFILE && .ci/build_packages/tests.sh"
  302. - name: create sha256
  303. env:
  304. PROFILE: ${{ matrix.profile}}
  305. working-directory: source
  306. run: |
  307. if [ -d _packages/$PROFILE ]; then
  308. cd _packages/$PROFILE
  309. for var in $(ls emqx-* ); do
  310. sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  311. done
  312. cd -
  313. fi
  314. - uses: actions/upload-artifact@v1
  315. if: startsWith(github.ref, 'refs/tags/')
  316. with:
  317. name: ${{ matrix.profile }}-${{ matrix.otp }}
  318. path: source/_packages/${{ matrix.profile }}/.
  319. docker:
  320. runs-on: ubuntu-20.04
  321. needs: prepare
  322. strategy:
  323. fail-fast: false
  324. matrix:
  325. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  326. otp:
  327. - 24.0.5-emqx-1
  328. steps:
  329. - uses: actions/download-artifact@v2
  330. with:
  331. name: source-${{ matrix.otp }}
  332. path: .
  333. - name: unzip source code
  334. run: unzip -q source-${{ matrix.otp }}.zip
  335. - uses: docker/setup-buildx-action@v1
  336. - uses: docker/setup-qemu-action@v1
  337. with:
  338. image: tonistiigi/binfmt:latest
  339. platforms: all
  340. - uses: docker/metadata-action@v3
  341. id: meta
  342. with:
  343. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  344. flavor: |
  345. latest=${{ !github.event.release.prerelease }}
  346. tags: |
  347. type=ref,event=branch
  348. type=ref,event=pr
  349. type=ref,event=tag
  350. type=semver,pattern={{version}}
  351. type=semver,pattern={{major}}.{{minor}}
  352. - uses: docker/login-action@v1
  353. if: github.event_name == 'release'
  354. with:
  355. username: ${{ secrets.DOCKER_HUB_USER }}
  356. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  357. - uses: docker/build-push-action@v2
  358. with:
  359. push: ${{ github.event_name == 'release' }}
  360. pull: true
  361. no-cache: true
  362. platforms: linux/amd64,linux/arm64
  363. tags: ${{ steps.meta.outputs.tags }}
  364. labels: ${{ steps.meta.outputs.labels }}
  365. build-args: |
  366. BUILD_FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14
  367. RUN_FROM=alpine:3.14
  368. EMQX_NAME=${{ matrix.profile }}
  369. file: source/deploy/docker/Dockerfile
  370. context: source
  371. delete-artifact:
  372. runs-on: ubuntu-20.04
  373. strategy:
  374. matrix:
  375. otp:
  376. - 23.2.7.2-emqx-2
  377. - 24.0.5-emqx-1
  378. needs: [prepare, mac, linux, docker]
  379. steps:
  380. - uses: geekyeggo/delete-artifact@v1
  381. with:
  382. name: source-${{ matrix.otp }}
  383. upload:
  384. runs-on: ubuntu-20.04
  385. if: startsWith(github.ref, 'refs/tags/')
  386. needs: [prepare, mac, linux, docker]
  387. strategy:
  388. matrix:
  389. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  390. otp:
  391. - 24.0.5-emqx-1
  392. steps:
  393. - uses: actions/checkout@v2
  394. - name: get_version
  395. run: |
  396. echo 'version<<EOF' >> $GITHUB_ENV
  397. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  398. echo 'EOF' >> $GITHUB_ENV
  399. - uses: actions/download-artifact@v2
  400. with:
  401. name: ${{ matrix.profile }}-${{ matrix.otp }}
  402. path: ./_packages/${{ matrix.profile }}
  403. - name: install dos2unix
  404. run: sudo apt-get update && sudo apt install -y dos2unix
  405. - name: get packages
  406. run: |
  407. set -e -u
  408. cd _packages/${{ matrix.profile }}
  409. for var in $( ls |grep emqx |grep -v sha256); do
  410. dos2unix $var.sha256
  411. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  412. done
  413. cd -
  414. - name: upload aws s3
  415. run: |
  416. set -e -u
  417. if [ "${{ matrix.profile }}" == "emqx" ];then
  418. broker="emqx-ce"
  419. else
  420. broker=${{ matrix.profile }}
  421. fi
  422. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  423. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  424. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  425. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  426. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  427. - uses: Rory-Z/upload-release-asset@v1
  428. if: github.event_name == 'release' && matrix.profile != 'emqx-ee'
  429. with:
  430. repo: emqx
  431. path: "_packages/${{ matrix.profile }}/emqx-*"
  432. token: ${{ github.token }}
  433. - uses: Rory-Z/upload-release-asset@v1
  434. if: github.event_name == 'release' && matrix.profile == 'emqx-ee'
  435. with:
  436. repo: emqx-enterprise
  437. path: "_packages/${{ matrix.profile }}/emqx-*"
  438. token: ${{ github.token }}
  439. - name: update to emqx.io
  440. if: github.event_name == 'release'
  441. run: |
  442. set -e -x -u
  443. curl -w %{http_code} \
  444. --insecure \
  445. -H "Content-Type: application/json" \
  446. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  447. -X POST \
  448. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  449. ${{ secrets.EMQX_IO_RELEASE_API }}
  450. - name: update repo.emqx.io
  451. if: github.event_name == 'release' && endsWith(github.repository, 'enterprise') && matrix.profile == 'emqx-ee'
  452. run: |
  453. curl --silent --show-error \
  454. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  455. -H "Accept: application/vnd.github.v3+json" \
  456. -X POST \
  457. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ee\": \"true\"}}" \
  458. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  459. - name: update repo.emqx.io
  460. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  461. run: |
  462. curl --silent --show-error \
  463. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  464. -H "Accept: application/vnd.github.v3+json" \
  465. -X POST \
  466. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ce\": \"true\"}}" \
  467. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  468. - name: update homebrew packages
  469. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  470. run: |
  471. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  472. curl --silent --show-error \
  473. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  474. -H "Accept: application/vnd.github.v3+json" \
  475. -X POST \
  476. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  477. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  478. fi
  479. - uses: geekyeggo/delete-artifact@v1
  480. with:
  481. name: ${{ matrix.profile }}