瀏覽代碼

test-build-gx.sh
test-deploy-lims-gx.sh

lizw 3 年之前
父節點
當前提交
7b08395140
共有 2 個文件被更改,包括 402 次插入0 次删除
  1. 268 0
      yxt/test-build-gx.sh
  2. 134 0
      yxt/test-deploy-lims-gx.sh

+ 268 - 0
yxt/test-build-gx.sh

@@ -0,0 +1,268 @@
+#!/bin/bash
+#set -x
+set -e
+
+codePath=~/ws/yxt_lmis_test_gx
+pushPath=~/build/yxt_lmis_test_gx
+pushGitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_test_gx.git
+pushPath_2=~/build/yxt_lmis_report_test_gx
+pushGitUrl_2=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_report_test_gx.git
+gitUrlArr=(
+  "www@git.yvanui.com:yvan-private/yvan-framework.git"
+  "www@git.yvanui.com:jztd/wms-core.git"
+  "www@git.yvanui.com:jztd/yvan-ext.git"
+  "www@git.yvanui.com:jztd/wms8.git"
+  "www@git.yvanui.com:jztd/yvan-studio.git"
+  "www@git.yvanui.com:jztd/lmis-report-system.git"
+)
+branchArr=(
+  "master"
+  "branch-2022-3-30"
+  "master"
+  "master"
+  "master"
+  "master"
+)
+positionArr=(
+  "."
+  "lmis"
+  "yvan-ext"
+  "wms8"
+  "yvan-studio"
+  "lmis-report-system"
+)
+# 是否需要构建,-1:自动;0:不需要;1:需要
+needBuild=(
+"1"
+"1"
+"1"
+"1"
+"1"
+"1"
+)
+
+echoPrefix="\033[36m+"
+echoSuffix="\033[0m"
+
+buildCode() {
+  # 构建 yvan-ext
+  if [ "${needBuild[3]}" != "0" ]; then
+    echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
+    cd "$codePath/yvan-ext"
+    echo -e "$echoPrefix yarn $echoSuffix"
+    yarn
+    echo -e "$echoPrefix yarn link $echoSuffix"
+    yarn link
+    echo -e "$echoPrefix yarn build $echoSuffix"
+    yarn build
+    echo ""
+  else
+    echo "yvan-ext 文件未变化"
+  fi
+
+  # 构建 lmis/client
+  if [ "${needBuild[2]}" != "0" ]; then
+    echo -e "$echoPrefix cd lmis/client $echoSuffix"
+    cd "$codePath/lmis/client"
+    echo -e "$echoPrefix yarn $echoSuffix"
+    yarn
+    echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
+    yarn link yvan-ext
+    echo -e "$echoPrefix yarn build $echoSuffix"
+    yarn build
+    echo ""
+  else
+    echo "lmis 文件未变化"
+  fi
+
+  # 构建 lmis-report-system/client
+  if [ "${needBuild[6]}" != "0" ]; then
+    echo -e "$echoPrefix cd lmis-report-system/client $echoSuffix"
+    cd "$codePath/lmis-report-system/client"
+    echo -e "$echoPrefix yarn $echoSuffix"
+    yarn
+    echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
+    yarn link yvan-ext
+    echo -e "$echoPrefix yarn build $echoSuffix"
+    yarn build
+    echo ""
+  else
+    echo "lmis-report-system 文件未变化"
+  fi
+
+  # 构建 java
+  echo -e "$echoPrefix cd $codePath $echoSuffix"
+  cd $codePath
+  echo -e "$echoPrefix gradle build -x test $echoSuffix"
+  gradle build -x test
+  echo ""
+}
+
+deployPush() {
+  # 更新push git
+  pullCode $pushPath $pushGitUrl "master" "."
+
+  # 同步 lmis/ent/build/libs
+  echo -e "$echoPrefix rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' $codePath/lmis/ent/build/libs/ $pushPath/ $echoSuffix"
+  rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' "$codePath/lmis/ent/build/libs/" "$pushPath/"
+  echo ""
+
+  # 同步 lmis/client/tsconfig.json
+  echo -e "$echoPrefix rsync -av --delete --include 'tsconfig.json' --exclude '/*' $codePath/lmis/client/ $pushPath/client/ $echoSuffix"
+  rsync -av --delete --include 'tsconfig.json' --exclude '/*' "$codePath/lmis/client/" "$pushPath/client/"
+  echo ""
+
+  # 同步 lmis/client/node_modules
+  echo -e "$echoPrefix rsync -av --delete --exclude 'yvan-ext/' $codePath/lmis/client/node_modules/ $pushPath/client/node_modules/ $echoSuffix"
+  rsync -av --delete --exclude 'yvan-ext' "$codePath/lmis/client/node_modules/" "$pushPath/client/node_modules/"
+  echo ""
+
+  # 同步 lmis/client/public
+  echo -e "$echoPrefix rsync -av --delete $codePath/lmis/client/public/ $pushPath/client/public/ $echoSuffix"
+  rsync -av --delete "$codePath/lmis/client/public/" "$pushPath/client/public/"
+  echo ""
+
+  # 同步 yvan-ext
+  echo -e "$echoPrefix rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' $codePath/yvan-ext/ $pushPath/client/node_modules/yvan-ext/ $echoSuffix"
+  rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' "$codePath/yvan-ext/" "$pushPath/client/node_modules/yvan-ext/"
+  echo ""
+
+  # 同步 lmis/dist
+  echo -e "$echoPrefix rsync -av --delete $codePath/lmis/dist/ $pushPath/dist/ $echoSuffix"
+  rsync -av --delete "$codePath/lmis/dist/" "$pushPath/dist/"
+  echo ""
+
+  # 提交文件
+  echo -e "$echoPrefix cd $pushPath $echoSuffix"
+  cd "$pushPath"
+  if [ -n "$(git config user.name)" ]; then
+      echo -e "$echoPrefix git config user.name 'bot' $echoSuffix"
+      git config user.name 'bot'
+      echo -e "$echoPrefix git config user.email 'bot@git.com' $echoSuffix"
+      git config user.email 'bot@git.com'
+  fi
+  echo -e "$echoPrefix git add -A $echoSuffix"
+  git add -A
+  if [ -n "$(git status -s)" ]; then
+    echo -e "$echoPrefix git commit -am 自动deploy提交 $echoSuffix"
+    git commit -am "自动deploy提交"
+    echo -e "$echoPrefix git push origin master $echoSuffix"
+    git push origin master
+  else
+    echo "文件未变化不需要push"
+  fi
+  echo ""
+
+  #---------------------------------------------------------------------------------------------------------------------
+
+  # 更新push git
+  pullCode $pushPath_2 $pushGitUrl_2 "master" "."
+
+  # 同步 lmis-report-system/app/build/libs
+  echo -e "$echoPrefix rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' $codePath/lmis-report-system/app/build/libs/ $pushPath_2/ $echoSuffix"
+  rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' "$codePath/lmis-report-system/app/build/libs/" "$pushPath_2/"
+  echo ""
+
+  # 同步 lmis-report-system/client/tsconfig.json
+  echo -e "$echoPrefix rsync -av --delete --include 'tsconfig.json' --exclude '/*' $codePath/lmis-report-system/client/ $pushPath_2/client/ $echoSuffix"
+  rsync -av --delete --include 'tsconfig.json' --exclude '/*' "$codePath/lmis-report-system/client/" "$pushPath_2/client/"
+  echo ""
+
+  # 同步 lmis-report-system/client/node_modules
+  echo -e "$echoPrefix rsync -av --delete --exclude 'yvan-ext/' $codePath/lmis-report-system/client/node_modules/ $pushPath_2/client/node_modules/ $echoSuffix"
+  rsync -av --delete --exclude 'yvan-ext' "$codePath/lmis-report-system/client/node_modules/" "$pushPath_2/client/node_modules/"
+  echo ""
+
+  # 同步 lmis-report-system/client/public
+  echo -e "$echoPrefix rsync -av --delete $codePath/lmis-report-system/client/public/ $pushPath_2/client/public/ $echoSuffix"
+  rsync -av --delete "$codePath/lmis-report-system/client/public/" "$pushPath_2/client/public/"
+  echo ""
+
+  # 同步 yvan-ext
+  echo -e "$echoPrefix rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' $codePath/yvan-ext/ $pushPath_2/client/node_modules/yvan-ext/ $echoSuffix"
+  rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' "$codePath/yvan-ext/" "$pushPath_2/client/node_modules/yvan-ext/"
+  echo ""
+
+  # 同步 lmis-report-system/dist
+  echo -e "$echoPrefix rsync -av --delete $codePath/lmis-report-system/dist/ $pushPath_2/dist/ $echoSuffix"
+  rsync -av --delete "$codePath/lmis-report-system/dist/" "$pushPath_2/dist/"
+  echo ""
+
+  # 提交文件
+  echo -e "$echoPrefix cd $pushPath_2 $echoSuffix"
+  cd "$pushPath_2"
+  if [ -n "$(git config user.name)" ]; then
+      echo -e "$echoPrefix git config user.name 'bot' $echoSuffix"
+      git config user.name 'bot'
+      echo -e "$echoPrefix git config user.email 'bot@git.com' $echoSuffix"
+      git config user.email 'bot@git.com'
+  fi
+  echo -e "$echoPrefix git add -A $echoSuffix"
+  git add -A
+  if [ -n "$(git status -s)" ]; then
+    echo -e "$echoPrefix git commit -am 自动deploy提交 $echoSuffix"
+    git commit -am "自动deploy提交"
+    echo -e "$echoPrefix git push origin master $echoSuffix"
+    git push origin master
+  else
+    echo "文件未变化不需要push"
+  fi
+  echo ""
+}
+
+isChange="1"                # 仓库是否发生变化,0未:变化;非0:变化
+pullCode() {
+  # Usage: pullCode "codePath" "gitUrl" "branch" "position"
+  path=$1                   # 代码保存路径
+  gitUrl=$2                 # git仓库地址
+  branch=${3:-"master"}     # git分支
+  position=${4:-""}         # 使用“.”clone到当前文件夹
+  isChange="1"
+  # 创建文件夹
+  if [ ! -d "$path" ]; then
+    echo -e "$echoPrefix mkdir -p $path $echoSuffix"
+    mkdir -p $path
+  fi
+
+  # git clone
+  echo -e "$echoPrefix cd $path $echoSuffix"
+  cd $path
+  if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
+    echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
+    git clone $gitUrl $position
+    isChange="2"
+  fi
+
+  # 进入文件夹,切换分支,git pull
+  if [ "$position" != "" ]; then
+    echo -e "$echoPrefix cd $position $echoSuffix"
+    cd $position
+  fi
+  echo -e "$echoPrefix git checkout $branch $echoSuffix"
+  git checkout $branch
+  echo -e "$echoPrefix git pull $echoSuffix"
+  if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == 1 ]; then
+    isChange="0"
+  fi
+  echo ""
+}
+
+for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
+  pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
+  if [ "${needBuild[idx]}" == "-1" ]; then
+    needBuild[idx]=$isChange
+  fi
+done
+echo "###--代码更新完成--------------------------------------------------------------------------###"
+echo ""
+
+buildCode
+echo "###--代码构建完成--------------------------------------------------------------------------###"
+echo ""
+
+deployPush
+echo "###--文件推送完成--------------------------------------------------------------------------###"
+echo ""
+
+# lmis 云南测试(广西)
+# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt/test-build-gx.sh)

+ 134 - 0
yxt/test-deploy-lims-gx.sh

@@ -0,0 +1,134 @@
+#!/bin/bash
+#time=`date +%Y-%m-%d.%H-%M`
+#set -x
+set -e
+
+gitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_test.git
+dirPath=~/deploy/yxt_lmis
+serverName=yxt_lmis
+logPath=/data/logs/yxt_lmis_sx/yxt_lmis_sx.log
+
+cmd=$1
+profiles=${2:-"yxt-sx-test"}
+echoPrefix="\033[36m+"
+echoSuffix="\033[0m"
+
+# 山西服务的日志位置
+if [ "$profiles" == "yxt-prod" ];then
+  logPath=/data/logs/yxt_lmis_sx/yxt_lmis_sx.log
+fi
+
+#-------------------------------------------------------------------
+JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
+DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
+JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
+#-------------------------------------------------------------------
+
+isChange="1"                # 仓库是否发生变化,0未:变化;非0:变化
+pullCode() {
+  # Usage: pullCode "codePath" "gitUrl" "branch" "position"
+  path=$1                   # 代码保存路径
+  gitUrl=$2                 # git仓库地址
+  branch=${3:-"master"}     # git分支
+  position=${4:-""}         # 使用“.”clone到当前文件夹
+  isChange="1"
+  # 创建文件夹
+  if [ ! -d "$path" ]; then
+    echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix"
+    exit
+  fi
+
+  # git clone
+  echo -e "$echoPrefix cd $path $echoSuffix"
+  cd $path
+  if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
+    echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
+    git clone $gitUrl $position
+    isChange="2"
+  fi
+
+  # 进入文件夹,切换分支,git pull
+  if [ "$position" != "" ]; then
+    echo -e "$echoPrefix cd $position $echoSuffix"
+    cd $position
+  fi
+  echo -e "$echoPrefix git checkout $branch $echoSuffix"
+  git checkout $branch
+  echo -e "$echoPrefix git pull $echoSuffix"
+  if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == 1 ]; then
+    isChange="0"
+  fi
+  echo ""
+}
+
+startServer() {
+  pid=$1
+  if [ -z $pid ];then
+    echo -e "$echoPrefix cd $dirPath $echoSuffix"
+    cd $dirPath
+    echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./ent-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8082 >>/dev/null 2>&1 & $echoSuffix"
+    java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./ent-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8082 >>/dev/null 2>&1 &
+    echo "$serverName 启动成功!"
+  else
+    echo "$serverName 正在运行..."
+  fi
+  echo "查看日志:  tail -F $logPath -n 100"
+}
+
+stopServer() {
+  pid=$1
+  if [ -z $pid ];then
+    echo "$serverName 未运行"
+  else
+    echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
+    ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill
+    echo "$serverName 已停止!"
+  fi
+}
+
+deployPull() {
+  pid=$1
+  if [ -z $pid ];then
+    pullCode $dirPath $gitUrl "master" "."
+  else
+    echo "$serverName 正在运行,必须先stop,再pull"
+  fi
+}
+
+deployServer() {
+  pid=$1
+  if [ ! -z $pid ];then
+    stopServer $pid
+    sleep 3s
+  fi
+  deployPull
+  startServer
+}
+
+logs() {
+  tail -F $logPath -n 100
+}
+
+pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
+# 操作参数: pull deploy start stop kill log logs
+if [ "$cmd" == "pull" ];then
+  deployPull $pid
+elif [ "$cmd" == "deploy" ];then
+  deployServer $pid
+elif [ "$cmd" == "start" ];then
+  startServer $pid
+elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then
+  stopServer $pid
+elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then
+  logs
+else
+  if [ -z $pid ];then
+    echo "$serverName 未运行 | 输入操作参数: pull deploy start stop kill log logs"
+  else
+    echo "输入操作参数: pull deploy start stop kill log logs"
+    echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100"
+  fi
+fi
+
+# lmis 云南测试(广西)
+# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt/test-deploy-lims.sh) [cmd profiles]