build_packages.yaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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-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. exclude:
  115. - profile: emqx-edge
  116. steps:
  117. - uses: actions/download-artifact@v2
  118. with:
  119. name: source
  120. path: .
  121. - name: unzip source code
  122. run: unzip -q source.zip
  123. - name: prepare
  124. run: |
  125. brew install curl zip unzip gnu-sed kerl unixodbc freetds
  126. echo "/usr/local/bin" >> $GITHUB_PATH
  127. git config --global credential.helper store
  128. - name: build erlang
  129. timeout-minutes: 60
  130. run: |
  131. kerl build 23.2.7
  132. kerl install 23.2.7 $HOME/.kerl/23.2.7
  133. - name: build
  134. run: |
  135. . $HOME/.kerl/23.2.7/activate
  136. make -C source ${{ matrix.profile }}-pkg
  137. - name: test
  138. run: |
  139. cd source
  140. pkg_name=$(basename _packages/${{ matrix.profile }}/${{ matrix.profile }}-*.zip)
  141. unzip _packages/${{ matrix.profile }}/$pkg_name
  142. gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  143. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  144. ready='no'
  145. for i in {1..10}; do
  146. if curl -fs 127.0.0.1:18083 > /dev/null; then
  147. ready='yes'
  148. break
  149. fi
  150. sleep 1
  151. done
  152. if [ "$ready" != "yes" ]; then
  153. echo "Timed out waiting for emqx to be ready"
  154. cat emqx/log/erlang.log.1
  155. exit 1
  156. fi
  157. ./emqx/bin/emqx_ctl status
  158. ./emqx/bin/emqx stop
  159. rm -rf emqx
  160. openssl dgst -sha256 ./_packages/${{ matrix.profile }}/$pkg_name | awk '{print $2}' > ./_packages/${{ matrix.profile }}/$pkg_name.sha256
  161. - uses: actions/upload-artifact@v1
  162. if: startsWith(github.ref, 'refs/tags/')
  163. with:
  164. name: ${{ matrix.profile }}
  165. path: source/_packages/${{ matrix.profile }}/.
  166. linux:
  167. runs-on: ubuntu-20.04
  168. needs: prepare
  169. strategy:
  170. matrix:
  171. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  172. arch:
  173. - amd64
  174. - arm64
  175. os:
  176. - ubuntu20.04
  177. - ubuntu18.04
  178. - ubuntu16.04
  179. - debian10
  180. - debian9
  181. # - opensuse
  182. - centos8
  183. - centos7
  184. - centos6
  185. - raspbian10
  186. - raspbian9
  187. exclude:
  188. - os: centos6
  189. arch: arm64
  190. - os: raspbian9
  191. arch: amd64
  192. - os: raspbian10
  193. arch: amd64
  194. - os: raspbian9
  195. profile: emqx
  196. - os: raspbian10
  197. profile: emqx
  198. - os: raspbian9
  199. profile: emqx-ee
  200. - os: raspbian10
  201. profile: emqx-ee
  202. defaults:
  203. run:
  204. shell: bash
  205. steps:
  206. - name: prepare docker
  207. run: |
  208. mkdir -p $HOME/.docker
  209. echo '{ "experimental": "enabled" }' | tee $HOME/.docker/config.json
  210. echo '{ "experimental": true, "storage-driver": "overlay2", "max-concurrent-downloads": 50, "max-concurrent-uploads": 50}' | sudo tee /etc/docker/daemon.json
  211. sudo systemctl restart docker
  212. docker info
  213. docker buildx create --use --name mybuild
  214. docker run --rm --privileged tonistiigi/binfmt --install all
  215. - uses: actions/download-artifact@v2
  216. with:
  217. name: source
  218. path: .
  219. - name: unzip source code
  220. run: unzip -q source.zip
  221. - name: downloads emqx zip packages
  222. env:
  223. PROFILE: ${{ matrix.profile }}
  224. ARCH: ${{ matrix.arch }}
  225. SYSTEM: ${{ matrix.os }}
  226. run: |
  227. set -e -u -x
  228. cd source
  229. if [ $ARCH = "arm64" ];then arch="aarch64"; else arch="x86_64"; fi
  230. if [ $PROFILE = "emqx" ];then broker="emqx-ce"; else broker="$PROFILE"; fi
  231. if [ $PROFILE = "emqx-ee" ];then edition='enterprise'; else edition='opensource'; fi
  232. vsn="$(grep -E "define.+EMQX_RELEASE.+${edition}" include/emqx_release.hrl | cut -d '"' -f2)"
  233. pre_vsn="$(echo $vsn | grep -oE '^[0-9]+.[0-9]')"
  234. if [ $PROFILE = "emqx-ee" ]; then
  235. old_vsns=($(git tag -l "e$pre_vsn.[0-9]" | sed "s/e$vsn//"))
  236. else
  237. old_vsns=($(git tag -l "v$pre_vsn.[0-9]" | sed "s/v$vsn//"))
  238. fi
  239. mkdir -p tmp/relup_packages/$PROFILE
  240. cd tmp/relup_packages/$PROFILE
  241. for tag in ${old_vsns[@]};do
  242. 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
  243. wget https://s3-${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ secrets.AWS_S3_BUCKET }}/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$arch.zip
  244. wget https://s3-${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ secrets.AWS_S3_BUCKET }}/$broker/$tag/$PROFILE-$SYSTEM-${tag#[e|v]}-$arch.zip.sha256
  245. echo "$(cat $PROFILE-$SYSTEM-${tag#[e|v]}-$arch.zip.sha256) $PROFILE-$SYSTEM-${tag#[e|v]}-$arch.zip" | sha256sum -c || exit 1
  246. fi
  247. done
  248. cd -
  249. - name: build emqx packages
  250. env:
  251. ERL_OTP: erl23.2.7
  252. PROFILE: ${{ matrix.profile }}
  253. ARCH: ${{ matrix.arch }}
  254. SYSTEM: ${{ matrix.os }}
  255. run: |
  256. set -e -u
  257. cd source
  258. docker buildx build --no-cache \
  259. --platform=linux/$ARCH \
  260. -t cross_build_emqx_for_$SYSTEM \
  261. -f .ci/build_packages/Dockerfile \
  262. --build-arg BUILD_FROM=emqx/build-env:$ERL_OTP-$SYSTEM \
  263. --build-arg EMQX_NAME=$PROFILE \
  264. --output type=tar,dest=/tmp/cross-build-$PROFILE-for-$SYSTEM.tar .
  265. mkdir -p /tmp/packages/$PROFILE
  266. tar -xvf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar --wildcards emqx/_packages/$PROFILE/*
  267. mv emqx/_packages/$PROFILE/* /tmp/packages/$PROFILE/
  268. rm -rf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar
  269. docker rm -f $(docker ps -a -q)
  270. docker volume prune -f
  271. - name: create sha256
  272. env:
  273. PROFILE: ${{ matrix.profile}}
  274. run: |
  275. if [ -d /tmp/packages/$PROFILE ]; then
  276. cd /tmp/packages/$PROFILE
  277. for var in $(ls emqx-* ); do
  278. bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  279. done
  280. cd -
  281. fi
  282. - uses: actions/upload-artifact@v1
  283. if: startsWith(github.ref, 'refs/tags/')
  284. with:
  285. name: ${{ matrix.profile }}
  286. path: /tmp/packages/${{ matrix.profile }}/.
  287. docker:
  288. runs-on: ubuntu-20.04
  289. needs: prepare
  290. strategy:
  291. matrix:
  292. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  293. arch:
  294. - [amd64, x86_64]
  295. - [arm64v8, aarch64]
  296. - [arm32v7, arm]
  297. - [i386, i386]
  298. - [s390x, s390x]
  299. exclude:
  300. - profile: emqx-ee
  301. arch: [i386, i386]
  302. - profile: emqx-ee
  303. arch: [s390x, s390x]
  304. steps:
  305. - uses: actions/download-artifact@v2
  306. with:
  307. name: source
  308. path: .
  309. - name: unzip source code
  310. run: unzip -q source.zip
  311. - name: build emqx docker image
  312. env:
  313. PROFILE: ${{ matrix.profile }}
  314. ARCH: ${{ matrix.arch[0] }}
  315. QEMU_ARCH: ${{ matrix.arch[1] }}
  316. run: |
  317. sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  318. cd source
  319. sudo TARGET=emqx/$PROFILE ARCH=$ARCH QEMU_ARCH=$QEMU_ARCH make docker
  320. cd _packages/$PROFILE && for var in $(ls ${PROFILE}-docker-* ); do sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"; done && cd -
  321. - uses: actions/upload-artifact@v1
  322. if: startsWith(github.ref, 'refs/tags/')
  323. with:
  324. name: ${{ matrix.profile }}
  325. path: source/_packages/${{ matrix.profile }}/.
  326. delete-artifact:
  327. runs-on: ubuntu-20.04
  328. needs: [prepare, mac, linux, docker]
  329. steps:
  330. - uses: geekyeggo/delete-artifact@v1
  331. with:
  332. name: source
  333. upload:
  334. runs-on: ubuntu-20.04
  335. if: startsWith(github.ref, 'refs/tags/')
  336. needs: [prepare, mac, linux, docker]
  337. strategy:
  338. matrix:
  339. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  340. steps:
  341. - uses: actions/checkout@v2
  342. - name: get_version
  343. run: |
  344. echo 'version<<EOF' >> $GITHUB_ENV
  345. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  346. echo 'EOF' >> $GITHUB_ENV
  347. - uses: actions/download-artifact@v2
  348. with:
  349. name: ${{ matrix.profile }}
  350. path: ./_packages/${{ matrix.profile }}
  351. - name: install dos2unix
  352. run: sudo apt-get update && sudo apt install -y dos2unix
  353. - name: get packages
  354. run: |
  355. set -e -u
  356. cd _packages/${{ matrix.profile }}
  357. for var in $( ls |grep emqx |grep -v sha256); do
  358. dos2unix $var.sha256
  359. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  360. done
  361. cd -
  362. - name: upload aws s3
  363. run: |
  364. set -e -u
  365. if [ "${{ matrix.profile }}" == "emqx" ];then
  366. broker="emqx-ce"
  367. else
  368. broker=${{ matrix.profile }}
  369. fi
  370. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  371. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  372. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  373. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  374. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  375. - uses: Rory-Z/upload-release-asset@v1
  376. if: github.event_name == 'release'
  377. with:
  378. repo: emqx
  379. path: "_packages/${{ matrix.profile }}/emqx-*"
  380. token: ${{ github.token }}
  381. - name: update to emqx.io
  382. if: github.event_name == 'release'
  383. run: |
  384. set -e -x -u
  385. curl -w %{http_code} \
  386. --insecure \
  387. -H "Content-Type: application/json" \
  388. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  389. -X POST \
  390. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  391. ${{ secrets.EMQX_IO_RELEASE_API }}
  392. - name: push docker image to docker hub
  393. if: github.event_name == 'release'
  394. run: |
  395. set -e -x -u
  396. sudo make docker-prepare
  397. 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 -
  398. echo ${{ secrets.DOCKER_HUB_TOKEN }} |sudo docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin
  399. sudo TARGET=emqx/${{ matrix.profile }} make docker-push
  400. sudo TARGET=emqx/${{ matrix.profile }} make docker-manifest-list
  401. - name: update repo.emqx.io
  402. if: github.event_name == 'release' && endsWith(github.repository, 'enterprise') && matrix.profile == 'emqx-ee'
  403. run: |
  404. curl --silent --show-error \
  405. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  406. -H "Accept: application/vnd.github.v3+json" \
  407. -X POST \
  408. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ee\": \"true\"}}" \
  409. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  410. - name: update repo.emqx.io
  411. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  412. run: |
  413. curl --silent --show-error \
  414. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  415. -H "Accept: application/vnd.github.v3+json" \
  416. -X POST \
  417. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ce\": \"true\"}}" \
  418. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  419. - name: update homebrew packages
  420. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  421. run: |
  422. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  423. curl --silent --show-error \
  424. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  425. -H "Accept: application/vnd.github.v3+json" \
  426. -X POST \
  427. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  428. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  429. fi
  430. - uses: geekyeggo/delete-artifact@v1
  431. with:
  432. name: ${{ matrix.profile }}