build_packages.yaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. inputs:
  13. which_branch:
  14. required: false
  15. jobs:
  16. prepare:
  17. runs-on: ubuntu-20.04
  18. # prepare source with any OTP version, no need for a matrix
  19. container: "ghcr.io/emqx/emqx-builder/5.0-2:24.1.5-2-ubuntu20.04"
  20. outputs:
  21. old_vsns: ${{ steps.find_old_versons.outputs.old_vsns }}
  22. steps:
  23. - uses: actions/checkout@v2
  24. with:
  25. ref: ${{ github.event.inputs.which_branch }}
  26. path: source
  27. fetch-depth: 0
  28. - name: find old versions
  29. id: find_old_versons
  30. shell: bash
  31. working-directory: source
  32. run: |
  33. vsn="$(./pkg-vsn.sh)"
  34. pre_vsn="$(echo $vsn | grep -oE '^[0-9]+.[0-9]')"
  35. old_vsns="$(git tag -l "v$pre_vsn.[0-9]" | xargs echo -n | sed "s/v$vsn//")"
  36. echo "::set-output name=old_vsns::$old_vsns"
  37. - name: get_all_deps
  38. run: |
  39. make -C source deps-all
  40. zip -ryq source.zip source/* source/.[^.]*
  41. - uses: actions/upload-artifact@v2
  42. with:
  43. name: source
  44. path: source.zip
  45. windows:
  46. runs-on: windows-2019
  47. needs: prepare
  48. strategy:
  49. fail-fast: false
  50. matrix:
  51. profile: # only CE for windows
  52. - emqx
  53. otp:
  54. - 23.2
  55. steps:
  56. - uses: actions/download-artifact@v2
  57. with:
  58. name: source
  59. path: .
  60. - name: unzip source code
  61. run: Expand-Archive -Path source.zip -DestinationPath ./
  62. - uses: ilammy/msvc-dev-cmd@v1
  63. - uses: gleam-lang/setup-erlang@v1.1.2
  64. id: install_erlang
  65. ## gleam-lang/setup-erlang does not yet support the installation of otp24 on windows
  66. with:
  67. otp-version: ${{ matrix.otp }}
  68. - name: build
  69. env:
  70. PYTHON: python
  71. DIAGNOSTIC: 1
  72. working-directory: source
  73. run: |
  74. $env:PATH = "${{ steps.install_erlang.outputs.erlpath }}\bin;$env:PATH"
  75. $version = $( "${{ github.ref }}" -replace "^(.*)/(.*)/" )
  76. if ($version -match "^v[0-9]+\.[0-9]+(\.[0-9]+)?") {
  77. $regex = "[0-9]+\.[0-9]+(-alpha|-beta|-rc)?\.[0-9]+"
  78. $pkg_name = "${{ matrix.profile }}-$([regex]::matches($version, $regex).value)-otp${{ matrix.otp }}-windows-amd64.zip"
  79. }
  80. else {
  81. $pkg_name = "${{ matrix.profile }}-$($version -replace '/')-otp${{ matrix.otp }}-windows-amd64.zip"
  82. }
  83. ## We do not build/release bcrypt and quic for windows package
  84. Remove-Item -Recurse -Force -Path _build/default/lib/bcrypt/
  85. Remove-Item -Recurse -Force -Path _build/default/lib/quicer/
  86. if (Test-Path rebar.lock) {
  87. Remove-Item -Force -Path rebar.lock
  88. }
  89. make ensure-rebar3
  90. copy rebar3 "${{ steps.install_erlang.outputs.erlpath }}\bin"
  91. ls "${{ steps.install_erlang.outputs.erlpath }}\bin"
  92. rebar3 --help
  93. make ${{ matrix.profile }}
  94. mkdir -p _packages/${{ matrix.profile }}
  95. Compress-Archive -Path _build/${{ matrix.profile }}/rel/emqx -DestinationPath _build/${{ matrix.profile }}/rel/$pkg_name
  96. mv _build/${{ matrix.profile }}/rel/$pkg_name _packages/${{ matrix.profile }}
  97. Get-FileHash -Path "_packages/${{ matrix.profile }}/$pkg_name" | Format-List | grep 'Hash' | awk '{print $3}' > _packages/${{ matrix.profile }}/$pkg_name.sha256
  98. - name: run emqx
  99. timeout-minutes: 1
  100. working-directory: source
  101. run: |
  102. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  103. Start-Sleep -s 5
  104. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  105. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  106. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  107. - uses: actions/upload-artifact@v1
  108. if: startsWith(github.ref, 'refs/tags/')
  109. with:
  110. name: ${{ matrix.profile }}
  111. path: source/_packages/${{ matrix.profile }}/.
  112. mac:
  113. needs: prepare
  114. strategy:
  115. fail-fast: false
  116. matrix:
  117. profile: # no EDGE for mac
  118. - emqx
  119. - emqx-enterprise
  120. otp:
  121. - 24.1.5-2
  122. macos:
  123. - macos-11
  124. - macos-10.15
  125. exclude:
  126. - profile: emqx-edge
  127. runs-on: ${{ matrix.macos }}
  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: otp-${{ matrix.otp }}-${{ matrix.macos }}
  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.otp }}
  155. kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
  156. - name: build
  157. working-directory: source
  158. run: |
  159. . $HOME/.kerl/${{ matrix.otp }}/activate
  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. working-directory: source
  166. run: |
  167. pkg_name=$(find _packages/${{ matrix.profile }} -mindepth 1 -maxdepth 1 -iname \*.zip)
  168. unzip -q $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/api/v5/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 $pkg_name | awk '{print $2}' > $pkg_name.sha256
  188. - uses: actions/upload-artifact@v1
  189. if: startsWith(github.ref, 'refs/tags/')
  190. with:
  191. name: ${{ matrix.profile }}-${{ matrix.otp }}
  192. path: source/_packages/${{ matrix.profile }}/.
  193. linux:
  194. runs-on: ubuntu-20.04
  195. needs: prepare
  196. strategy:
  197. fail-fast: false
  198. matrix:
  199. profile: ## all editions for linux
  200. - emqx-edge
  201. - emqx
  202. - emqx-enterprise
  203. otp:
  204. - 24.1.5-2 # we test with OTP 23, but only build package on OTP 24 versions
  205. arch:
  206. - amd64
  207. - arm64
  208. os:
  209. - ubuntu20.04
  210. - ubuntu18.04
  211. - ubuntu16.04
  212. - debian10
  213. - debian9
  214. # - opensuse
  215. - centos8
  216. - centos7
  217. - raspbian10
  218. # - raspbian9
  219. exclude:
  220. - os: raspbian9
  221. arch: amd64
  222. - os: raspbian10
  223. arch: amd64
  224. - os: raspbian9
  225. profile: emqx
  226. - os: raspbian10
  227. profile: emqx
  228. - os: raspbian9
  229. profile: emqx-enterprise
  230. - os: raspbian10
  231. profile: emqx-enterprise
  232. defaults:
  233. run:
  234. shell: bash
  235. steps:
  236. - uses: docker/setup-buildx-action@v1
  237. - uses: docker/setup-qemu-action@v1
  238. with:
  239. image: tonistiigi/binfmt:latest
  240. platforms: all
  241. - uses: actions/download-artifact@v2
  242. with:
  243. name: source
  244. path: .
  245. - name: unzip source code
  246. run: unzip -q source.zip
  247. - name: downloads old emqx zip packages
  248. env:
  249. OTP_VSN: ${{ matrix.otp }}
  250. PROFILE: ${{ matrix.profile }}
  251. ARCH: ${{ matrix.arch }}
  252. SYSTEM: ${{ matrix.os }}
  253. OLD_VSNS: ${{ needs.prepare.outputs.old_vsns }}
  254. working-directory: source
  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 _upgrade_base
  265. cd _upgrade_base
  266. old_vsns=($(echo $OLD_VSNS | tr ' ' ' '))
  267. for tag in ${old_vsns[@]}; do
  268. package_name="${PROFILE}-${tag#[e|v]}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
  269. 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/$package_name.zip) | grep -oE "^[23]+")" ]; then
  270. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$package_name.zip
  271. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$broker/$tag/$package_name.zip.sha256
  272. echo "$(cat $package_name.zip.sha256) $package_name.zip" | sha256sum -c || exit 1
  273. fi
  274. done
  275. - name: build emqx packages
  276. env:
  277. OTP: ${{ matrix.otp }}
  278. PROFILE: ${{ matrix.profile }}
  279. ARCH: ${{ matrix.arch }}
  280. SYSTEM: ${{ matrix.os }}
  281. working-directory: source
  282. run: |
  283. docker run -i --rm \
  284. -v $(pwd):/emqx \
  285. --workdir /emqx \
  286. --platform linux/$ARCH \
  287. ghcr.io/emqx/emqx-builder/5.0-2:$OTP-$SYSTEM \
  288. bash -euc "make $PROFILE-zip || cat rebar3.crashdump; \
  289. make $PROFILE-pkg || cat rebar3.crashdump; \
  290. EMQX_NAME=$PROFILE && .ci/build_packages/tests.sh"
  291. - name: create sha256
  292. env:
  293. PROFILE: ${{ matrix.profile}}
  294. working-directory: source
  295. run: |
  296. if [ -d _packages/$PROFILE ]; then
  297. cd _packages/$PROFILE
  298. for var in $(ls emqx-* ); do
  299. sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  300. done
  301. cd -
  302. fi
  303. - uses: actions/upload-artifact@v1
  304. if: startsWith(github.ref, 'refs/tags/')
  305. with:
  306. name: ${{ matrix.profile }}-${{ matrix.otp }}
  307. path: source/_packages/${{ matrix.profile }}/.
  308. docker:
  309. runs-on: ubuntu-20.04
  310. needs: prepare
  311. strategy:
  312. fail-fast: false
  313. matrix:
  314. profile: # all editions for docker
  315. - emqx-edge
  316. - emqx
  317. - emqx-enterprise
  318. # NOTE: for docker, only support latest otp version, not a matrix
  319. otp:
  320. - 24.1.5-2 # update to latest
  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. - uses: docker/setup-buildx-action@v1
  329. - uses: docker/setup-qemu-action@v1
  330. with:
  331. image: tonistiigi/binfmt:latest
  332. platforms: all
  333. - uses: docker/metadata-action@v3
  334. id: meta
  335. with:
  336. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  337. flavor: |
  338. latest=${{ !github.event.release.prerelease }}
  339. tags: |
  340. type=ref,event=branch
  341. type=ref,event=pr
  342. type=ref,event=tag
  343. type=semver,pattern={{version}}
  344. labels:
  345. org.opencontainers.image.otp.version=${{ matrix.otp }}
  346. - uses: docker/login-action@v1
  347. if: github.event_name == 'release'
  348. with:
  349. username: ${{ secrets.DOCKER_HUB_USER }}
  350. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  351. - uses: docker/build-push-action@v2
  352. with:
  353. push: ${{ github.event_name == 'release' && !github.event.release.prerelease }}
  354. pull: true
  355. no-cache: true
  356. platforms: linux/amd64,linux/arm64
  357. tags: ${{ steps.meta.outputs.tags }}
  358. labels: ${{ steps.meta.outputs.labels }}
  359. build-args: |
  360. BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-2:${{ matrix.otp }}-alpine3.14
  361. RUN_FROM=alpine:3.14
  362. EMQX_NAME=${{ matrix.profile }}
  363. file: source/deploy/docker/Dockerfile
  364. context: source
  365. delete-artifact:
  366. runs-on: ubuntu-20.04
  367. needs: [prepare, mac, linux, docker]
  368. steps:
  369. - uses: geekyeggo/delete-artifact@v1
  370. with:
  371. name: source
  372. upload:
  373. runs-on: ubuntu-20.04
  374. if: startsWith(github.ref, 'refs/tags/')
  375. needs: [prepare, mac, linux, docker]
  376. strategy:
  377. matrix:
  378. profile:
  379. - emqx-edge
  380. - emqx
  381. - emqx-enterprise
  382. otp:
  383. - 24.1.5-2
  384. steps:
  385. - uses: actions/checkout@v2
  386. - name: get_version
  387. run: |
  388. echo 'version<<EOF' >> $GITHUB_ENV
  389. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  390. echo 'EOF' >> $GITHUB_ENV
  391. - uses: actions/download-artifact@v2
  392. with:
  393. name: ${{ matrix.profile }}-${{ matrix.otp }}
  394. path: ./_packages/${{ matrix.profile }}
  395. - name: install dos2unix
  396. run: sudo apt-get update && sudo apt install -y dos2unix
  397. - name: get packages
  398. run: |
  399. set -e -u
  400. cd _packages/${{ matrix.profile }}
  401. for var in $( ls |grep emqx |grep -v sha256); do
  402. dos2unix $var.sha256
  403. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  404. done
  405. cd -
  406. - name: upload aws s3
  407. run: |
  408. set -e -u
  409. if [ "${{ matrix.profile }}" == "emqx" ];then
  410. broker="emqx-ce"
  411. else
  412. broker=${{ matrix.profile }}
  413. fi
  414. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  415. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  416. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  417. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  418. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  419. - uses: Rory-Z/upload-release-asset@v1
  420. if: github.event_name == 'release'
  421. with:
  422. repo: emqx
  423. path: "_packages/${{ matrix.profile }}/emqx-*"
  424. token: ${{ github.token }}
  425. - name: update to emqx.io
  426. if: github.event_name == 'release'
  427. run: |
  428. set -e -x -u
  429. curl -w %{http_code} \
  430. --insecure \
  431. -H "Content-Type: application/json" \
  432. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  433. -X POST \
  434. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  435. ${{ secrets.EMQX_IO_RELEASE_API }}
  436. - name: update repo.emqx.io
  437. if: github.event_name == 'release'
  438. run: |
  439. if [ "${{ matrix.profile }}" = 'emqx-enterprise' ]; then
  440. BOOL_FLAG_NAME="emqx_ee"
  441. else
  442. BOOL_FLAG_NAME="emqx_ce"
  443. fi
  444. curl --silent --show-error \
  445. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  446. -H "Accept: application/vnd.github.v3+json" \
  447. -X POST \
  448. -d "{\"ref\":\"v1.0.4\",\"inputs\":{\"version\": \"${{ env.version }}\", \"${BOOL_FLAG_NAME}\": \"true\"}}" \
  449. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  450. - name: update homebrew packages
  451. if: github.event_name == 'release' && matrix.profile == 'emqx'
  452. run: |
  453. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  454. curl --silent --show-error \
  455. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  456. -H "Accept: application/vnd.github.v3+json" \
  457. -X POST \
  458. -d "{\"ref\":\"v1.0.4\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  459. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  460. fi
  461. - uses: geekyeggo/delete-artifact@v1
  462. with:
  463. name: ${{ matrix.profile }}