build_packages.yaml 17 KB

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