build_packages.yaml 18 KB

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