build_packages.yaml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. push:
  9. branches:
  10. - 'ci/**'
  11. release:
  12. types:
  13. - published
  14. workflow_dispatch:
  15. inputs:
  16. which_branch:
  17. required: false
  18. jobs:
  19. prepare:
  20. runs-on: ubuntu-20.04
  21. # prepare source with any OTP version, no need for a matrix
  22. container: "ghcr.io/emqx/emqx-builder/5.0-5:1.13.2-24.1.5-4-ubuntu20.04"
  23. outputs:
  24. ce_old_vsns: ${{ steps.find_old_versons.outputs.ce_old_vsns }}
  25. ee_old_vsns: ${{ steps.find_old_versons.outputs.ee_old_vsns }}
  26. DEP_ROCKSDB_REF: ${{ steps.deps-refs.outputs.DEP_ROCKSDB_REF }}
  27. DEP_QUICER_REF: ${{ steps.deps-refs.outputs.DEP_QUICER_REF }}
  28. steps:
  29. - uses: actions/checkout@v2
  30. with:
  31. ref: ${{ github.event.inputs.which_branch }}
  32. path: source
  33. fetch-depth: 0
  34. - name: Get deps git refs for cache
  35. id: deps-refs
  36. working-directory: source
  37. run: |
  38. bash -x scripts/get-dep-refs.sh
  39. make clean-all
  40. - name: find old versions
  41. id: find_old_versons
  42. shell: bash
  43. working-directory: source
  44. run: |
  45. ce_old_vsns="$(./scripts/relup-base-vsns.sh community | xargs)"
  46. ee_old_vsns="$(./scripts/relup-base-vsns.sh enterprise | xargs)"
  47. echo "::set-output name=ce_old_vsns::${ce_old_vsns}"
  48. echo "::set-output name=ee_old_vsns::${ee_old_vsns}"
  49. - name: get_all_deps
  50. run: |
  51. make -C source deps-all
  52. zip -ryq source.zip source/* source/.[^.]*
  53. - uses: actions/upload-artifact@v2
  54. with:
  55. name: source
  56. path: source.zip
  57. windows:
  58. runs-on: windows-2019
  59. needs: prepare
  60. strategy:
  61. fail-fast: false
  62. matrix:
  63. profile: # only CE for windows
  64. - emqx
  65. otp:
  66. ## gleam-lang/setup-erlang does not yet support the installation of otp24 on windows
  67. - 23.2
  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.2
  77. id: install_erlang
  78. with:
  79. otp-version: ${{ matrix.otp }}
  80. - name: build
  81. env:
  82. PYTHON: python
  83. DIAGNOSTIC: 1
  84. working-directory: source
  85. run: |
  86. $env:PATH = "${{ steps.install_erlang.outputs.erlpath }}\bin;$env:PATH"
  87. $version = $( "${{ github.ref }}" -replace "^(.*)/(.*)/" )
  88. if ($version -match "^v[0-9]+\.[0-9]+(\.[0-9]+)?") {
  89. $regex = "[0-9]+\.[0-9]+(-alpha|-beta|-rc)?\.[0-9]+"
  90. $pkg_name = "${{ matrix.profile }}-$([regex]::matches($version, $regex).value)-otp${{ matrix.otp }}-windows-amd64.tar.gz"
  91. }
  92. else {
  93. $pkg_name = "${{ matrix.profile }}-$($version -replace '/')-otp${{ matrix.otp }}-windows-amd64.tar.gz"
  94. }
  95. ## We do not build/release bcrypt and quic for windows package
  96. Remove-Item -Recurse -Force -Path _build/default/lib/bcrypt/
  97. Remove-Item -Recurse -Force -Path _build/default/lib/quicer/
  98. if (Test-Path rebar.lock) {
  99. Remove-Item -Force -Path rebar.lock
  100. }
  101. make ensure-rebar3
  102. copy rebar3 "${{ steps.install_erlang.outputs.erlpath }}\bin"
  103. ls "${{ steps.install_erlang.outputs.erlpath }}\bin"
  104. rebar3 --help
  105. make ${{ matrix.profile }}
  106. mkdir -p _packages/${{ matrix.profile }}
  107. Compress-Archive -Path _build/${{ matrix.profile }}/rel/emqx -DestinationPath _build/${{ matrix.profile }}/rel/$pkg_name
  108. mv _build/${{ matrix.profile }}/rel/$pkg_name _packages/${{ matrix.profile }}
  109. Get-FileHash -Path "_packages/${{ matrix.profile }}/$pkg_name" | Format-List | grep 'Hash' | awk '{print $3}' > _packages/${{ matrix.profile }}/$pkg_name.sha256
  110. - name: run emqx
  111. timeout-minutes: 1
  112. working-directory: source
  113. run: |
  114. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  115. Start-Sleep -s 5
  116. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  117. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  118. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  119. - uses: actions/upload-artifact@v1
  120. if: startsWith(github.ref, 'refs/tags/')
  121. with:
  122. name: ${{ matrix.profile }}
  123. path: source/_packages/${{ matrix.profile }}/.
  124. mac:
  125. needs: prepare
  126. strategy:
  127. fail-fast: false
  128. matrix:
  129. profile: # no EDGE for mac
  130. - emqx
  131. - emqx-enterprise
  132. otp:
  133. - 24.1.5-4
  134. os:
  135. - macos-11
  136. - macos-10.15
  137. exclude:
  138. - profile: emqx-edge
  139. runs-on: ${{ matrix.os }}
  140. steps:
  141. - uses: actions/download-artifact@v2
  142. with:
  143. name: source
  144. path: .
  145. - name: unzip source code
  146. run: unzip -q source.zip
  147. - name: prepare
  148. run: |
  149. brew update
  150. brew install curl zip unzip gnu-sed kerl unixodbc freetds
  151. echo "/usr/local/bin" >> $GITHUB_PATH
  152. git config --global credential.helper store
  153. - uses: actions/cache@v2
  154. id: cache
  155. with:
  156. path: ~/.kerl/${{ matrix.otp }}
  157. key: otp-install-${{ matrix.otp }}-${{ matrix.os }}
  158. - name: build erlang
  159. if: steps.cache.outputs.cache-hit != 'true'
  160. timeout-minutes: 60
  161. env:
  162. KERL_BUILD_BACKEND: git
  163. OTP_GITHUB_URL: https://github.com/emqx/otp
  164. run: |
  165. kerl update releases
  166. kerl build ${{ matrix.otp }}
  167. kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
  168. - name: load rocksdb cache
  169. uses: actions/cache@v2
  170. with:
  171. path: source/_build/default/lib/rocksdb/
  172. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_ROCKSDB_REF }}
  173. - name: load quicer cache
  174. uses: actions/cache@v2
  175. with:
  176. path: source/_build/default/lib/quicer/
  177. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_QUICER_REF }}
  178. - name: build
  179. working-directory: source
  180. run: |
  181. . $HOME/.kerl/${{ matrix.otp }}/activate
  182. make ensure-rebar3
  183. sudo cp rebar3 /usr/local/bin/rebar3
  184. rm -rf _build/${{ matrix.profile }}/lib
  185. make ${{ matrix.profile }}-tgz
  186. - name: test
  187. working-directory: source
  188. run: |
  189. pkg_name=$(find _packages/${{ matrix.profile }} -mindepth 1 -maxdepth 1 -iname \*.tar.gz)
  190. tar -zxf $pkg_name
  191. # gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  192. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  193. ready='no'
  194. for i in {1..10}; do
  195. if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then
  196. ready='yes'
  197. break
  198. fi
  199. sleep 1
  200. done
  201. if [ "$ready" != "yes" ]; then
  202. echo "Timed out waiting for emqx to be ready"
  203. cat emqx/log/erlang.log.1
  204. exit 1
  205. fi
  206. ./emqx/bin/emqx_ctl status
  207. ./emqx/bin/emqx stop
  208. rm -rf emqx
  209. openssl dgst -sha256 $pkg_name | awk '{print $2}' > $pkg_name.sha256
  210. - uses: actions/upload-artifact@v1
  211. if: startsWith(github.ref, 'refs/tags/')
  212. with:
  213. name: ${{ matrix.profile }}-${{ matrix.otp }}
  214. path: source/_packages/${{ matrix.profile }}/.
  215. linux:
  216. needs: prepare
  217. runs-on: ${{ matrix.build_machine }}
  218. container:
  219. image: "ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
  220. strategy:
  221. fail-fast: false
  222. matrix:
  223. profile: ## all editions for linux
  224. - emqx-edge
  225. - emqx
  226. - emqx-enterprise
  227. otp:
  228. - 24.1.5-4 # we test with OTP 23, but only build package on OTP 24 versions
  229. elixir:
  230. - 1.13.2
  231. # used to split elixir packages into a separate job, since the
  232. # entire job may take a lot of time, especially on arm64
  233. # emulation.
  234. # we only want to build ubuntu and centos with elixir for the
  235. # time being, so it's easier to just include those with
  236. # `with_elixir` set.
  237. build_elixir:
  238. # - with_elixir
  239. - no_elixir
  240. arch:
  241. - amd64
  242. - arm64
  243. os:
  244. - ubuntu20.04
  245. - ubuntu18.04
  246. - ubuntu16.04
  247. - debian10
  248. - debian9
  249. # - opensuse
  250. - centos7
  251. - raspbian10
  252. # - raspbian9
  253. build_machine:
  254. - aws-arm64
  255. - ubuntu-20.04
  256. exclude:
  257. - arch: arm64
  258. build_machine: ubuntu-20.04
  259. - arch: amd64
  260. build_machine: aws-arm64
  261. - os: raspbian9
  262. arch: amd64
  263. - os: raspbian10
  264. arch: amd64
  265. - os: raspbian10 # we only have arm32 image
  266. arch: arm64
  267. - os: raspbian9
  268. profile: emqx
  269. - os: raspbian10
  270. profile: emqx
  271. - os: raspbian9
  272. profile: emqx-enterprise
  273. - os: raspbian10
  274. profile: emqx-enterprise
  275. include:
  276. - profile: emqx
  277. otp: 24.1.5-4
  278. elixir: 1.13.2
  279. build_elixir: with_elixir
  280. arch: amd64
  281. os: ubuntu20.04
  282. build_machine: ubuntu-20.04
  283. - profile: emqx
  284. otp: 24.1.5-4
  285. elixir: 1.13.2
  286. build_elixir: with_elixir
  287. arch: amd64
  288. os: centos7
  289. build_machine: ubuntu-20.04
  290. defaults:
  291. run:
  292. shell: bash
  293. steps:
  294. - uses: AutoModality/action-clean@v1
  295. if: matrix.build_machine == 'aws-arm64'
  296. - uses: actions/download-artifact@v2
  297. with:
  298. name: source
  299. path: .
  300. - name: unzip source code
  301. run: unzip -q source.zip
  302. - name: load rocksdb cache
  303. uses: actions/cache@v2
  304. with:
  305. path: |
  306. source/_build/default/lib/rocksdb/
  307. source/deps/rocksdb/
  308. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_ROCKSDB_REF }}
  309. - name: load quicer cache
  310. uses: actions/cache@v2
  311. with:
  312. path: |
  313. source/_build/default/lib/quicer/
  314. source/deps/quicer/
  315. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_QUICER_REF }}
  316. - name: download old emqx tgz packages
  317. env:
  318. OTP_VSN: ${{ matrix.otp }}
  319. PROFILE: ${{ matrix.profile }}
  320. ARCH: ${{ matrix.arch }}
  321. SYSTEM: ${{ matrix.os }}
  322. CE_OLD_VSNS: ${{ needs.prepare.outputs.ce_old_vsns }}
  323. EE_OLD_VSNS: ${{ needs.prepare.outputs.ee_old_vsns }}
  324. working-directory: source
  325. run: |
  326. set -e -x -u
  327. if [ $PROFILE = 'emqx' ]; then
  328. s3dir='emqx-ce'
  329. OLD_VSNS="$CE_OLD_VSNS"
  330. elif [ $PROFILE = 'emqx-enterprise' ]; then
  331. s3dir='emqx-ee'
  332. OLD_VSNS="$EE_OLD_VSNS"
  333. elif [ $PROFILE = 'emqx-edge' ]; then
  334. s3dir='emqx-edge'
  335. OLD_VSNS="$CE_OLD_VSNS"
  336. else
  337. echo "unknown profile $PROFILE"
  338. exit 1
  339. fi
  340. mkdir -p _upgrade_base
  341. cd _upgrade_base
  342. old_vsns=$(echo "$OLD_VSNS" | tr ' ' ' ')
  343. # workaround for bash empty array expanding issue in different bash versions
  344. if [ -n "$old_vsns" ]; then
  345. old_vsns=($old_vsns)
  346. for tag in ${old_vsns[@]}; do
  347. package_name="${PROFILE}-${tag#[e|v]}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
  348. 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
  349. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz
  350. wget --no-verbose https://s3-us-west-2.amazonaws.com/packages.emqx/$s3dir/$tag/$package_name.tar.gz.sha256
  351. echo "$(cat $package_name.tar.gz.sha256) $package_name.tar.gz" | sha256sum -c || exit 1
  352. fi
  353. done
  354. fi
  355. - name: build emqx packages
  356. working-directory: source
  357. env:
  358. OTP: ${{ matrix.otp }}
  359. ELIXIR: ${{ matrix.elixir }}
  360. PROFILE: ${{ matrix.profile }}
  361. ARCH: ${{ matrix.arch }}
  362. SYSTEM: ${{ matrix.os }}
  363. run: |
  364. set -eu
  365. # Align path for CMake caches
  366. if [ ! "$PWD" = "/emqx" ]; then
  367. ln -s $PWD /emqx
  368. cd /emqx
  369. fi
  370. echo "pwd is $PWD"
  371. PkgTypes="tgz pkg"
  372. WithElixir=""
  373. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  374. PkgTypes="tgz"
  375. # set Elixir build flag
  376. WithElixir="--with-elixir"
  377. fi
  378. for PKGTYPE in ${PkgTypes};
  379. do
  380. ./scripts/buildx.sh \
  381. --profile "${PROFILE}" \
  382. --pkgtype "${PKGTYPE}" \
  383. --arch "${ARCH}" \
  384. --otp "${OTP}" \
  385. --elixir "${ELIXIR}" "$WithElixir" \
  386. --system "${SYSTEM}" \
  387. --builder "ghcr.io/emqx/emqx-builder/5.0-5:${ELIXIR}-${OTP}-${SYSTEM}"
  388. done
  389. - name: create sha256
  390. env:
  391. PROFILE: ${{ matrix.profile}}
  392. working-directory: source
  393. run: |
  394. if [ -d _packages/$PROFILE ]; then
  395. cd _packages/$PROFILE
  396. for var in $(ls emqx-* ); do
  397. bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"
  398. done
  399. cd -
  400. fi
  401. - uses: actions/upload-artifact@v1
  402. if: startsWith(github.ref, 'refs/tags/')
  403. with:
  404. name: ${{ matrix.profile }}-${{ matrix.otp }}
  405. path: source/_packages/${{ matrix.profile }}/.
  406. docker:
  407. runs-on: ${{ matrix.build_machine }}
  408. needs: prepare
  409. strategy:
  410. fail-fast: false
  411. matrix:
  412. os:
  413. - alpine3.14
  414. profile: # all editions for docker
  415. - emqx-edge
  416. - emqx
  417. - emqx-enterprise
  418. # NOTE: for docker, only support latest otp and elixir
  419. # versions, not a matrix
  420. otp:
  421. - 24.1.5-4 # update to latest
  422. elixir:
  423. - 1.13.2 # update to latest
  424. arch:
  425. - amd64
  426. - arm64
  427. build_elixir:
  428. - no_elixir
  429. build_machine:
  430. - aws-arm64
  431. - ubuntu-20.04
  432. exclude:
  433. - arch: arm64
  434. build_machine: ubuntu-20.04
  435. - arch: amd64
  436. build_machine: aws-arm64
  437. include:
  438. - os: alpine3.14
  439. profile: emqx
  440. otp: 24.1.5-4
  441. elixir: 1.13.2
  442. arch: amd64
  443. build_elixir: with_elixir
  444. build_machine: ubuntu-20.04
  445. steps:
  446. - uses: AutoModality/action-clean@v1
  447. if: matrix.build_machine == 'aws-arm64'
  448. - uses: actions/download-artifact@v2
  449. with:
  450. name: source
  451. path: .
  452. - name: unzip source code
  453. run: unzip -q source.zip
  454. - uses: docker/setup-buildx-action@v1
  455. - name: load rocksdb cache
  456. uses: actions/cache@v2
  457. with:
  458. path: |
  459. source/_build/default/lib/rocksdb/
  460. source/deps/rocksdb//
  461. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_ROCKSDB_REF }}
  462. - name: load quicer cache
  463. uses: actions/cache@v2
  464. with:
  465. path: |
  466. source/_build/default/lib/quicer/
  467. source/deps/quicer/
  468. key: ${{ matrix.os }}-${{ matrix.otp }}-${{ matrix.arch }}-${{ needs.prepare.outputs.DEP_QUICER_REF }}
  469. - name: prepare for docker-action-parms
  470. id: pre-meta
  471. run: |
  472. img=$(echo ${{ matrix.os }} | sed 's#\([0-9.]\+\)$#:\1#g')
  473. emqx_name=${{ matrix.profile }}
  474. img_suffix=${{ matrix.arch }}
  475. img_labels="org.opencontainers.image.otp.version=${{ matrix.otp }}"
  476. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  477. emqx_name="emqx-elixir"
  478. img_suffix="elixir-${{ matrix.arch }}"
  479. img_labels="org.opencontainers.image.elixir.version=${{ matrix.elixir }}\n${img_labels}"
  480. fi
  481. echo "::set-output name=img::${img}"
  482. echo "::set-output name=emqx_name::${emqx_name}"
  483. echo "::set-output name=img_suffix::${img_suffix}"
  484. echo "::set-output name=img_labels::${img_labels}"
  485. # NOTE, Pls make sure this is identical as the one in job 'docker-push-multi-arch-manifest'
  486. - uses: docker/metadata-action@v3
  487. id: meta
  488. with:
  489. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  490. flavor: |
  491. latest=${{ github.event_name == 'release' && !github.event.release.prerelease }}
  492. suffix=-${{ steps.pre-meta.outputs.img_suffix }}
  493. tags: |
  494. type=ref,event=branch
  495. type=ref,event=pr
  496. type=ref,event=tag
  497. type=semver,pattern={{version}}
  498. labels:
  499. ${{ steps.pre-meta.outputs.img_labels }}
  500. - uses: docker/login-action@v1
  501. if: >
  502. ${{ (github.event_name == 'release' && !github.event.release.prerelease)
  503. || (github.event.repository.owner != 'emqx' && startsWith(github.ref_name, 'ci/')) }}
  504. with:
  505. username: ${{ secrets.DOCKER_HUB_USER }}
  506. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  507. - uses: docker/build-push-action@v2
  508. with:
  509. push: >
  510. ${{ (github.event_name == 'release' && !github.event.release.prerelease)
  511. || (github.event.repository.owner != 'emqx' && startsWith(github.ref_name, 'ci/')) }}
  512. pull: true
  513. no-cache: true
  514. platforms: linux/${{ matrix.arch }}
  515. tags: ${{ steps.meta.outputs.tags }}
  516. labels: ${{ steps.meta.outputs.labels }}
  517. build-args: |
  518. BUILD_FROM=ghcr.io/emqx/emqx-builder/5.0-5:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}
  519. RUN_FROM=${{ steps.pre-meta.outputs.img }}
  520. EMQX_NAME=${{ steps.pre-meta.outputs.emqx_name }}
  521. file: source/deploy/docker/Dockerfile
  522. context: source
  523. - uses: aws-actions/configure-aws-credentials@v1
  524. if: github.event_name == 'release' && !github.event.release.prerelease && matrix.profile == 'emqx'
  525. with:
  526. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  527. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  528. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  529. - name: Push image to aws ecr
  530. if: github.event_name == 'release' && !github.event.release.prerelease && matrix.profile == 'emqx' && matrix.build_elixir == 'no_elixir'
  531. run: |
  532. version=${GITHUB_REF##*/}
  533. docker pull emqx/emqx:${version#v}
  534. docker tag emqx/emqx:${version#v} public.ecr.aws/emqx/emqx:${version#v}
  535. aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
  536. docker push public.ecr.aws/emqx/emqx:${version#v}
  537. - name: Push image to aws ecr (elixir)
  538. if: github.event_name == 'release' && !github.event.release.prerelease && matrix.profile == 'emqx' && matrix.build_elixir == 'with_elixir'
  539. run: |
  540. version=${GITHUB_REF##*/}-elixir
  541. docker pull emqx/emqx:${version#v}
  542. docker tag emqx/emqx:${version#v} public.ecr.aws/emqx/emqx:${version#v}
  543. aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
  544. docker push public.ecr.aws/emqx/emqx:${version#v}
  545. docker-push-multi-arch-manifest:
  546. # note, we only run on amd64
  547. if: >
  548. (github.event_name == 'release' && !github.event.release.prerelease)
  549. || (github.event.repository.owner != 'emqx' && startsWith(github.ref_name, 'ci/'))
  550. needs:
  551. - prepare
  552. - docker
  553. runs-on: ubuntu-latest
  554. strategy:
  555. fail-fast: false
  556. matrix:
  557. profile: # all editions for docker
  558. - emqx-edge
  559. - emqx
  560. - emqx-enterprise
  561. # NOTE: for docker, only support latest otp version, not a matrix
  562. otp:
  563. - 24.1.5-4 # update to latest
  564. #
  565. elixir:
  566. - 1.13.2 # update to latest
  567. arch:
  568. - amd64
  569. - arm64
  570. build_elixir:
  571. - no_elixir
  572. build_machine:
  573. - aws-arm64
  574. - ubuntu-20.04
  575. exclude:
  576. - arch: arm64
  577. build_machine: ubuntu-20.04
  578. - arch: amd64
  579. build_machine: aws-arm64
  580. include:
  581. - os: alpine3.14
  582. profile: emqx
  583. otp: 24.1.5-4
  584. elixir: 1.13.2
  585. arch: amd64
  586. build_elixir: with_elixir
  587. build_machine: ubuntu-20.04
  588. steps:
  589. - uses: actions/download-artifact@v2
  590. if: matrix.arch == 'amd64'
  591. with:
  592. name: source
  593. path: .
  594. - name: unzip source code
  595. if: matrix.arch == 'amd64'
  596. run: unzip -q source.zip
  597. - uses: docker/login-action@v1
  598. if: matrix.arch == 'amd64'
  599. with:
  600. username: ${{ secrets.DOCKER_HUB_USER }}
  601. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  602. - name: prepare for docker-action-parms
  603. id: pre-meta
  604. run: |
  605. img=$(echo ${{ matrix.os }} | sed 's#\([0-9.]\+\)$#:\1#g')
  606. emqx_name=${{ matrix.profile }}
  607. img_suffix=${{ matrix.arch }}
  608. img_labels="org.opencontainers.image.otp.version=${{ matrix.otp }}"
  609. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  610. emqx_name="emqx-elixir"
  611. img_suffix="elixir-${{ matrix.arch }}"
  612. img_labels="org.opencontainers.image.elixir.version=${{ matrix.elixir }}\n$img_labels"
  613. fi
  614. echo "::set-output name=img::${img}"
  615. echo "::set-output name=emqx_name::${emqx_name}"
  616. echo "::set-output name=img_suffix::${img_suffix}"
  617. echo "::set-output name=img_labels::${img_labels}"
  618. # NOTE, Pls make sure this is identical as the one in job 'docker'
  619. - uses: docker/metadata-action@v3
  620. if: matrix.arch == 'amd64'
  621. id: meta
  622. with:
  623. images: ${{ github.repository_owner }}/${{ matrix.profile }}
  624. flavor: |
  625. latest=false
  626. suffix=-${{ steps.pre-meta.outputs.img_suffix }}
  627. tags: |
  628. type=ref,event=branch
  629. type=ref,event=pr
  630. type=ref,event=tag
  631. type=semver,pattern={{version}}
  632. labels:
  633. ${{ steps.pre-meta.outputs.img_labels }}
  634. - name: update manifest for multiarch image
  635. if: matrix.arch == 'amd64'
  636. working-directory: source
  637. run: |
  638. IsPushLatest=${{ github.event_name == 'release' && !github.event.release.prerelease }};
  639. scripts/docker-create-push-manifests.sh "${{ steps.meta.outputs.tags }}" "$IsPushLatest"
  640. delete-artifact:
  641. runs-on: ubuntu-20.04
  642. needs: [prepare, mac, linux, docker]
  643. steps:
  644. - uses: geekyeggo/delete-artifact@v1
  645. with:
  646. name: source
  647. upload:
  648. runs-on: ubuntu-20.04
  649. if: startsWith(github.ref, 'refs/tags/')
  650. needs: [prepare, mac, linux, docker]
  651. strategy:
  652. matrix:
  653. profile:
  654. - emqx-edge
  655. - emqx
  656. - emqx-enterprise
  657. otp:
  658. - 24.1.5-4
  659. steps:
  660. - uses: actions/checkout@v2
  661. - name: get_version
  662. run: |
  663. echo 'version<<EOF' >> $GITHUB_ENV
  664. echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g" >> $GITHUB_ENV
  665. echo 'EOF' >> $GITHUB_ENV
  666. - uses: actions/download-artifact@v2
  667. with:
  668. name: ${{ matrix.profile }}-${{ matrix.otp }}
  669. path: ./_packages/${{ matrix.profile }}
  670. - name: install dos2unix
  671. run: sudo apt-get update && sudo apt install -y dos2unix
  672. - name: get packages
  673. run: |
  674. set -e -u
  675. cd _packages/${{ matrix.profile }}
  676. for var in $( ls |grep emqx |grep -v sha256); do
  677. dos2unix $var.sha256
  678. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  679. done
  680. cd -
  681. - name: upload aws s3
  682. run: |
  683. set -e -u
  684. PROFILE=${{ matrix.profile }}
  685. if [ $PROFILE = 'emqx' ]; then
  686. s3dir='emqx-ce'
  687. elif [ $PROFILE = 'emqx-enterprise' ]; then
  688. s3dir='emqx-ee'
  689. elif [ $PROFILE = 'emqx-edge' ]; then
  690. s3dir='emqx-edge'
  691. else
  692. echo "unknown profile $PROFILE"
  693. exit 1
  694. fi
  695. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  696. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  697. aws configure set default.region ${{ secrets.AWS_DEFAULT_REGION }}
  698. aws s3 cp --recursive _packages/${{ matrix.profile }} s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ env.version }}
  699. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ env.version }}/*"
  700. - uses: Rory-Z/upload-release-asset@v1
  701. if: github.event_name == 'release'
  702. with:
  703. repo: emqx
  704. path: "_packages/${{ matrix.profile }}/emqx-*"
  705. token: ${{ github.token }}
  706. - name: update to emqx.io
  707. if: github.event_name == 'release'
  708. run: |
  709. set -e -x -u
  710. curl -w %{http_code} \
  711. --insecure \
  712. -H "Content-Type: application/json" \
  713. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  714. -X POST \
  715. -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${{ env.version }}\" }" \
  716. ${{ secrets.EMQX_IO_RELEASE_API }}
  717. - name: update repo.emqx.io
  718. if: github.event_name == 'release'
  719. run: |
  720. if [ "${{ matrix.profile }}" = 'emqx-enterprise' ]; then
  721. BOOL_FLAG_NAME="emqx_ee"
  722. else
  723. BOOL_FLAG_NAME="emqx_ce"
  724. fi
  725. curl --silent --show-error \
  726. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  727. -H "Accept: application/vnd.github.v3+json" \
  728. -X POST \
  729. -d "{\"ref\":\"v1.0.4\",\"inputs\":{\"version\": \"${{ env.version }}\", \"${BOOL_FLAG_NAME}\": \"true\"}}" \
  730. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_repos.yaml/dispatches"
  731. - name: update homebrew packages
  732. if: github.event_name == 'release' && matrix.profile == 'emqx'
  733. run: |
  734. if [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
  735. curl --silent --show-error \
  736. -H "Authorization: token ${{ secrets.CI_GIT_TOKEN }}" \
  737. -H "Accept: application/vnd.github.v3+json" \
  738. -X POST \
  739. -d "{\"ref\":\"v1.0.4\",\"inputs\":{\"version\": \"${{ env.version }}\"}}" \
  740. "https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_emqx_homebrew.yaml/dispatches"
  741. fi
  742. - uses: geekyeggo/delete-artifact@v1
  743. with:
  744. name: ${{ matrix.profile }}