build_packages.yaml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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-3:24.1.5-3-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. ## gleam-lang/setup-erlang does not yet support the installation of otp24 on windows
  55. - 23.2
  56. steps:
  57. - uses: actions/download-artifact@v2
  58. with:
  59. name: source
  60. path: .
  61. - name: unzip source code
  62. run: Expand-Archive -Path source.zip -DestinationPath ./
  63. - uses: ilammy/msvc-dev-cmd@v1
  64. - uses: gleam-lang/setup-erlang@v1.1.2
  65. id: install_erlang
  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.tar.gz"
  79. }
  80. else {
  81. $pkg_name = "${{ matrix.profile }}-$($version -replace '/')-otp${{ matrix.otp }}-windows-amd64.tar.gz"
  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-3
  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/${{ matrix.otp }}
  145. key: otp-install-${{ 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: Get deps git refs for cache
  157. id: deps-refs
  158. run: |
  159. cd source
  160. . $HOME/.kerl/${{ matrix.otp }}/activate
  161. make ensure-rebar3
  162. sudo cp rebar3 /usr/local/bin/rebar3
  163. scripts/get-dep-refs.sh
  164. make clean-all
  165. - name: load rocksdb cache
  166. uses: actions/cache@v2
  167. with:
  168. path: source/_build/default/lib/rocksdb/
  169. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_ROCKSDB_REF }}
  170. - name: load quicer cache
  171. uses: actions/cache@v2
  172. with:
  173. path: source/_build/default/lib/quicer/
  174. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_QUICER_REF }}
  175. - name: build
  176. working-directory: source
  177. run: |
  178. . $HOME/.kerl/${{ matrix.otp }}/activate
  179. make ensure-rebar3
  180. sudo cp rebar3 /usr/local/bin/rebar3
  181. rm -rf _build/${{ matrix.profile }}/lib
  182. make ${{ matrix.profile }}-tgz
  183. - name: test
  184. working-directory: source
  185. run: |
  186. pkg_name=$(find _packages/${{ matrix.profile }} -mindepth 1 -maxdepth 1 -iname \*.tar.gz)
  187. tar -zxf $pkg_name
  188. # gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  189. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  190. ready='no'
  191. for i in {1..10}; do
  192. if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then
  193. ready='yes'
  194. break
  195. fi
  196. sleep 1
  197. done
  198. if [ "$ready" != "yes" ]; then
  199. echo "Timed out waiting for emqx to be ready"
  200. cat emqx/log/erlang.log.1
  201. exit 1
  202. fi
  203. ./emqx/bin/emqx_ctl status
  204. ./emqx/bin/emqx stop
  205. rm -rf emqx
  206. openssl dgst -sha256 $pkg_name | awk '{print $2}' > $pkg_name.sha256
  207. - uses: actions/upload-artifact@v1
  208. if: startsWith(github.ref, 'refs/tags/')
  209. with:
  210. name: ${{ matrix.profile }}-${{ matrix.otp }}
  211. path: source/_packages/${{ matrix.profile }}/.
  212. linux:
  213. runs-on: ubuntu-20.04
  214. needs: prepare
  215. strategy:
  216. fail-fast: false
  217. matrix:
  218. profile: ## all editions for linux
  219. - emqx-edge
  220. - emqx
  221. - emqx-enterprise
  222. otp:
  223. - 24.1.5-3 # we test with OTP 23, but only build package on OTP 24 versions
  224. arch:
  225. - amd64
  226. - arm64
  227. os:
  228. - ubuntu20.04
  229. - ubuntu18.04
  230. - ubuntu16.04
  231. - debian10
  232. - debian9
  233. # - opensuse
  234. - centos8
  235. - centos7
  236. - raspbian10
  237. # - raspbian9
  238. exclude:
  239. - os: raspbian9
  240. arch: amd64
  241. - os: raspbian10
  242. arch: amd64
  243. - os: raspbian9
  244. profile: emqx
  245. - os: raspbian10
  246. profile: emqx
  247. - os: raspbian9
  248. profile: emqx-enterprise
  249. - os: raspbian10
  250. profile: emqx-enterprise
  251. defaults:
  252. run:
  253. shell: bash
  254. steps:
  255. - uses: docker/setup-buildx-action@v1
  256. - uses: docker/setup-qemu-action@v1
  257. with:
  258. image: tonistiigi/binfmt:latest
  259. platforms: all
  260. - uses: actions/download-artifact@v2
  261. with:
  262. name: source
  263. path: .
  264. - name: unzip source code
  265. run: unzip -q source.zip
  266. - name: Get deps git refs for cache
  267. id: deps-refs
  268. run: |
  269. cd source
  270. scripts/get-dep-refs.sh
  271. make clean-all
  272. - name: load rocksdb cache
  273. uses: actions/cache@v2
  274. with:
  275. path: source/_build/default/lib/rocksdb/
  276. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_ROCKSDB_REF }}
  277. - name: load quicer cache
  278. uses: actions/cache@v2
  279. with:
  280. path: source/_build/default/lib/quicer/
  281. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ steps.deps-refs.outputs.DEP_QUICER_REF }}
  282. - name: download old emqx tgz packages
  283. env:
  284. OTP_VSN: ${{ matrix.otp }}
  285. PROFILE: ${{ matrix.profile }}
  286. ARCH: ${{ matrix.arch }}
  287. SYSTEM: ${{ matrix.os }}
  288. OLD_VSNS: ${{ needs.prepare.outputs.old_vsns }}
  289. working-directory: source
  290. run: |
  291. set -e -x -u
  292. if [ $PROFILE = 'emqx' ]; then
  293. s3dir='emqx-ce'
  294. elif [ $PROFILE = 'emqx-enterprise' ]; then
  295. s3dir='emqx-ee'
  296. elif [ $PROFILE = 'emqx-edge' ]; then
  297. s3dir='emqx-edge'
  298. else
  299. echo "unknown profile $PROFILE"
  300. exit 1
  301. fi
  302. mkdir -p _upgrade_base
  303. cd _upgrade_base
  304. old_vsns=($(echo $OLD_VSNS | tr ' ' ' '))
  305. for tag in ${old_vsns[@]}; do
  306. package_name="${PROFILE}-${tag#[e|v]}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
  307. if [ ! -z "$(echo $(curl -I -m 10 -o /dev/null -s -w %{http_code} https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz) | grep -oE "^[23]+")" ]; then
  308. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz
  309. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz.sha256
  310. echo "$(cat $package_name.tar.gz.sha256) $package_name.tar.gz" | sha256sum -c || exit 1
  311. fi
  312. done
  313. - name: build emqx packages
  314. env:
  315. OTP: ${{ matrix.otp }}
  316. PROFILE: ${{ matrix.profile }}
  317. ARCH: ${{ matrix.arch }}
  318. SYSTEM: ${{ matrix.os }}
  319. working-directory: source
  320. run: |
  321. ./scripts/buildx.sh \
  322. --profile "${PROFILE}" \
  323. --pkgtype "tgz" \
  324. --arch "${ARCH}" \
  325. --builder "ghcr.io/emqx/emqx-builder/5.0-3:${OTP}-${SYSTEM}"
  326. ## the pkg build is incremental on the tgz build
  327. ./scripts/buildx.sh \
  328. --profile "${PROFILE}" \
  329. --pkgtype "pkg" \
  330. --arch "${ARCH}" \
  331. --builder "ghcr.io/emqx/emqx-builder/5.0-3:${OTP}-${SYSTEM}"
  332. - name: create sha256
  333. env:
  334. PROFILE: ${{ matrix.profile}}
  335. working-directory: source
  336. run: |
  337. if [ -d _packages/$PROFILE ]; then
  338. cd _packages/$PROFILE
  339. for var in $(ls emqx-* ); do
  340. sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  341. done
  342. cd -
  343. fi
  344. - uses: actions/upload-artifact@v1
  345. if: startsWith(github.ref, 'refs/tags/')
  346. with:
  347. name: ${{ matrix.profile }}-${{ matrix.otp }}
  348. path: source/_packages/${{ matrix.profile }}/.
  349. docker:
  350. runs-on: ubuntu-20.04
  351. needs: prepare
  352. strategy:
  353. fail-fast: false
  354. matrix:
  355. profile: # all editions for docker
  356. - emqx-edge
  357. - emqx
  358. - emqx-enterprise
  359. # NOTE: for docker, only support latest otp version, not a matrix
  360. otp:
  361. - 24.1.5-3 # update to latest
  362. steps:
  363. - uses: actions/download-artifact@v2
  364. with:
  365. name: source
  366. path: .
  367. - name: unzip source code
  368. run: unzip -q source.zip
  369. - uses: docker/setup-buildx-action@v1
  370. - uses: docker/setup-qemu-action@v1
  371. with:
  372. image: tonistiigi/binfmt:latest
  373. platforms: all
  374. - uses: docker/metadata-action@v3
  375. id: meta
  376. with:
  377. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  378. flavor: |
  379. latest=${{ !github.event.release.prerelease }}
  380. tags: |
  381. type=ref,event=branch
  382. type=ref,event=pr
  383. type=ref,event=tag
  384. type=semver,pattern={{version}}
  385. labels:
  386. org.opencontainers.image.otp.version=${{ matrix.otp }}
  387. - uses: docker/login-action@v1
  388. if: github.event_name == 'release'
  389. with:
  390. username: ${{ secrets.DOCKER_HUB_USER }}
  391. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  392. - uses: docker/build-push-action@v2
  393. with:
  394. push: ${{ github.event_name == 'release' && !github.event.release.prerelease }}
  395. pull: true
  396. no-cache: true
  397. platforms: linux/amd64,linux/arm64
  398. tags: ${{ steps.meta.outputs.tags }}
  399. labels: ${{ steps.meta.outputs.labels }}
  400. build-args: |
  401. BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-3:${{ matrix.otp }}-alpine3.14
  402. RUN_FROM=alpine:3.14
  403. EMQX_NAME=${{ matrix.profile }}
  404. file: source/deploy/docker/Dockerfile
  405. context: source
  406. - uses: aws-actions/configure-aws-credentials@v1
  407. if: github.event_name == 'release' && !github.event.release.prerelease && matrix.profile == 'emqx'
  408. with:
  409. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  410. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  411. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  412. - name: Push image to aws ecr
  413. if: github.event_name == 'release' && !github.event.release.prerelease && matrix.profile == 'emqx'
  414. run: |
  415. version=${GITHUB_REF##*/}
  416. docker pull emqx/emqx:${version#v}
  417. docker tag emqx/emqx:${version#v} public.ecr.aws/emqx/emqx:${version#v}
  418. aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
  419. docker push public.ecr.aws/emqx/emqx:${version#v}
  420. delete-artifact:
  421. runs-on: ubuntu-20.04
  422. needs: [prepare, mac, linux, docker]
  423. steps:
  424. - uses: geekyeggo/delete-artifact@v1
  425. with:
  426. name: source
  427. upload:
  428. runs-on: ubuntu-20.04
  429. if: startsWith(github.ref, 'refs/tags/')
  430. needs: [prepare, mac, linux, docker]
  431. strategy:
  432. matrix:
  433. profile:
  434. - emqx-edge
  435. - emqx
  436. - emqx-enterprise
  437. otp:
  438. - 24.1.5-3
  439. steps:
  440. - uses: actions/checkout@v2
  441. - name: get_version
  442. run: |
  443. echo 'version<<EOF' >> $GITHUB_ENV
  444. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  445. echo 'EOF' >> $GITHUB_ENV
  446. - uses: actions/download-artifact@v2
  447. with:
  448. name: ${{ matrix.profile }}-${{ matrix.otp }}
  449. path: ./_packages/${{ matrix.profile }}
  450. - name: install dos2unix
  451. run: sudo apt-get update && sudo apt install -y dos2unix
  452. - name: get packages
  453. run: |
  454. set -e -u
  455. cd _packages/${{ matrix.profile }}
  456. for var in $( ls |grep emqx |grep -v sha256); do
  457. dos2unix $var.sha256
  458. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  459. done
  460. cd -
  461. - name: upload aws s3
  462. run: |
  463. set -e -u
  464. PROFILE=${{ matrix.profile }}
  465. if [ $PROFILE = 'emqx' ]; then
  466. s3dir='emqx-ce'
  467. elif [ $PROFILE = 'emqx-enterprise' ]; then
  468. s3dir='emqx-ee'
  469. elif [ $PROFILE = 'emqx-edge' ]; then
  470. s3dir='emqx-edge'
  471. else
  472. echo "unknown profile $PROFILE"
  473. exit 1
  474. fi
  475. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  476. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  477. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  478. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ env.version }}
  479. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ env.version }}/*"
  480. - uses: Rory-Z/upload-release-asset@v1
  481. if: github.event_name == 'release'
  482. with:
  483. repo: emqx
  484. path: "_packages/${{ matrix.profile }}/emqx-*"
  485. token: ${{ github.token }}
  486. - name: update to emqx.io
  487. if: github.event_name == 'release'
  488. run: |
  489. set -e -x -u
  490. curl -w %{http_code} \
  491. --insecure \
  492. -H "Content-Type: application/json" \
  493. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  494. -X POST \
  495. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  496. ${{ secrets.EMQX_IO_RELEASE_API }}
  497. - name: update repo.emqx.io
  498. if: github.event_name == 'release'
  499. run: |
  500. if [ "${{ matrix.profile }}" = 'emqx-enterprise' ]; then
  501. BOOL_FLAG_NAME="emqx_ee"
  502. else
  503. BOOL_FLAG_NAME="emqx_ce"
  504. fi
  505. curl --silent --show-error \
  506. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  507. -H "Accept: application/vnd.github.v3+json" \
  508. -X POST \
  509. -d "{\"ref\":\"v1.0.4\",\"inputs\":{\"version\": \"${{ env.version }}\", \"${BOOL_FLAG_NAME}\": \"true\"}}" \
  510. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  511. - name: update homebrew packages
  512. if: github.event_name == 'release' && matrix.profile == 'emqx'
  513. run: |
  514. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  515. curl --silent --show-error \
  516. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  517. -H "Accept: application/vnd.github.v3+json" \
  518. -X POST \
  519. -d "{\"ref\":\"v1.0.4\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  520. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  521. fi
  522. - uses: geekyeggo/delete-artifact@v1
  523. with:
  524. name: ${{ matrix.profile }}