build.sh 4.9 KB

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