build_packages.yaml 17 KB

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