build_packages.yaml 18 KB

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