diff --git a/yxt-hen/build.sh b/yxt-hen/build.sh new file mode 100644 index 0000000..9c7f3fc --- /dev/null +++ b/yxt-hen/build.sh @@ -0,0 +1,267 @@ +#!/bin/bash +#set -x +set -e + +codePath=~/ws/yxt_lmis_hen +pushPath=~/build/yxt_lmis_hen +pushGitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_hen.git +pushPath_2=~/build/yxt_lmis_report_hen +pushGitUrl_2=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_report_hen.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" + "hen_2022_04_18" +) +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 "" + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt-hen/build.sh) diff --git a/yxt-hen/deploy-lims-report.sh b/yxt-hen/deploy-lims-report.sh new file mode 100644 index 0000000..f7ce2fc --- /dev/null +++ b/yxt-hen/deploy-lims-report.sh @@ -0,0 +1,128 @@ +#!/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_report_hen.git +dirPath=~/deploy/yxt_lmis_report_hen +serverName=yxt_hen_report +logPath=~/logs/yxt_lmis_report_hen_nohup.log + +cmd=$1 +profiles=${2:-"yxt-hen-prod"} +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +#------------------------------------------------------------------- +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 ./app-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8786 >$logPath 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./app-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8786 >$logPath 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 + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt-hen/deploy-lims-report.sh) [cmd profiles] diff --git a/yxt-hen/deploy-lims.sh b/yxt-hen/deploy-lims.sh new file mode 100644 index 0000000..2d045f4 --- /dev/null +++ b/yxt-hen/deploy-lims.sh @@ -0,0 +1,128 @@ +#!/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_hen.git +dirPath=~/deploy/yxt_lmis_hen +serverName=yxt_hen_lmis +logPath=~/logs/yxt_lmis_hen_nohup.log + +cmd=$1 +profiles=${2:-"yxt-hen-prod"} +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx4g -Xms4g" +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=8110 >$logPath 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=8110 >$logPath 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 + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt-hen/deploy-lims.sh) [cmd profiles]