build_packages.yaml 18 KB

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