build-plugins.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. set -euo pipefail
  3. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
  4. PLUGIN_TYPE=$1
  5. PLUGIN_NAME=$2
  6. VERSION=$(git describe --tags --always)
  7. OS=$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g')
  8. pre(){
  9. mkdir -p _plugins/$OS/$PLUGIN_TYPE
  10. if [ $(cat etc/$PLUGIN_TYPE/$PLUGIN_NAME.json | jq -r ".libs") != 'null' ]; then
  11. for lib in $(cat etc/$PLUGIN_TYPE/$PLUGIN_NAME.json | jq -r ".libs[]"); do
  12. go get $lib;
  13. done
  14. fi
  15. }
  16. post(){
  17. if [ -f "etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml" ]; then
  18. cp etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml extensions/$PLUGIN_TYPE/$PLUGIN_NAME;
  19. fi
  20. cd extensions/$PLUGIN_TYPE/$PLUGIN_NAME
  21. zip -r ${PLUGIN_NAME}_$(go env GOARCH).zip .
  22. cd -
  23. mv $(find extensions/$PLUGIN_TYPE/$PLUGIN_NAME -name "*.zip") _plugins/$OS/$PLUGIN_TYPE
  24. }
  25. build(){
  26. case $PLUGIN_NAME in
  27. influx )
  28. go build -trimpath -modfile extensions.mod --buildmode=plugin -tags plugins -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME.go
  29. ;;
  30. tdengine )
  31. if [ "$(uname -m)" = "x86_64" ]; then
  32. 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;
  33. fi;
  34. if [ "$(uname -m)" = "aarch64" ]; then
  35. 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;
  36. fi;
  37. tar -zxvf /tmp/TDengine-client-2.4.0.18.tar.gz
  38. cd TDengine-client-2.4.0.18 && ./install_client.sh && cd -
  39. go build -trimpath -modfile extensions.mod --buildmode=plugin -tags plugins -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME.go
  40. ;;
  41. labelImage )
  42. if [ ! -d "/tmp/tensorflow" ];then
  43. git clone -b v2.2.0-rc3 --depth 1 https://github.com/tensorflow/tensorflow.git /tmp/tensorflow;
  44. fi;
  45. if [ "$(uname -m)" = "x86_64" ]; then
  46. cp $(pwd)/extensions/functions/dependencies/tensorflow/amd64/*.so $(pwd)/extensions/functions/labelImage/lib
  47. fi;
  48. if [ "$(uname -m)" = "aarch64" ]; then
  49. cp $(pwd)/extensions/functions/dependencies/tensorflow/arm64/*.so $(pwd)/extensions/functions/labelImage/lib
  50. fi;
  51. CGO_CFLAGS=-I/tmp/tensorflow CGO_LDFLAGS=-L$(pwd)/extensions/functions/labelImage/lib go build -trimpath -modfile extensions.mod --buildmode=plugin -o extensions/functions/labelImage/labelImage.so extensions/functions/labelImage/*.go
  52. ;;
  53. tfLite )
  54. if [ ! -d "/tmp/tensorflow" ];then
  55. git clone -b v2.2.0-rc3 --depth 1 https://github.com/tensorflow/tensorflow.git /tmp/tensorflow;
  56. fi;
  57. if [ "$(uname -m)" = "x86_64" ]; then
  58. cp $(pwd)/extensions/functions/dependencies/tensorflow/amd64/*.so $(pwd)/extensions/functions/tfLite/lib
  59. fi;
  60. if [ "$(uname -m)" = "aarch64" ]; then
  61. cp $(pwd)/extensions/functions/dependencies/tensorflow/arm64/*.so $(pwd)/extensions/functions/tfLite/lib
  62. fi;
  63. CGO_CFLAGS=-I/tmp/tensorflow CGO_LDFLAGS=-L$(pwd)/extensions/functions/tfLite/lib go build -trimpath -modfile extensions.mod --buildmode=plugin -o extensions/functions/tfLite/tfLite.so extensions/functions/tfLite/*.go
  64. ;;
  65. * )
  66. go build -trimpath -modfile extensions.mod --buildmode=plugin -o extensions/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so extensions/$PLUGIN_TYPE/$PLUGIN_NAME/*.go
  67. ;;
  68. esac
  69. }
  70. pre
  71. build
  72. post