build_packages.yaml 17 KB

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