build_packages.yaml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. name: Cross build packages
  2. concurrency:
  3. group: build-${{ github.event_name }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. branches:
  8. - 'main-v4.**'
  9. schedule:
  10. - cron: '0 */6 * * *'
  11. release:
  12. types:
  13. - published
  14. workflow_dispatch:
  15. jobs:
  16. prepare:
  17. runs-on: ubuntu-20.04
  18. container: emqx/build-env:erl23.2.7.2-emqx-3-ubuntu20.04
  19. outputs:
  20. profiles: ${{ steps.set_profile.outputs.profiles}}
  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. run: |
  30. cd source
  31. if make emqx-ee --dry-run > /dev/null 2>&1; then
  32. echo "::set-output name=profiles::[\"emqx-ee\"]"
  33. else
  34. echo "::set-output name=profiles::[\"emqx\", \"emqx-edge\"]"
  35. fi
  36. - name: get_all_deps
  37. if: endsWith(github.repository, 'emqx')
  38. run: |
  39. make -C source deps-all
  40. zip -ryq source.zip source/* source/.[^.]*
  41. - name: get_all_deps
  42. if: endsWith(github.repository, 'enterprise')
  43. run: |
  44. echo "https://ci%40emqx.io:${{ secrets.CI_GIT_TOKEN }}@github.com" > $HOME/.git-credentials
  45. git config --global credential.helper store
  46. echo "${{ secrets.CI_GIT_TOKEN }}" >> source/scripts/git-token
  47. make -C source deps-all
  48. zip -ryq source.zip source/* source/.[^.]*
  49. - uses: actions/upload-artifact@v2
  50. with:
  51. name: source
  52. path: source.zip
  53. windows:
  54. runs-on: windows-2019
  55. needs: prepare
  56. if: endsWith(github.repository, 'emqx')
  57. strategy:
  58. matrix:
  59. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  60. exclude:
  61. - profile: emqx-edge
  62. steps:
  63. - uses: actions/download-artifact@v2
  64. with:
  65. name: source
  66. path: .
  67. - name: unzip source code
  68. run: Expand-Archive -Path source.zip -DestinationPath ./
  69. - uses: ilammy/msvc-dev-cmd@v1
  70. - uses: gleam-lang/setup-erlang@v1.1.0
  71. id: install_erlang
  72. with:
  73. otp-version: 23.2
  74. - name: build
  75. env:
  76. PYTHON: python
  77. DIAGNOSTIC: 1
  78. run: |
  79. $env:PATH = "${{ steps.install_erlang.outputs.erlpath }}\bin;$env:PATH"
  80. erl -eval "erlang:display(crypto:info_lib())" -s init stop
  81. $version = $( "${{ github.ref }}" -replace "^(.*)/(.*)/" )
  82. if ($version -match "^v[0-9]+\.[0-9]+(\.[0-9]+)?") {
  83. $regex = "[0-9]+\.[0-9]+(-alpha|-beta|-rc)?\.[0-9]+"
  84. $pkg_name = "${{ matrix.profile }}-windows-$([regex]::matches($version, $regex).value).zip"
  85. }
  86. else {
  87. $pkg_name = "${{ matrix.profile }}-windows-$($version -replace '/').zip"
  88. }
  89. cd source
  90. ## We do not build/release bcrypt for windows package
  91. Remove-Item -Recurse -Force -Path _build/default/lib/bcrypt/
  92. if (Test-Path rebar.lock) {
  93. Remove-Item -Force -Path rebar.lock
  94. }
  95. make ensure-rebar3
  96. copy rebar3 "${{ steps.install_erlang.outputs.erlpath }}\bin"
  97. ls "${{ steps.install_erlang.outputs.erlpath }}\bin"
  98. rebar3 --help
  99. make ${{ matrix.profile }}
  100. mkdir -p _packages/${{ matrix.profile }}
  101. Compress-Archive -Path _build/${{ matrix.profile }}/rel/emqx -DestinationPath _build/${{ matrix.profile }}/rel/$pkg_name
  102. mv _build/${{ matrix.profile }}/rel/$pkg_name _packages/${{ matrix.profile }}
  103. sha256sum "_packages/${{ matrix.profile }}/$pkg_name" | head -c 64 > "_packages/${{ matrix.profile }}/${pkg_name}.sha256"
  104. - name: run emqx
  105. timeout-minutes: 1
  106. run: |
  107. cd source
  108. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  109. Start-Sleep -s 5
  110. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  111. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  112. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  113. - uses: actions/upload-artifact@v1
  114. if: startsWith(github.ref, 'refs/tags/')
  115. with:
  116. name: ${{ matrix.profile }}
  117. path: source/_packages/${{ matrix.profile }}/.
  118. mac:
  119. needs: prepare
  120. strategy:
  121. matrix:
  122. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  123. erl_otp:
  124. - 23.2.7.2-emqx-3
  125. exclude:
  126. - profile: emqx-edge
  127. macos:
  128. - macos-10.15
  129. runs-on: ${{ matrix.macos }}
  130. steps:
  131. - uses: actions/download-artifact@v2
  132. with:
  133. name: source
  134. path: .
  135. - name: unzip source code
  136. run: unzip -q source.zip
  137. - name: prepare
  138. run: |
  139. brew update
  140. brew install curl zip unzip gnu-sed kerl unixodbc freetds
  141. echo "/usr/local/bin" >> $GITHUB_PATH
  142. git config --global credential.helper store
  143. - uses: actions/cache@v2
  144. id: cache
  145. with:
  146. path: ~/.kerl/${{ matrix.erl_otp }}
  147. key: otp-install-${{ matrix.erl_otp }}-${{ matrix.macos }}
  148. - name: build erlang
  149. if: steps.cache.outputs.cache-hit != 'true'
  150. timeout-minutes: 60
  151. env:
  152. KERL_BUILD_BACKEND: git
  153. OTP_GITHUB_URL: https://github.com/emqx/otp
  154. run: |
  155. kerl update releases
  156. kerl build ${{ matrix.erl_otp }}
  157. kerl install ${{ matrix.erl_otp }} $HOME/.kerl/${{ matrix.erl_otp }}
  158. - name: build
  159. run: |
  160. . $HOME/.kerl/${{ matrix.erl_otp }}/activate
  161. cd source
  162. make ensure-rebar3
  163. sudo cp rebar3 /usr/local/bin/rebar3
  164. rm -rf _build/${{ matrix.profile }}/lib
  165. make ${{ matrix.profile }}-zip
  166. - name: test
  167. run: |
  168. cd source
  169. pkg_name=$(basename _packages/${{ matrix.profile }}/${{ matrix.profile }}-*.zip)
  170. unzip -q _packages/${{ matrix.profile }}/$pkg_name
  171. gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  172. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  173. ready='no'
  174. for i in {1..10}; do
  175. if curl -fs 127.0.0.1:18083 > /dev/null; then
  176. ready='yes'
  177. break
  178. fi
  179. sleep 1
  180. done
  181. if [ "$ready" != "yes" ]; then
  182. echo "Timed out waiting for emqx to be ready"
  183. cat emqx/log/erlang.log.1
  184. exit 1
  185. fi
  186. ./emqx/bin/emqx_ctl status
  187. if ! ./emqx/bin/emqx stop; then
  188. cat emqx/log/erlang.log.1 || true
  189. cat emqx/log/emqx.log.1 || true
  190. echo "failed to stop emqx"
  191. exit 1
  192. fi
  193. rm -rf emqx
  194. #sha256sum ./_packages/${{ matrix.profile }}/$pkg_name | head -c64 > ./_packages/${{ matrix.profile }}/$pkg_name.sha256
  195. openssl dgst -sha256 ./_packages/${{ matrix.profile }}/$pkg_name | awk '{print $2}' > ./_packages/${{ matrix.profile }}/$pkg_name.sha256
  196. - uses: actions/upload-artifact@v1
  197. if: startsWith(github.ref, 'refs/tags/')
  198. with:
  199. name: ${{ matrix.profile }}
  200. path: source/_packages/${{ matrix.profile }}/.
  201. linux:
  202. runs-on: ubuntu-20.04
  203. needs: prepare
  204. strategy:
  205. fail-fast: false
  206. matrix:
  207. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  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. - name: prepare docker
  243. run: |
  244. mkdir -p $HOME/.docker
  245. echo '{ "experimental": "enabled" }' | tee $HOME/.docker/config.json
  246. echo '{ "experimental": true, "storage-driver": "overlay2", "max-concurrent-downloads": 50, "max-concurrent-uploads": 50}' | sudo tee /etc/docker/daemon.json
  247. sudo systemctl restart docker
  248. docker info
  249. docker buildx create --use --name mybuild
  250. docker run --rm --privileged tonistiigi/binfmt --install all
  251. - uses: actions/download-artifact@v2
  252. with:
  253. name: source
  254. path: .
  255. - name: unzip source code
  256. run: unzip -q source.zip
  257. - name: build emqx packages
  258. env:
  259. ERL_OTP: erl23.2.7.2-emqx-3
  260. PROFILE: ${{ matrix.profile }}
  261. ARCH: ${{ matrix.arch }}
  262. SYSTEM: ${{ matrix.os }}
  263. run: |
  264. set -e -u
  265. cd source
  266. docker buildx build --no-cache \
  267. --platform=linux/$ARCH \
  268. -t cross_build_emqx_for_$SYSTEM \
  269. -f .ci/build_packages/Dockerfile \
  270. --build-arg BUILD_FROM=emqx/build-env:$ERL_OTP-$SYSTEM \
  271. --build-arg EMQX_NAME=$PROFILE \
  272. --output type=tar,dest=/tmp/cross-build-$PROFILE-for-$SYSTEM.tar .
  273. mkdir -p /tmp/packages/$PROFILE
  274. tar -xvf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar --wildcards emqx/_packages/$PROFILE/*
  275. mv emqx/_packages/$PROFILE/* /tmp/packages/$PROFILE/
  276. rm -rf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar
  277. docker rm -f $(docker ps -a -q)
  278. docker volume prune -f
  279. - name: create sha256
  280. env:
  281. PROFILE: ${{ matrix.profile}}
  282. run: |
  283. if [ -d /tmp/packages/$PROFILE ]; then
  284. cd /tmp/packages/$PROFILE
  285. for var in $(ls emqx-* ); do
  286. bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  287. done
  288. cd -
  289. fi
  290. - uses: actions/upload-artifact@v1
  291. if: startsWith(github.ref, 'refs/tags/')
  292. with:
  293. name: ${{ matrix.profile }}
  294. path: /tmp/packages/${{ matrix.profile }}/.
  295. docker:
  296. runs-on: ubuntu-20.04
  297. needs: prepare
  298. strategy:
  299. fail-fast: false
  300. matrix:
  301. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  302. registry:
  303. - 'docker.io'
  304. - 'public.ecr.aws'
  305. exclude:
  306. # we don't have an aws ecr repo for enterprise and edge yet
  307. - profile: emqx-edge
  308. registry: 'public.ecr.aws'
  309. - profile: emqx-ee
  310. registry: 'public.ecr.aws'
  311. steps:
  312. - uses: actions/download-artifact@v2
  313. with:
  314. name: source
  315. path: .
  316. - name: unzip source code
  317. run: unzip -q source.zip
  318. - uses: docker/setup-buildx-action@v1
  319. - uses: docker/setup-qemu-action@v1
  320. with:
  321. image: tonistiigi/binfmt:latest
  322. platforms: all
  323. - uses: aws-actions/configure-aws-credentials@v1
  324. if: matrix.registry == 'public.ecr.aws'
  325. with:
  326. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  327. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  328. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  329. - name: Docker login to aws ecr
  330. if: matrix.registry == 'public.ecr.aws'
  331. run: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
  332. - uses: docker/login-action@v1
  333. if: matrix.registry == 'docker.io'
  334. with:
  335. username: ${{ secrets.DOCKER_HUB_USER }}
  336. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  337. - uses: docker/metadata-action@v3
  338. id: meta
  339. with:
  340. images: ${{ matrix.registry }}/${{ github.repository_owner }}/${{ matrix.profile }}
  341. flavor: |
  342. latest=${{ !github.event.release.prerelease }}
  343. tags: |
  344. type=ref,event=branch
  345. type=ref,event=pr
  346. type=match,pattern=[v|e](.*),group=1
  347. labels:
  348. org.opencontainers.image.otp.version=${{ matrix.otp }}
  349. - uses: docker/build-push-action@v2
  350. if: matrix.profile != 'emqx-ee'
  351. with:
  352. push: ${{ github.event_name == 'release' && !github.event.release.prerelease }}
  353. pull: true
  354. no-cache: true
  355. platforms: linux/amd64,linux/arm64
  356. tags: ${{ steps.meta.outputs.tags }}
  357. labels: ${{ steps.meta.outputs.labels }}
  358. build-args: |
  359. BUILD_FROM=emqx/build-env:erl23.2.7.2-emqx-3-alpine
  360. RUN_FROM=alpine:3.12
  361. EMQX_NAME=${{ matrix.profile }}
  362. file: source/deploy/docker/Dockerfile
  363. context: source
  364. - uses: docker/build-push-action@v2
  365. if: matrix.profile == 'emqx-ee'
  366. with:
  367. push: ${{ github.event_name == 'release' && !github.event.release.prerelease }}
  368. pull: true
  369. no-cache: true
  370. platforms: linux/amd64,linux/arm64
  371. tags: ${{ steps.meta.outputs.tags }}
  372. labels: ${{ steps.meta.outputs.labels }}
  373. build-args: |
  374. BUILD_FROM=emqx/build-env:erl23.2.7.2-emqx-3-alpine
  375. RUN_FROM=alpine:3.12
  376. EMQX_NAME=${{ matrix.profile }}
  377. file: source/deploy/docker/Dockerfile.enterprise
  378. context: source
  379. delete-artifact:
  380. runs-on: ubuntu-20.04
  381. needs: [prepare, mac, linux, docker]
  382. steps:
  383. - uses: geekyeggo/delete-artifact@v1
  384. with:
  385. name: source
  386. upload:
  387. runs-on: ubuntu-20.04
  388. if: startsWith(github.ref, 'refs/tags/')
  389. needs: [prepare, mac, linux, docker]
  390. strategy:
  391. fail-fast: false
  392. matrix:
  393. profile: ${{fromJSON(needs.prepare.outputs.profiles)}}
  394. steps:
  395. - uses: actions/checkout@v2
  396. - name: get_version
  397. run: |
  398. echo 'version<<EOF' >> $GITHUB_ENV
  399. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  400. echo 'EOF' >> $GITHUB_ENV
  401. - uses: actions/download-artifact@v2
  402. with:
  403. name: ${{ matrix.profile }}
  404. path: ./_packages/${{ matrix.profile }}
  405. - name: install dos2unix
  406. run: sudo apt-get update && sudo apt install -y dos2unix
  407. - name: get packages
  408. run: |
  409. set -e -u
  410. cd _packages/${{ matrix.profile }}
  411. for var in $( ls |grep emqx |grep -v sha256); do
  412. dos2unix $var.sha256
  413. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  414. done
  415. cd -
  416. - name: upload aws s3
  417. run: |
  418. set -e -u
  419. if [ "${{ matrix.profile }}" == "emqx" ];then
  420. broker="emqx-ce"
  421. else
  422. broker=${{ matrix.profile }}
  423. fi
  424. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  425. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  426. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  427. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$broker/${{ env.version }}
  428. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$broker/${{ env.version }}/*"
  429. - uses: Rory-Z/upload-release-asset@v1
  430. if: github.event_name == 'release' && matrix.profile != 'emqx-ee'
  431. with:
  432. repo: emqx
  433. path: "_packages/${{ matrix.profile }}/emqx-*"
  434. token: ${{ github.token }}
  435. - uses: Rory-Z/upload-release-asset@v1
  436. if: github.event_name == 'release' && matrix.profile == 'emqx-ee'
  437. with:
  438. repo: emqx-enterprise
  439. path: "_packages/${{ matrix.profile }}/emqx-*"
  440. token: ${{ github.token }}
  441. - name: update to emqx.io
  442. if: github.event_name == 'release'
  443. run: |
  444. set -e -x -u
  445. curl -w %{http_code} \
  446. --insecure \
  447. -H "Content-Type: application/json" \
  448. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  449. -X POST \
  450. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  451. ${{ secrets.EMQX_IO_RELEASE_API }}
  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.3\",\"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.3\",\"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.3\",\"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 }}