build-plugins.sh 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }
  26. post(){
  27. if [ -f "etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml" ]; then
  28. cp etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml extensions/$PLUGIN_TYPE/$PLUGIN_NAME;
  29. fi
  30. cd extensions/$PLUGIN_TYPE/$PLUGIN_NAME
  31. zip -r ${PLUGIN_NAME}_$(go env GOARCH).zip .
  32. cd -
  33. mv $(find extensions/$PLUGIN_TYPE/$PLUGIN_NAME -name "*.zip") _plugins/$OS/$PLUGIN_TYPE
  34. }
  35. build(){
  36. case $PLUGIN_NAME in
  37. influx )
  38. 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
  39. ;;
  40. tdengine )
  41. if [ "$(uname -m)" = "x86_64" ]; then
  42. 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;
  43. fi;
  44. if [ "$(uname -m)" = "aarch64" ]; then
  45. 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;
  46. fi;
  47. tar -zxvf /tmp/TDengine-client-2.4.0.18.tar.gz
  48. cd TDengine-client-2.4.0.18 && ./install_client.sh && cd -
  49. 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
  50. ;;
  51. labelImage )
  52. if [ ! -d "/tmp/tensorflow" ];then
  53. git clone -b v2.2.0-rc3 --depth 1 https://github.com/tensorflow/tensorflow.git /tmp/tensorflow;
  54. fi;
  55. if [ "$(uname -m)" = "x86_64" ]; then
  56. cp $(pwd)/extensions/functions/dependencies/tensorflow/amd64/*.so $(pwd)/extensions/functions/labelImage/lib
  57. fi;
  58. if [ "$(uname -m)" = "aarch64" ]; then
  59. cp $(pwd)/extensions/functions/dependencies/tensorflow/arm64/*.so $(pwd)/extensions/functions/labelImage/lib
  60. fi;
  61. 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
  62. ;;
  63. tfLite )
  64. if [ ! -d "/tmp/tensorflow" ];then
  65. git clone -b v2.2.0-rc3 --depth 1 https://github.com/tensorflow/tensorflow.git /tmp/tensorflow;
  66. fi;
  67. if [ "$(uname -m)" = "x86_64" ]; then
  68. cp $(pwd)/extensions/functions/dependencies/tensorflow/amd64/*.so $(pwd)/extensions/functions/tfLite/lib
  69. fi;
  70. if [ "$(uname -m)" = "aarch64" ]; then
  71. cp $(pwd)/extensions/functions/dependencies/tensorflow/arm64/*.so $(pwd)/extensions/functions/tfLite/lib
  72. fi;
  73. 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
  74. ;;
  75. * )
  76. go build -trimpath --buildmode=plugin -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/*.go
  77. ;;
  78. esac
  79. }
  80. pre
  81. build
  82. post