build.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/data3/thinkingwms-ui
  5. gitUrlArr=(
  6. "http://git.yvanui.com/jztd/thinkingwms-ui.git"
  7. "http://git.yvanui.com/jztd/yvan-ext.git"
  8. "http://git.yvanui.com/jztd/yvan-ext-mobile.git"
  9. )
  10. branchArr=(
  11. "develop"
  12. "master"
  13. "master"
  14. )
  15. positionArr=(
  16. "."
  17. "yvan-ext"
  18. "yvan-ext-mobile"
  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. exit
  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 checkout . $echoSuffix"
  57. git checkout .
  58. echo -e "$echoPrefix git pull $echoSuffix"
  59. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
  60. isChange="0"
  61. fi
  62. echo ""
  63. }
  64. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  65. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  66. if [ "${needBuild[idx]}" == "-1" ]; then
  67. needBuild[idx]=$isChange
  68. fi
  69. done
  70. echo -e "$echoPrefix sed -i 's/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g' $codePath/client/public/login.html $echoSuffix"
  71. sed -i "s/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g" $codePath/client/public/login.html
  72. echo -e "$echoPrefix sed -i 's/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g' $codePath/client/src/ApiConvert.js $echoSuffix"
  73. sed -i "s/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g" $codePath/client/src/ApiConvert.js
  74. echo "###--代码更新完成--------------------------------------------------------------------------###"
  75. echo ""
  76. buildCode() {
  77. # 构建 yvan-ext
  78. if [ "${needBuild[1]}" != "0" ]; then
  79. echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
  80. cd "$codePath/yvan-ext"
  81. # echo -e "$echoPrefix git reset --hard 22f18ac82221b4c6889696d500bfeb2981a2f3e1 $echoSuffix"
  82. # git reset --hard 22f18ac82221b4c6889696d500bfeb2981a2f3e1
  83. echo -e "$echoPrefix yarn $echoSuffix"
  84. yarn
  85. echo -e "$echoPrefix yarn link $echoSuffix"
  86. yarn link
  87. echo -e "$echoPrefix yarn build $echoSuffix"
  88. yarn build
  89. echo ""
  90. else
  91. echo "yvan-ext 文件未变化"
  92. fi
  93. # 构建 yvan-ext-mobile
  94. if [ "${needBuild[1]}" != "0" ]; then
  95. echo -e "$echoPrefix cd $codePath/yvan-ext-mobile $echoSuffix"
  96. cd "$codePath/yvan-ext-mobile"
  97. echo -e "$echoPrefix yarn $echoSuffix"
  98. yarn
  99. echo -e "$echoPrefix yarn link $echoSuffix"
  100. yarn link
  101. echo -e "$echoPrefix yarn build $echoSuffix"
  102. yarn build
  103. echo ""
  104. else
  105. echo "yvan-ext-mobile 文件未变化"
  106. fi
  107. # 构建 thinkingwms-ui/client
  108. if [ "${needBuild[2]}" != "0" ]; then
  109. echo -e "$echoPrefix cd $codePath/client $echoSuffix"
  110. cd "$codePath/client"
  111. echo -e "$echoPrefix yarn $echoSuffix"
  112. yarn
  113. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  114. yarn link yvan-ext
  115. echo -e "$echoPrefix yarn build $echoSuffix"
  116. yarn build
  117. echo ""
  118. else
  119. echo "thinkingwms-ui/client 文件未变化"
  120. fi
  121. # 构建 thinkingwms-ui/pda-client
  122. if [ "${needBuild[2]}" != "0" ]; then
  123. echo -e "$echoPrefix cd $codePath/pda-client $echoSuffix"
  124. cd "$codePath/pda-client"
  125. echo -e "$echoPrefix yarn $echoSuffix"
  126. yarn
  127. echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix"
  128. yarn link yvan-ext-mobile
  129. echo -e "$echoPrefix yarn build $echoSuffix"
  130. yarn build
  131. echo ""
  132. else
  133. echo "thinkingwms-ui/pda-client 文件未变化"
  134. fi
  135. # 构建 java
  136. echo -e "$echoPrefix cd $codePath $echoSuffix"
  137. cd $codePath
  138. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  139. gradle build -x test
  140. echo ""
  141. }
  142. buildCode
  143. echo "###--代码构建完成--------------------------------------------------------------------------###"
  144. echo ""
  145. logPath=/data3/thinkingwms_nohup.log
  146. dirPath=/data3/thinkingwms-ui/thinkingwms-backend/build/libs/
  147. serverName=dsl_thinkingwms_ui
  148. cmd=$1
  149. profiles=${2:-"test_hwy"}
  150. #-------------------------------------------------------------------
  151. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
  152. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  153. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  154. #-------------------------------------------------------------------
  155. startServer() {
  156. pid=$1
  157. if [ -z $pid ];then
  158. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  159. cd $dirPath
  160. 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"
  161. 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 &
  162. echo "$serverName 启动成功!"
  163. else
  164. echo "$serverName 正在运行..."
  165. fi
  166. echo "查看日志: tail -F $logPath -n 100"
  167. }
  168. stopServer() {
  169. pid=$1
  170. if [ -z $pid ];then
  171. echo "$serverName 未运行"
  172. else
  173. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill -9 $echoSuffix"
  174. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill -9
  175. echo "$serverName 已停止!"
  176. fi
  177. }
  178. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  179. if [ ! -z $pid ];then
  180. stopServer $pid
  181. sleep 3s
  182. fi
  183. startServer
  184. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/build.sh)