build-plugins.sh 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #
  3. # Copyright 2023 EMQ Technologies Co., Ltd.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. set -euo pipefail
  18. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
  19. PLUGIN_TYPE=$1
  20. PLUGIN_NAME=$2
  21. VERSION=$(git describe --tags --always)
  22. OS=$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g')
  23. pre(){
  24. mkdir -p _plugins/$OS/$PLUGIN_TYPE
  25. if [ $(cat etc/$PLUGIN_TYPE/$PLUGIN_NAME.json | jq -r ".libs") != 'null' ]; then
  26. for lib in $(cat etc/$PLUGIN_TYPE/$PLUGIN_NAME.json | jq -r ".libs[]"); do
  27. go get $lib;
  28. done
  29. fi
  30. }
  31. post(){
  32. if [ -f "etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml" ]; then
  33. cp etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml extensions/$PLUGIN_TYPE/$PLUGIN_NAME;
  34. fi
  35. cd extensions/$PLUGIN_TYPE/$PLUGIN_NAME
  36. zip -r ${PLUGIN_NAME}_$(go env GOARCH).zip .
  37. cd -
  38. mv $(find extensions/$PLUGIN_TYPE/$PLUGIN_NAME -name "*.zip") _plugins/$OS/$PLUGIN_TYPE
  39. }
  40. build(){
  41. case $PLUGIN_NAME in
  42. influx )
  43. go build -trimpath --buildmode=plugin -tags plugins -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME.go
  44. ;;
  45. tdengine )
  46. if [ "$(uname -m)" = "x86_64" ]; then
  47. wget "https://www.taosdata.com/assets-download/TDengine-client-2.4.0.18-Linux-x64.tar.gz" -O /tmp/TDengine-client-2.4.0.18.tar.gz;
  48. fi;
  49. if [ "$(uname -m)" = "aarch64" ]; then
  50. wget "https://www.taosdata.com/assets-download/TDengine-client-2.4.0.18-Linux-aarch64.tar.gz" -O /tmp/TDengine-client-2.4.0.18.tar.gz;
  51. fi;
  52. tar -zxvf /tmp/TDengine-client-2.4.0.18.tar.gz
  53. cd TDengine-client-2.4.0.18 && ./install_client.sh && cd -
  54. go build -trimpath --buildmode=plugin -tags plugins -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME.go
  55. ;;
  56. labelImage )
  57. if [ ! -d "/tmp/tensorflow" ];then
  58. git clone -b v2.2.0-rc3 --depth 1 https://github.com/tensorflow/tensorflow.git /tmp/tensorflow;
  59. fi;
  60. if [ "$(uname -m)" = "x86_64" ]; then
  61. cp $(pwd)/extensions/functions/dependencies/tensorflow/amd64/*.so $(pwd)/extensions/functions/labelImage/lib
  62. fi;
  63. if [ "$(uname -m)" = "aarch64" ]; then
  64. cp $(pwd)/extensions/functions/dependencies/tensorflow/arm64/*.so $(pwd)/extensions/functions/labelImage/lib
  65. fi;
  66. CGO_CFLAGS=-I/tmp/tensorflow CGO_LDFLAGS=-L$(pwd)/extensions/functions/labelImage/lib go build -trimpath --buildmode=plugin -o extensions/functions/labelImage/labelImage@$VERSION.so extensions/functions/labelImage/*.go
  67. ;;
  68. tfLite )
  69. if [ ! -d "/tmp/tensorflow" ];then
  70. git clone -b v2.2.0-rc3 --depth 1 https://github.com/tensorflow/tensorflow.git /tmp/tensorflow;
  71. fi;
  72. if [ "$(uname -m)" = "x86_64" ]; then
  73. cp $(pwd)/extensions/functions/dependencies/tensorflow/amd64/*.so $(pwd)/extensions/functions/tfLite/lib
  74. fi;
  75. if [ "$(uname -m)" = "aarch64" ]; then
  76. cp $(pwd)/extensions/functions/dependencies/tensorflow/arm64/*.so $(pwd)/extensions/functions/tfLite/lib
  77. fi;
  78. CGO_CFLAGS=-I/tmp/tensorflow CGO_LDFLAGS=-L$(pwd)/extensions/functions/tfLite/lib go build -trimpath --buildmode=plugin -o extensions/functions/tfLite/tfLite@$VERSION.so extensions/functions/tfLite/*.go
  79. ;;
  80. * )
  81. go build -trimpath --buildmode=plugin -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/*.go
  82. ;;
  83. esac
  84. }
  85. pre
  86. build
  87. post