build_packages.yaml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. erl_otp:
  204. - 23.2.7.2-emqx-2
  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. - centos6
  218. - raspbian10
  219. # - raspbian9
  220. exclude:
  221. - os: centos6
  222. arch: arm64
  223. - os: raspbian9
  224. arch: amd64
  225. - os: raspbian10
  226. arch: amd64
  227. - os: raspbian9
  228. profile: emqx
  229. - os: raspbian10
  230. profile: emqx
  231. - os: raspbian9
  232. profile: emqx-ee
  233. - os: raspbian10
  234. profile: emqx-ee
  235. defaults:
  236. run:
  237. shell: bash
  238. steps:
  239. - name: prepare docker
  240. run: |
  241. mkdir -p $HOME/.docker
  242. echo '{ "experimental": "enabled" }' | tee $HOME/.docker/config.json
  243. echo '{ "experimental": true, "storage-driver": "overlay2", "max-concurrent-downloads": 50, "max-concurrent-uploads": 50}' | sudo tee /etc/docker/daemon.json
  244. sudo systemctl restart docker
  245. docker info
  246. docker buildx create --use --name mybuild
  247. docker run --rm --privileged tonistiigi/binfmt --install all
  248. - uses: actions/download-artifact@v2
  249. with:
  250. name: source
  251. path: .
  252. - name: unzip source code
  253. run: unzip -q source.zip
  254. - name: downloads old emqx zip packages
  255. env:
  256. PROFILE: ${{ matrix.profile }}
  257. ARCH: ${{ matrix.arch }}
  258. SYSTEM: ${{ matrix.os }}
  259. OLD_VSNS: ${{ needs.prepare.outputs.old_vsns }}
  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 source/_upgrade_base
  270. cd source/_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. run: |
  286. set -e -u
  287. cd source
  288. docker buildx build --no-cache \
  289. --platform=linux/$ARCH \
  290. -t cross_build_emqx_for_$SYSTEM \
  291. -f .ci/build_packages/Dockerfile \
  292. --build-arg BUILD_FROM=emqx/build-env:$ERL_OTP-$SYSTEM \
  293. --build-arg EMQX_NAME=$PROFILE \
  294. --output type=tar,dest=/tmp/cross-build-$PROFILE-for-$SYSTEM.tar .
  295. mkdir -p /tmp/packages/$PROFILE
  296. tar -xvf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar --wildcards emqx/_packages/$PROFILE/*
  297. mv emqx/_packages/$PROFILE/* /tmp/packages/$PROFILE/
  298. rm -rf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar
  299. docker rm -f $(docker ps -a -q)
  300. docker volume prune -f
  301. - name: create sha256
  302. env:
  303. PROFILE: ${{ matrix.profile}}
  304. run: |
  305. if [ -d /tmp/packages/$PROFILE ]; then
  306. cd /tmp/packages/$PROFILE
  307. for var in $(ls emqx-* ); do
  308. bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  309. done
  310. cd -
  311. fi
  312. - uses: actions/upload-artifact@v1
  313. if: startsWith(github.ref, 'refs/tags/')
  314. with:
  315. name: ${{ matrix.profile }}
  316. path: /tmp/packages/${{ matrix.profile }}/.
  317. docker:
  318. runs-on: ubuntu-20.04
  319. needs: prepare
  320. strategy:
  321. fail-fast: false
  322. matrix:
  323. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  324. erl_otp:
  325. - 23.2.7.2-emqx-2
  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. - uses: docker/setup-buildx-action@v1
  334. - uses: docker/setup-qemu-action@v1
  335. with:
  336. image: tonistiigi/binfmt:latest
  337. platforms: all
  338. - name: build emqx docker image
  339. if: github.event_name != 'release'
  340. env:
  341. ERL_OTP: erl${{ matrix.erl_otp }}
  342. PROFILE: ${{ matrix.profile }}
  343. run: |
  344. cd source
  345. PKG_VSN="$(./pkg-vsn.sh)"
  346. docker buildx build --no-cache \
  347. --platform=linux/amd64,linux/arm64 \
  348. --build-arg PKG_VSN=$PKG_VSN \
  349. --build-arg BUILD_FROM=emqx/build-env:$ERL_OTP-alpine \
  350. --build-arg RUN_FROM=alpine:3.14 \
  351. --build-arg EMQX_NAME=$PROFILE \
  352. --tag emqx/$PROFILE:$PKG_VSN \
  353. -f deploy/docker/Dockerfile .
  354. - uses: docker/login-action@v1
  355. if: github.event_name == 'release'
  356. with:
  357. username: ${{ secrets.DOCKER_HUB_USER }}
  358. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  359. - name: build emqx docker image
  360. if: github.event_name == 'release'
  361. env:
  362. ERL_OTP: erl${{ matrix.erl_otp }}
  363. PROFILE: ${{ matrix.profile }}
  364. run: |
  365. cd source
  366. PKG_VSN="$(./pkg-vsn.sh)"
  367. docker buildx build --no-cache \
  368. --platform=linux/amd64,linux/arm64 \
  369. --build-arg PKG_VSN=$PKG_VSN \
  370. --build-arg BUILD_FROM=emqx/build-env:$ERL_OTP-alpine \
  371. --build-arg RUN_FROM=alpine:3.14 \
  372. --build-arg EMQX_NAME=$PROFILE \
  373. --tag emqx/$PROFILE:$PKG_VSN \
  374. -f deploy/docker/Dockerfile \
  375. --push .
  376. delete-artifact:
  377. runs-on: ubuntu-20.04
  378. needs: [prepare, mac, linux, docker]
  379. steps:
  380. - uses: geekyeggo/delete-artifact@v1
  381. with:
  382. name: source
  383. upload:
  384. runs-on: ubuntu-20.04
  385. if: startsWith(github.ref, 'refs/tags/')
  386. needs: [prepare, mac, linux, docker]
  387. strategy:
  388. matrix:
  389. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  390. steps:
  391. - uses: actions/checkout@v2
  392. - name: get_version
  393. run: |
  394. echo 'version<<EOF' >> $GITHUB_ENV
  395. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  396. echo 'EOF' >> $GITHUB_ENV
  397. - uses: actions/download-artifact@v2
  398. with:
  399. name: ${{ matrix.profile }}
  400. path: ./_packages/${{ matrix.profile }}
  401. - name: install dos2unix
  402. run: sudo apt-get update && sudo apt install -y dos2unix
  403. - name: get packages
  404. run: |
  405. set -e -u
  406. cd _packages/${{ matrix.profile }}
  407. for var in $( ls |grep emqx |grep -v sha256); do
  408. dos2unix $var.sha256
  409. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  410. done
  411. cd -
  412. - name: upload aws s3
  413. run: |
  414. set -e -u
  415. if [ "${{ matrix.profile }}" == "emqx" ];then
  416. broker="emqx-ce"
  417. else
  418. broker=${{ matrix.profile }}
  419. fi
  420. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  421. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  422. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  423. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  424. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  425. - uses: Rory-Z/upload-release-asset@v1
  426. if: github.event_name == 'release' && matrix.profile != 'emqx-ee'
  427. with:
  428. repo: emqx
  429. path: "_packages/${{ matrix.profile }}/emqx-*"
  430. token: ${{ github.token }}
  431. - uses: Rory-Z/upload-release-asset@v1
  432. if: github.event_name == 'release' && matrix.profile == 'emqx-ee'
  433. with:
  434. repo: emqx-enterprise
  435. path: "_packages/${{ matrix.profile }}/emqx-*"
  436. token: ${{ github.token }}
  437. - name: update to emqx.io
  438. if: github.event_name == 'release'
  439. run: |
  440. set -e -x -u
  441. curl -w %{http_code} \
  442. --insecure \
  443. -H "Content-Type: application/json" \
  444. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  445. -X POST \
  446. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  447. ${{ secrets.EMQX_IO_RELEASE_API }}
  448. - name: push docker image to docker hub
  449. if: github.event_name == 'release'
  450. run: |
  451. set -e -x -u
  452. sudo make docker-prepare
  453. 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 -
  454. echo ${{ secrets.DOCKER_HUB_TOKEN }} |sudo docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin
  455. sudo TARGET=emqx/${{ matrix.profile }} make docker-push
  456. sudo TARGET=emqx/${{ matrix.profile }} make docker-manifest-list
  457. - name: update repo.emqx.io
  458. if: github.event_name == 'release' && endsWith(github.repository, 'enterprise') && matrix.profile == 'emqx-ee'
  459. run: |
  460. curl --silent --show-error \
  461. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  462. -H "Accept: application/vnd.github.v3+json" \
  463. -X POST \
  464. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ee\": \"true\"}}" \
  465. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  466. - name: update repo.emqx.io
  467. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  468. run: |
  469. curl --silent --show-error \
  470. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  471. -H "Accept: application/vnd.github.v3+json" \
  472. -X POST \
  473. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\", \"emqx_ce\": \"true\"}}" \
  474. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  475. - name: update homebrew packages
  476. if: github.event_name == 'release' && endsWith(github.repository, 'emqx') && matrix.profile == 'emqx'
  477. run: |
  478. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  479. curl --silent --show-error \
  480. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  481. -H "Accept: application/vnd.github.v3+json" \
  482. -X POST \
  483. -d "{\"ref\":\"v1.0.1\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  484. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  485. fi
  486. - uses: geekyeggo/delete-artifact@v1
  487. with:
  488. name: ${{ matrix.profile }}