build_packages.yaml 17 KB

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