build_packages.yaml 18 KB

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