build.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/data3/yvan-framework
  5. gitUrlArr=(
  6. "http://git.yvanui.com/yvan-private/yvan-framework.git"
  7. "http://git.yvanui.com/jztd/yvan-ext.git"
  8. "http://git.yvanui.com/jztd/thinkingwms-ui.git"
  9. )
  10. branchArr=(
  11. "master"
  12. "master"
  13. "master"
  14. )
  15. positionArr=(
  16. "."
  17. "yvan-ext"
  18. "thinkingwms-ui"
  19. )
  20. # 是否需要构建,-1:自动;0:不需要;1:需要
  21. needBuild=(
  22. "-1"
  23. "-1"
  24. "-1"
  25. )
  26. echoPrefix="\033[36m+"
  27. echoSuffix="\033[0m"
  28. isChange="1" # 仓库是否发生变化,0:未变化;非0:变化
  29. pullCode() {
  30. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  31. path=$1 # 代码保存路径
  32. gitUrl=$2 # git仓库地址
  33. branch=${3:-"master"} # git分支
  34. position=${4:-""} # 使用“.”clone到当前文件夹
  35. isChange="1"
  36. # 创建文件夹
  37. if [ ! -d "$path" ]; then
  38. echo -e "$echoPrefix mkdir -p $path $echoSuffix"
  39. mkdir -p $path
  40. fi
  41. # git clone
  42. echo -e "$echoPrefix cd $path $echoSuffix"
  43. cd $path
  44. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  45. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  46. git clone $gitUrl $position
  47. isChange="2"
  48. fi
  49. # 进入文件夹,切换分支,git pull
  50. if [ "$position" != "" ]; then
  51. echo -e "$echoPrefix cd $position $echoSuffix"
  52. cd $position
  53. fi
  54. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  55. git checkout $branch
  56. echo -e "$echoPrefix git pull $echoSuffix"
  57. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
  58. isChange="0"
  59. fi
  60. echo ""
  61. }
  62. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  63. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  64. if [ "${needBuild[idx]}" == "-1" ]; then
  65. needBuild[idx]=$isChange
  66. fi
  67. done
  68. echo "###--代码更新完成--------------------------------------------------------------------------###"
  69. echo ""
  70. buildCode() {
  71. # 构建 yvan-ext
  72. if [ "${needBuild[1]}" != "0" ]; then
  73. echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
  74. cd "$codePath/yvan-ext"
  75. echo -e "$echoPrefix yarn $echoSuffix"
  76. yarn
  77. echo -e "$echoPrefix yarn link $echoSuffix"
  78. yarn link
  79. echo -e "$echoPrefix yarn build $echoSuffix"
  80. yarn build
  81. echo ""
  82. else
  83. echo "yvan-ext 文件未变化"
  84. fi
  85. # 构建 thinkingwms-ui/client
  86. if [ "${needBuild[2]}" != "0" ]; then
  87. echo -e "$echoPrefix cd $codePath/thinkingwms-ui/client $echoSuffix"
  88. cd "$codePath/thinkingwms-ui/client"
  89. echo -e "$echoPrefix yarn $echoSuffix"
  90. yarn
  91. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  92. yarn link yvan-ext
  93. echo -e "$echoPrefix yarn build $echoSuffix"
  94. yarn build
  95. echo ""
  96. else
  97. echo "thinkingwms-ui 文件未变化"
  98. fi
  99. # 构建 java
  100. echo -e "$echoPrefix cd $codePath $echoSuffix"
  101. cd $codePath
  102. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  103. gradle build -x test
  104. echo ""
  105. }
  106. buildCode
  107. echo "###--代码构建完成--------------------------------------------------------------------------###"
  108. echo ""
  109. logPath=/data3/thinkingwms_nohup.log
  110. dirPath=/data3/yvan-framework/thinkingwms-ui/thinkingwms-backend/build/libs/
  111. serverName=dsl_thinkingwms_ui
  112. cmd=$1
  113. profiles=${2:-"test"}
  114. #-------------------------------------------------------------------
  115. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
  116. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  117. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  118. #-------------------------------------------------------------------
  119. startServer() {
  120. pid=$1
  121. if [ -z $pid ];then
  122. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  123. cd $dirPath
  124. echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./thinkingwms-backend-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles >$logPath 2>&1 & $echoSuffix"
  125. java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./thinkingwms-backend-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles >$logPath 2>&1 &
  126. echo "$serverName 启动成功!"
  127. else
  128. echo "$serverName 正在运行..."
  129. fi
  130. echo "查看日志: tail -F $logPath -n 100"
  131. }
  132. stopServer() {
  133. pid=$1
  134. if [ -z $pid ];then
  135. echo "$serverName 未运行"
  136. else
  137. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
  138. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill
  139. echo "$serverName 已停止!"
  140. fi
  141. }
  142. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  143. if [ ! -z $pid ];then
  144. stopServer $pid
  145. sleep 3s
  146. fi
  147. startServer
  148. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/build.sh)