build_packages.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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.5
  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.5'
  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. golang:
  99. - 1.18.5
  100. steps:
  101. - uses: actions/checkout@v2
  102. with:
  103. fetch-depth: 0
  104. - uses: docker/setup-buildx-action@v1
  105. - uses: docker/setup-qemu-action@v1
  106. with:
  107. image: tonistiigi/binfmt:latest
  108. platforms: all
  109. - name: Build single platform image
  110. if: endsWith( matrix.suffix, 'python') == false
  111. uses: docker/build-push-action@v2
  112. with:
  113. context: .
  114. platforms: linux/amd64
  115. push: false
  116. load: true
  117. tags: docker.io/lfedge/ekuiper
  118. build-args: GO_VERSION=${{ matrix.golang }}
  119. file: deploy/docker/Dockerfile${{ matrix.suffix }}
  120. - name: Test docker image
  121. run: |
  122. docker run -d --name ekuiper docker.io/lfedge/ekuiper
  123. ip_address=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ekuiper)
  124. sleep 5
  125. if ! curl ${ip_address}:9081 >/dev/null 2>&1; then
  126. echo "docker image failed"
  127. docker logs ekuiper
  128. exit 1
  129. fi
  130. - uses: docker/metadata-action@v3
  131. id: meta
  132. with:
  133. images: docker.io/lfedge/ekuiper
  134. flavor: |
  135. latest=${{ github.event_name == 'release' && matrix.suffix == '-slim' && !github.event.release.prerelease}}
  136. suffix=${{ matrix.suffix }}
  137. tags: |
  138. type=ref,event=branch
  139. type=ref,event=pr
  140. type=ref,event=tag
  141. type=semver,pattern={{version}}
  142. type=semver,pattern={{major}}.{{minor}}
  143. - uses: docker/login-action@v1
  144. if: github.event_name == 'release'
  145. with:
  146. username: ${{ secrets.DOCKER_HUB_USER }}
  147. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  148. - name: Update version for setup.py
  149. if: github.event_name == 'release'
  150. run: sed -i -r "s|([ \t]*version=).*|\1'${GITHUB_REF#refs/tags/}',|1" sdk/python/setup.py
  151. - name: Build multi platform image
  152. uses: docker/build-push-action@v2
  153. with:
  154. context: .
  155. platforms: linux/amd64,linux/arm64,linux/arm/v7
  156. push: ${{ github.event_name == 'release' }}
  157. tags: ${{ steps.meta.outputs.tags }}
  158. build-args: GO_VERSION=${{ matrix.golang }}
  159. labels: ${{ steps.meta.outputs.labels }}
  160. file: deploy/docker/Dockerfile${{ matrix.suffix }}
  161. build-plugins:
  162. runs-on: ubuntu-latest
  163. strategy:
  164. fail-fast: false
  165. matrix:
  166. plugin:
  167. - sinks/file
  168. - sinks/image
  169. - sinks/influx
  170. - sinks/tdengine
  171. - sinks/zmq
  172. - sinks/redis
  173. - sinks/sql
  174. - sources/random
  175. - sources/zmq
  176. - sources/sql
  177. - functions/accumulateWordCount
  178. - functions/countPlusOne
  179. - functions/echo
  180. - functions/image
  181. - functions/geohash
  182. - functions/labelImage
  183. arch:
  184. - linux/amd64
  185. - linux/arm64
  186. golang:
  187. - 1.18.5
  188. exclude:
  189. - arch: linux/arm64
  190. plugin: functions/labelImage
  191. steps:
  192. - uses: actions/checkout@v2
  193. with:
  194. fetch-depth: 0
  195. - uses: docker/setup-buildx-action@v1
  196. - uses: docker/setup-qemu-action@v1
  197. with:
  198. image: tonistiigi/binfmt:latest
  199. platforms: all
  200. - name: build debian plugins
  201. run: |
  202. docker run -i --rm \
  203. -v $(pwd):/ekuiper \
  204. --workdir /ekuiper \
  205. --platform ${{ matrix.arch }} \
  206. ghcr.io/lf-edge/ekuiper/base:${{ matrix.golang }}-debian \
  207. bash -euc "make ${{ matrix.plugin }}"
  208. - name: Build ekuiper image
  209. uses: docker/build-push-action@v2
  210. if: matrix.arch == 'linux/amd64'
  211. with:
  212. context: .
  213. platforms: linux/amd64
  214. push: false
  215. load: true
  216. tags: docker.io/lfedge/ekuiper
  217. file: deploy/docker/Dockerfile-alpine
  218. - name: test docker and plugins
  219. if: matrix.arch == 'linux/amd64'
  220. env:
  221. PLUGIN: ${{ matrix.plugin }}
  222. run: |
  223. set -e -x -u
  224. plugin_type=$(echo ${PLUGIN%%/*})
  225. plugin_name=$(echo ${PLUGIN##*/})
  226. container_id=$(docker run -d -v $(pwd)/_plugins:/var/plugins docker.io/lfedge/ekuiper)
  227. ip_address=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_id)
  228. os=$(docker exec -i ${container_id} sh -c "sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g'" )
  229. os=debian
  230. sleep 5
  231. if ! curl ${ip_address}:9081 >/dev/null 2>&1; then echo "docker image failed"; exit 1; fi
  232. if [ "${plugin_name}" = "tdengine" ]; 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\", \"shellParas\": [\"2.4.0.18\"]}"
  237. elif [ "${plugin_name}" = "image" ]; 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\": [\"resize\",\"thumbnail\"]}"
  242. elif [ "${plugin_name}" = "geohash" ]; then
  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\", \"functions\": [\"geohashEncode\", \"geohashEncodeInt\", \"geohashDecode\", \"geohashDecodeInt\", \"geohashBoundingBox\", \"geohashBoundingBoxInt\", \"geohashNeighbor\", \"geohashNeighborInt\", \"geohashNeighbors\", \"geohashNeighborsInt\"]}"
  247. else
  248. curl \
  249. ${ip_address}:9081/plugins/${plugin_type} \
  250. -X POST \
  251. -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\"}"
  252. fi
  253. docker logs ${container_id}
  254. [ $plugin_name = $(curl ${ip_address}:9081/plugins/${plugin_type}/${plugin_name} | jq '.name'| sed 's/\"//g' ) ] || exit 1
  255. - uses: actions/upload-artifact@v2
  256. with:
  257. name: plugins
  258. path: "_plugins/"
  259. build-kubernetes-tool:
  260. runs-on: ubuntu-latest
  261. steps:
  262. - uses: actions/checkout@v2
  263. with:
  264. fetch-depth: 0
  265. - uses: docker/setup-buildx-action@v1
  266. - uses: docker/setup-qemu-action@v1
  267. with:
  268. image: tonistiigi/binfmt:latest
  269. platforms: all
  270. - name: Build single platform image
  271. uses: docker/build-push-action@v2
  272. with:
  273. context: .
  274. platforms: linux/amd64
  275. push: false
  276. load: true
  277. tags: docker.io/lfedge/ekuiper-kubernetes-tool
  278. file: deploy/docker/Dockerfile-kubernetes-tool
  279. - name: Test docker image
  280. run: |
  281. docker run -d --name kuiper-kubernetes-tool docker.io/lfedge/ekuiper-kubernetes-tool
  282. sleep 5
  283. if [[ "$(docker logs kuiper-kubernetes-tool)" != *"Kuiper kubernetes tool is started successfully!"* ]]; then exit 1; fi
  284. - uses: docker/metadata-action@v3
  285. id: meta
  286. with:
  287. images: docker.io/lfedge/ekuiper-kubernetes-tool
  288. flavor: |
  289. latest=${{ github.event_name == 'release' && !github.event.release.prerelease}}
  290. tags: |
  291. type=ref,event=branch
  292. type=ref,event=pr
  293. type=ref,event=tag
  294. type=semver,pattern={{version}}
  295. type=semver,pattern={{major}}.{{minor}}
  296. - uses: docker/login-action@v1
  297. if: github.event_name == 'release'
  298. with:
  299. username: ${{ secrets.DOCKER_HUB_USER }}
  300. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  301. - name: Build multi platform image
  302. uses: docker/build-push-action@v2
  303. with:
  304. context: .
  305. platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
  306. push: ${{ github.event_name == 'release' }}
  307. tags: ${{ steps.meta.outputs.tags }}
  308. labels: ${{ steps.meta.outputs.labels }}
  309. file: deploy/docker/Dockerfile-kubernetes-tool
  310. release:
  311. runs-on: ubuntu-latest
  312. needs:
  313. - build
  314. - build-on-mac
  315. - build-plugins
  316. steps:
  317. - uses: actions/checkout@v2
  318. - uses: actions/download-artifact@v1
  319. with:
  320. name: packages
  321. path: _packages
  322. - uses: actions/download-artifact@v1
  323. with:
  324. name: packages-mac
  325. path: _packages
  326. - uses: actions/download-artifact@v1
  327. with:
  328. name: plugins
  329. path: _plugins
  330. - name: check packages
  331. run: |
  332. cd _packages && for var in $( ls |grep -v sha256); do
  333. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  334. done
  335. - uses: Rory-Z/upload-release-asset@v1
  336. if: github.event_name == 'release'
  337. with:
  338. repo: ekuiper
  339. path: "_packages/kuiper-*"
  340. token: ${{ secrets.GITHUB_TOKEN }}
  341. - name: upload packages to s3
  342. if: github.event_name == 'release'
  343. run: |
  344. version=$(echo ${{ github.ref }} | sed -r "s .*/.*/(.*) \1 g")
  345. aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
  346. aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  347. aws configure set default.region us-west-2
  348. aws s3 rm --quiet --recursive s3://packages.emqx/kuiper/$version
  349. aws s3 cp --quiet --recursive ./_packages s3://packages.emqx/kuiper/$version
  350. aws s3 cp --quiet --recursive ./_plugins s3://packages.emqx/kuiper-plugins/$version
  351. aws cloudfront create-invalidation --distribution-id E170YEULGLT8XB --paths "/kuiper/$version/*,/kuiper-plugins/$version/*"
  352. - name: update ekuiper.org
  353. if: github.event_name == 'release'
  354. run: |
  355. set -e -x -u
  356. curl -w %{http_code} \
  357. --insecure \
  358. -H "Content-Type: application/json" \
  359. -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
  360. -X POST \
  361. -d "{\"repo\":\"lf-edge/ekuiper\", \"tag\": \"${{ github.ref_name }}\" }" \
  362. ${{ secrets.EMQX_IO_RELEASE_API }}