build_packages.yaml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. 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-2
  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:8081/status > /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-2
  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. steps:
  322. - uses: actions/download-artifact@v2
  323. with:
  324. name: source
  325. path: .
  326. - name: unzip source code
  327. run: unzip -q source.zip
  328. - name: build emqx docker image
  329. env:
  330. PROFILE: ${{ matrix.profile }}
  331. ARCH: ${{ matrix.arch[0] }}
  332. QEMU_ARCH: ${{ matrix.arch[1] }}
  333. run: |
  334. sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  335. cd source
  336. sudo TARGET=emqx/$PROFILE ARCH=$ARCH QEMU_ARCH=$QEMU_ARCH make docker
  337. cd _packages/$PROFILE && for var in $(ls ${PROFILE}-docker-* ); do sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"; done && cd -
  338. - uses: actions/upload-artifact@v1
  339. if: startsWith(github.ref, 'refs/tags/')
  340. with:
  341. name: ${{ matrix.profile }}
  342. path: source/_packages/${{ matrix.profile }}/.
  343. delete-artifact:
  344. runs-on: ubuntu-20.04
  345. needs: [prepare, mac, linux, docker]
  346. steps:
  347. - uses: geekyeggo/delete-artifact@v1
  348. with:
  349. name: source
  350. upload:
  351. runs-on: ubuntu-20.04
  352. if: startsWith(github.ref, 'refs/tags/')
  353. needs: [prepare, mac, linux, docker]
  354. strategy:
  355. matrix:
  356. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  357. steps:
  358. - uses: actions/checkout@v2
  359. - name: get_version
  360. run: |
  361. echo 'version<<EOF' >> $GITHUB_ENV
  362. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  363. echo 'EOF' >> $GITHUB_ENV
  364. - uses: actions/download-artifact@v2
  365. with:
  366. name: ${{ matrix.profile }}
  367. path: ./_packages/${{ matrix.profile }}
  368. - name: install dos2unix
  369. run: sudo apt-get update && sudo apt install -y dos2unix
  370. - name: get packages
  371. run: |
  372. set -e -u
  373. cd _packages/${{ matrix.profile }}
  374. for var in $( ls |grep emqx |grep -v sha256); do
  375. dos2unix $var.sha256
  376. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  377. done
  378. cd -
  379. - name: upload aws s3
  380. run: |
  381. set -e -u
  382. if [ "${{ matrix.profile }}" == "emqx" ];then
  383. broker="emqx-ce"
  384. else
  385. broker=${{ matrix.profile }}
  386. fi
  387. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  388. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  389. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  390. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  391. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  392. - uses: Rory-Z/upload-release-asset@v1
  393. if: github.event_name == 'release' && matrix.profile != 'emqx-ee'
  394. with:
  395. repo: emqx
  396. path: "_packages/${{ matrix.profile }}/emqx-*"
  397. token: ${{ github.token }}
  398. - uses: Rory-Z/upload-release-asset@v1
  399. if: github.event_name == 'release' && matrix.profile == 'emqx-ee'
  400. with:
  401. repo: emqx-enterprise
  402. path: "_packages/${{ matrix.profile }}/emqx-*"
  403. token: ${{ github.token }}
  404. - name: update to emqx.io
  405. if: github.event_name == 'release'
  406. run: |
  407. set -e -x -u
  408. curl -w %{http_code} \
  409. --insecure \
  410. -H "Content-Type: application/json" \
  411. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  412. -X POST \
  413. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  414. ${{ secrets.EMQX_IO_RELEASE_API }}
  415. - name: push docker image to docker hub
  416. if: github.event_name == 'release'
  417. run: |
  418. set -e -x -u
  419. sudo make docker-prepare
  420. 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 -
  421. echo ${{ secrets.DOCKER_HUB_TOKEN }} |sudo docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin
  422. sudo TARGET=emqx/${{ matrix.profile }} make docker-push
  423. sudo TARGET=emqx/${{ matrix.profile }} make docker-manifest-list
  424. - name: update repo.emqx.io
  425. if: github.event_name == 'release' && endsWith(github.repository, 'enterprise') && matrix.profile == 'emqx-ee'
  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_ee\": \"true\"}}" \
  432. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  433. - name: update repo.emqx.io
  434. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  435. run: |
  436. curl --silent --show-error \
  437. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  438. -H "Accept: application/vnd.github.v3+json" \
  439. -X POST \
  440. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ce\": \"true\"}}" \
  441. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  442. - name: update homebrew packages
  443. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  444. run: |
  445. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  446. curl --silent --show-error \
  447. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  448. -H "Accept: application/vnd.github.v3+json" \
  449. -X POST \
  450. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  451. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  452. fi
  453. - uses: geekyeggo/delete-artifact@v1
  454. with:
  455. name: ${{ matrix.profile }}