build_packages.yaml 17 KB

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