build_packages.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. name: Build packages
  2. concurrency:
  3. group: build-${{ github.event_name }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. tags:
  8. - "*"
  9. pull_request:
  10. release:
  11. types:
  12. - published
  13. jobs:
  14. build:
  15. runs-on: ubuntu-latest
  16. strategy:
  17. matrix:
  18. golang:
  19. - 1.18
  20. arch:
  21. - linux/amd64
  22. - linux/arm64
  23. - linux/arm/v7
  24. os:
  25. - debian
  26. - centos
  27. exclude:
  28. - os: centos
  29. arch: linux/arm/v7
  30. steps:
  31. - uses: actions/checkout@v2
  32. with:
  33. fetch-depth: 0
  34. - uses: docker/setup-buildx-action@v1
  35. - uses: docker/setup-qemu-action@v1
  36. with:
  37. image: tonistiigi/binfmt:latest
  38. platforms: all
  39. - uses: docker/setup-buildx-action@v1
  40. - name: build
  41. if: matrix.os == 'debian'
  42. run: |
  43. docker run -i --rm \
  44. -v $(pwd):/ekuiper \
  45. --workdir /ekuiper \
  46. --env KUIPER_SOURCE='/ekuiper' \
  47. --platform ${{ matrix.arch }} \
  48. ghcr.io/lf-edge/ekuiper/base:${{ matrix.golang }}-${{ matrix.os }} \
  49. bash -euc "make pkg && .github/scripts/test.sh"
  50. - name: build
  51. if: matrix.os == 'centos'
  52. run: |
  53. docker run -i --rm \
  54. -v $(pwd):/ekuiper \
  55. --workdir /ekuiper \
  56. --env KUIPER_SOURCE='/ekuiper' \
  57. --platform ${{ matrix.arch }} \
  58. ghcr.io/lf-edge/ekuiper/base:${{ matrix.golang }}-${{ matrix.os }} \
  59. bash -euc "make -C deploy/packages && .github/scripts/test.sh"
  60. - name: create sha file
  61. run: |
  62. cd _packages && for var in $(ls); do sudo bash -c "echo $(sha256sum $var | awk '{print $1}') > $var.sha256"; done && cd -
  63. - uses: actions/upload-artifact@v1
  64. with:
  65. name: packages
  66. path: _packages/.
  67. build-on-mac:
  68. runs-on: macos-latest
  69. steps:
  70. - uses: actions/checkout@v2
  71. with:
  72. fetch-depth: 0
  73. - uses: actions/setup-go@v2
  74. with:
  75. go-version: '1.18'
  76. - name: prepare
  77. run: |
  78. brew install curl zip unzip gnu-sed upx pkg-config zmq
  79. echo "/usr/local/bin:$PATH" >> ~/.bashrc
  80. - name: build
  81. run: |
  82. make pkg
  83. cd _packages && for var in $(ls); do openssl dgst -sha256 $var | awk '{print $2}' > $var.sha256; done && cd -
  84. - uses: actions/upload-artifact@v1
  85. with:
  86. name: packages-mac
  87. path: _packages/.
  88. build-docker-images:
  89. runs-on: ubuntu-latest
  90. strategy:
  91. fail-fast: false
  92. matrix:
  93. suffix:
  94. - ""
  95. - "-alpine"
  96. - "-slim"
  97. - "-slim-python"
  98. steps:
  99. - uses: actions/checkout@v2
  100. with:
  101. fetch-depth: 0
  102. - uses: docker/setup-buildx-action@v1
  103. - uses: docker/setup-qemu-action@v1
  104. with:
  105. image: tonistiigi/binfmt:latest
  106. platforms: all
  107. - name: Build single platform image
  108. if: endsWith( matrix.suffix, 'python') == false
  109. uses: docker/build-push-action@v2
  110. with:
  111. context: .
  112. platforms: linux/amd64
  113. push: false
  114. load: true
  115. tags: docker.io/lfedge/ekuiper
  116. file: deploy/docker/Dockerfile${{ matrix.suffix }}
  117. - name: Test docker image
  118. run: |
  119. docker run -d --name ekuiper docker.io/lfedge/ekuiper
  120. ip_address=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ekuiper)
  121. sleep 5
  122. if ! curl ${ip_address}:9081 >/dev/null 2>&1; then
  123. echo "docker image failed"
  124. docker logs ekuiper
  125. exit 1
  126. fi
  127. - uses: docker/metadata-action@v3
  128. id: meta
  129. with:
  130. images: docker.io/lfedge/ekuiper
  131. flavor: |
  132. latest=${{ github.event_name == 'release' && matrix.suffix == '-slim' && !github.event.release.prerelease}}
  133. suffix=${{ matrix.suffix }}
  134. tags: |
  135. type=ref,event=branch
  136. type=ref,event=pr
  137. type=ref,event=tag
  138. type=semver,pattern={{version}}
  139. type=semver,pattern={{major}}.{{minor}}
  140. - uses: docker/login-action@v1
  141. if: github.event_name == 'release'
  142. with:
  143. username: ${{ secrets.DOCKER_HUB_USER }}
  144. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  145. - name: Update version for setup.py
  146. if: github.event_name == 'release'
  147. run: sed -i -r "s|([ \t]*version=).*|\1'${GITHUB_REF#refs/tags/}',|1" sdk/python/setup.py
  148. - name: Build multi platform image
  149. uses: docker/build-push-action@v2
  150. with:
  151. context: .
  152. platforms: linux/amd64,linux/arm64,linux/arm/v7
  153. push: ${{ github.event_name == 'release' }}
  154. tags: ${{ steps.meta.outputs.tags }}
  155. labels: ${{ steps.meta.outputs.labels }}
  156. file: deploy/docker/Dockerfile${{ matrix.suffix }}
  157. build-plugins:
  158. runs-on: ubuntu-latest
  159. strategy:
  160. fail-fast: false
  161. matrix:
  162. plugin:
  163. - sinks/file
  164. - sinks/image
  165. - sinks/influx
  166. - sinks/tdengine
  167. - sinks/zmq
  168. - sinks/redis
  169. - sinks/sql
  170. - sources/random
  171. - sources/zmq
  172. - sources/sql
  173. - functions/accumulateWordCount
  174. - functions/countPlusOne
  175. - functions/echo
  176. - functions/image
  177. - functions/geohash
  178. - functions/labelImage
  179. arch:
  180. - linux/amd64
  181. - linux/arm64
  182. golang:
  183. - 1.18
  184. exclude:
  185. - arch: linux/arm64
  186. plugin: functions/labelImage
  187. steps:
  188. - uses: actions/checkout@v2
  189. with:
  190. fetch-depth: 0
  191. - uses: docker/setup-buildx-action@v1
  192. - uses: docker/setup-qemu-action@v1
  193. with:
  194. image: tonistiigi/binfmt:latest
  195. platforms: all
  196. - name: build debian plugins
  197. run: |
  198. docker run -i --rm \
  199. -v $(pwd):/ekuiper \
  200. --workdir /ekuiper \
  201. --platform ${{ matrix.arch }} \
  202. ghcr.io/lf-edge/ekuiper/base:${{ matrix.golang }}-debian \
  203. bash -euc "make ${{ matrix.plugin }}"
  204. - name: Build ekuiper image
  205. uses: docker/build-push-action@v2
  206. if: matrix.arch == 'linux/amd64'
  207. with:
  208. context: .
  209. platforms: linux/amd64
  210. push: false
  211. load: true
  212. tags: docker.io/lfedge/ekuiper
  213. file: deploy/docker/Dockerfile
  214. - name: test docker and plugins
  215. if: matrix.arch == 'linux/amd64'
  216. env:
  217. PLUGIN: ${{ matrix.plugin }}
  218. run: |
  219. set -e -x -u
  220. plugin_type=$(echo ${PLUGIN%%/*})
  221. plugin_name=$(echo ${PLUGIN##*/})
  222. container_id=$(docker run -d -v $(pwd)/_plugins:/var/plugins docker.io/lfedge/ekuiper)
  223. ip_address=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_id)
  224. os=$(docker exec -i ${container_id} sh -c "sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g'" )
  225. sleep 5
  226. if ! curl ${ip_address}:9081 >/dev/null 2>&1; then echo "docker image failed"; exit 1; fi
  227. if [ "${plugin_name}" = "tdengine" ]; then
  228. curl \
  229. ${ip_address}:9081/plugins/${plugin_type} \
  230. -X POST \
  231. -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\", \"shellParas\": [\"2.4.0.18\"]}"
  232. elif [ "${plugin_name}" = "image" ]; then
  233. curl \
  234. ${ip_address}:9081/plugins/${plugin_type} \
  235. -X POST \
  236. -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\", \"functions\": [\"resize\",\"thumbnail\"]}"
  237. elif [ "${plugin_name}" = "geohash" ]; then
  238. curl \
  239. ${ip_address}:9081/plugins/${plugin_type} \
  240. -X POST \
  241. -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\", \"functions\": [\"geohashEncode\", \"geohashEncodeInt\", \"geohashDecode\", \"geohashDecodeInt\", \"geohashBoundingBox\", \"geohashBoundingBoxInt\", \"geohashNeighbor\", \"geohashNeighborInt\", \"geohashNeighbors\", \"geohashNeighborsInt\"]}"
  242. else
  243. curl \
  244. ${ip_address}:9081/plugins/${plugin_type} \
  245. -X POST \
  246. -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\"}"
  247. fi
  248. docker logs ${container_id}
  249. [ $plugin_name = $(curl ${ip_address}:9081/plugins/${plugin_type}/${plugin_name} | jq '.name'| sed 's/\"//g' ) ] || exit 1
  250. - uses: actions/upload-artifact@v2
  251. with:
  252. name: plugins
  253. path: "_plugins/"
  254. build-kubernetes-tool:
  255. runs-on: ubuntu-latest
  256. steps:
  257. - uses: actions/checkout@v2
  258. with:
  259. fetch-depth: 0
  260. - uses: docker/setup-buildx-action@v1
  261. - uses: docker/setup-qemu-action@v1
  262. with:
  263. image: tonistiigi/binfmt:latest
  264. platforms: all
  265. - name: Build single platform image
  266. uses: docker/build-push-action@v2
  267. with:
  268. context: .
  269. platforms: linux/amd64
  270. push: false
  271. load: true
  272. tags: docker.io/lfedge/ekuiper-kubernetes-tool
  273. file: deploy/docker/Dockerfile-kubernetes-tool
  274. - name: Test docker image
  275. run: |
  276. docker run -d --name kuiper-kubernetes-tool docker.io/lfedge/ekuiper-kubernetes-tool
  277. sleep 5
  278. if [[ "$(docker logs kuiper-kubernetes-tool)" != *"Kuiper kubernetes tool is started successfully!"* ]]; then exit 1; fi
  279. - uses: docker/metadata-action@v3
  280. id: meta
  281. with:
  282. images: docker.io/lfedge/ekuiper-kubernetes-tool
  283. flavor: |
  284. latest=${{ github.event_name == 'release' && !github.event.release.prerelease}}
  285. tags: |
  286. type=ref,event=branch
  287. type=ref,event=pr
  288. type=ref,event=tag
  289. type=semver,pattern={{version}}
  290. type=semver,pattern={{major}}.{{minor}}
  291. - uses: docker/login-action@v1
  292. if: github.event_name == 'release'
  293. with:
  294. username: ${{ secrets.DOCKER_HUB_USER }}
  295. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  296. - name: Build multi platform image
  297. uses: docker/build-push-action@v2
  298. with:
  299. context: .
  300. platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
  301. push: ${{ github.event_name == 'release' }}
  302. tags: ${{ steps.meta.outputs.tags }}
  303. labels: ${{ steps.meta.outputs.labels }}
  304. file: deploy/docker/Dockerfile-kubernetes-tool
  305. release:
  306. runs-on: ubuntu-latest
  307. needs:
  308. - build
  309. - build-on-mac
  310. - build-plugins
  311. steps:
  312. - uses: actions/checkout@v2
  313. - uses: actions/download-artifact@v1
  314. with:
  315. name: packages
  316. path: _packages
  317. - uses: actions/download-artifact@v1
  318. with:
  319. name: packages-mac
  320. path: _packages
  321. - uses: actions/download-artifact@v1
  322. with:
  323. name: plugins
  324. path: _plugins
  325. - name: check packages
  326. run: |
  327. cd _packages && for var in $( ls |grep -v sha256); do
  328. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  329. done
  330. - uses: Rory-Z/upload-release-asset@v1
  331. if: github.event_name == 'release'
  332. with:
  333. repo: ekuiper
  334. path: "_packages/kuiper-*"
  335. token: ${{ secrets.GITHUB_TOKEN }}
  336. - name: upload packages to s3
  337. if: github.event_name == 'release'
  338. run: |
  339. version=$(echo ${{ github.ref }} | sed -r "s .*/.*/(.*) \1 g")
  340. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  341. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  342. aws configure set default.region us-west-2
  343. aws s3 rm --quiet --recursive s3://packages.emqx/kuiper/$version
  344. aws s3 cp --quiet --recursive ./_packages s3://packages.emqx/kuiper/$version
  345. aws s3 cp --quiet --recursive ./_plugins s3://packages.emqx/kuiper-plugins/$version
  346. aws cloudfront create-invalidation --distribution-id E170YEULGLT8XB --paths "/kuiper/$version/*,/kuiper-plugins/$version/*"
  347. - name: update ekuiper.org
  348. if: github.event_name == 'release'
  349. run: |
  350. set -e -x -u
  351. curl -w %{http_code} \
  352. --insecure \
  353. -H "Content-Type: application/json" \
  354. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  355. -X POST \
  356. -d "{\"repo\":\"lf-edge/ekuiper\", \"tag\": \"${{ github.ref_name }}\" }" \
  357. ${{ secrets.EMQX_IO_RELEASE_API }}