diff --git a/dsl/001sync_code.sh b/dsl/001sync_code.sh new file mode 100644 index 0000000..1319b36 --- /dev/null +++ b/dsl/001sync_code.sh @@ -0,0 +1,208 @@ +#!/bin/bash +#set -x +set -e + +source_path=/home/www/sync_code/sd_dsl/wms85std +source_git=( + "www@git.yvanui.com:jztd/wms85std.git" + "www@git.yvanui.com:lizhiwei/yvan-framework.git" + "www@git.yvanui.com:luoyifan/yvan-ui.git" +) +source_branch=( + "sd_dsl2" + "8.6" + "master" +) +source_position=( + "." + "yvan-framework" + "yvan-ui" +) + +target_path=/home/www/sync_code/sd_dsl/wms85std-sd +target_git=www@git.yvanui.com:lizhiwei/wms85std-sd.git +target_branch=main +target_position=. + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + # 创建文件夹 + 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 + 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 checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ]; then + echo "" + fi + echo "" +} + +source_pull() { + for ((idx=0; idx<${#source_git[@]}; idx++)); do + pullCode $source_path ${source_git[idx]} ${source_branch[idx]} ${source_position[idx]} + done +} + +source_build() { + # 构建 java + echo -e "$echoPrefix cd $source_path $echoSuffix" + cd $source_path + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" + + # 构建 yvan-ui + echo -e "$echoPrefix cd $source_path/yvan-ui $echoSuffix" + cd $source_path/yvan-ui + echo -e "$echoPrefix yarn install $echoSuffix" + yarn install + echo -e "$echoPrefix yarn run build_only $echoSuffix" + yarn run build_only +} + +target_pull() { + pullCode $target_path ${target_git} ${target_branch} ${target_position} +} + +target_build() { + # 构建 java + echo -e "$echoPrefix cd $target_path $echoSuffix" + cd $target_path + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" +} + +sync_files() { + echo -e "$echoPrefix 开始同步: $source_path $echoSuffix" + rsync -azr --progress --delete \ + --exclude '.git/' \ + --exclude '.gradle/' \ + --exclude '.httpCache/' \ + --exclude '.idea/' \ + --exclude 'logs/' \ + --exclude 'build/' \ + --exclude 'out/' \ + --exclude 'libs/' \ + --exclude 'node_modules/' \ + --exclude 'yvan-framework/' \ + --exclude 'yvan-ui/' \ + --exclude 'yvan-ui-dist/' \ + --exclude 'build.gradle' \ + --exclude 'settings.gradle' \ + --exclude 'application*' \ + --exclude 'bootstrap*' \ + --exclude 'wms-print/' \ + --exclude 'generated/' \ + --exclude 'generated_tests/' \ + --exclude '*.bpmn' \ + --exclude 'wms-modules/yvan-studio/' \ + --exclude 'gradle.properties' \ + --exclude 'gradle-wrapper.properties' \ + --exclude 'Dockerfile*' \ + $source_path/ $target_path + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 开始同步 $source_path/yvan-framework/yvan-studio $echoSuffix" + rsync -azr --progress --delete \ + --exclude '.git/' \ + --exclude '.gradle/' \ + --exclude '.httpCache/' \ + --exclude '.idea/' \ + --exclude 'logs/' \ + --exclude 'build/' \ + --exclude 'out/' \ + --exclude 'libs/' \ + --exclude 'node_modules/' \ + --exclude 'yvan-framework/' \ + --exclude 'src/main/java/' \ + --exclude 'src/main/resources/' \ + --exclude 'src/test/' \ + --exclude 'yvan-ui/' \ + --exclude 'build.gradle' \ + --exclude 'settings.gradle' \ + --exclude 'application*' \ + --exclude 'bootstrap*' \ + --exclude 'generated/' \ + --exclude 'generated_tests/' \ + --exclude '*.bpmn' \ + --exclude 'gradle.properties' \ + --exclude 'gradle-wrapper.properties' \ + --exclude 'Dockerfile*' \ + $source_path/yvan-framework/yvan-studio $target_path/wms-modules + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 开始同步 lib $echoSuffix" + rsync -azr --progress \ + --include '/yvan-*' \ + --include '/wms-core-*' \ + --include '/wms-api-*' \ + --exclude='*' \ + $source_path/wms-modules/wms-system/build/libs/lib/ $target_path/libs + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 开始同步 yvan-ui $echoSuffix" + rsync -azr --progress --delete $source_path/yvan-ui/dist/ $target_path/yvan-ui-dist/dist + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 处理前端资源缓存 $echoSuffix" + version=$(date +_%Y_%m_%d_%H_%M_%S) + echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $target_path/wms-ui/index.html $echoSuffix" + sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $target_path/wms-ui/index.html + echo -e "$echoPrefix sed -i 's|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g' $target_path/wms-ui/index.html $echoSuffix" + sed -i "s|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g" $target_path/wms-ui/index.html + echo -e "$echoPrefix sed -i 's|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g' $target_path/yvan-ui-dist/dist/js/*.js $echoSuffix" + sed -i "s|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g" $target_path/yvan-ui-dist/dist/js/*.js + echo -e "$echoPrefix 处理前端资源缓存-完成 $echoSuffix" +} + +commit_target() { + echo -e "$echoPrefix cd $target_path $echoSuffix" + cd $target_path + echo -e "$echoPrefix git add --all . $echoSuffix" + git add --all . + echo -e "$echoPrefix git commit -m '代码同步' $echoSuffix" + git commit -m '代码同步' + echo -e "$echoPrefix git push origin $target_branch $echoSuffix" + git push origin $target_branch +} + +source_pull +target_pull +source_build +target_pull +sync_files +target_build +commit_target + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/001sync_code.sh) + + + diff --git a/hua_wei_yun/10wms86-test.sh b/hua_wei_yun/10wms86-test.sh index 299afb2..cc1933a 100644 --- a/hua_wei_yun/10wms86-test.sh +++ b/hua_wei_yun/10wms86-test.sh @@ -152,6 +152,10 @@ deployPull() { needBuild[idx]=$isChange fi done + echo -e "$echoPrefix cd /home/www/deploy/wms85_sd_test/wms-ui/node_modules/yvan-ui $echoSuffix" + cd /home/www/deploy/wms85_sd_test/wms-ui/node_modules/yvan-ui + echo -e "$echoPrefix git pull $echoSuffix" + git pull echo "###--代码更新完成--------------------------------------------------------------------------###" echo "" } diff --git a/hua_wei_yun/12wms86-sd-test.sh b/hua_wei_yun/12wms86-sd-test.sh index 7e492d8..7162fe1 100644 --- a/hua_wei_yun/12wms86-sd-test.sh +++ b/hua_wei_yun/12wms86-sd-test.sh @@ -156,6 +156,11 @@ deployPull() { cd /home/www/deploy/wms85_sd_test/wms-ui/node_modules/yvan-ui echo -e "$echoPrefix git pull $echoSuffix" git pull + + version=$(date +_%Y_%m_%d_%H_%M_%S) + echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/wms-ui/index.html $echoSuffix" + sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/wms-ui/index.html + echo "###--代码更新完成--------------------------------------------------------------------------###" echo "" } diff --git a/nanyao/test/logistic-front.groovy b/nanyao/test/logistic-front.groovy new file mode 100644 index 0000000..37a3f87 --- /dev/null +++ b/nanyao/test/logistic-front.groovy @@ -0,0 +1,121 @@ +//file:noinspection ALL +pipeline { + agent any + + environment { + projectName = 'logistic-front' + // 源码配置 + gitCredentials = '98b675d5-b623-4b76-85eb-28a6ed865100' + // 构建配置 + baseDir = "${WORKSPACE}/" + dockerImgTag = "$projectName:v$BUILD_NUMBER" + dockerfileTarget = 'test' + // harbor配置 + harborProtocol = 'https://' + harborIP = 'swr.cn-east-3.myhuaweicloud.com' + harborCredentials = credentials('6de05cdf-c772-4658-8e15-94aec51283cd') + harborRepositorie = 'wlyc-dev' + // 部署配置 + imagePullSecrets = 'hw-swr-auth' + k8sNamespace = 'nanyao' + containerPort = '8080' + nodePort = 'false' + logging = 'enable' + // 自定义环境变量 + JAVA_HOME = "/usr/local/jdk1.8.0_321" + NODE_HOME = "/usr/local/node-v14.20.1-linux-x64" + PATH = "$JAVA_HOME/bin:$NODE_HOME/bin:$PATH" + } + + stages { + stage('#检查环境') { + steps { + sh """ + java -version + node -v + helm version + """ + } + } + + stage('#拉取代码') { + steps { + checkout([ + $class : 'GitSCM', + branches : [[name: '*/main']], + userRemoteConfigs: [[url: "https://code.50yc.com/yypt/logistic-master.git", credentialsId: "${gitCredentials}"]], + extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: './']], + ]) + } + } + + stage('#编译项目') { + steps { + sh """ + npm config set registry https://registry.npmjs.org/ + yarn config set registry https://registry.npmjs.org/ -g + cd $baseDir + cd front/public/yvan-ui + git pull + cd $baseDir + cp -r front/public/yvan-ui/ front/node_modules/ + cp -r front/node_modules/yvan-ui/dist/js/ front/public/ + cd $baseDir + cd front + ls -hl + ls -hl public + ls -hl public/yvan-ui + ls -hl node_modules + ls -hl node_modules/yvan-ui + """ + } + } + + stage('#构建镜像') { + steps { + sh """ + cd $baseDir + pwd + sudo docker build -f ./Dockerfile-logistic-front --target $dockerfileTarget -t $dockerImgTag $baseDir + """ + } + } + + stage('#推送镜像') { + steps { + sh 'sudo docker login --username $harborCredentials_USR --password $harborCredentials_PSW $harborProtocol$harborIP' + sh "sudo docker tag $dockerImgTag $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker push $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker rmi $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker rmi $dockerImgTag" + } + } + + stage('#部署服务') { + steps { + sh """ + helm repo add lizw-repo https://gitee.com/LiZhiW/helm-chart/raw/master + helm repo update lizw-repo + """ + script { + def deployCMD = new StringBuilder() + deployCMD.append("helm upgrade --install $projectName lizw-repo/node01") + deployCMD.append(" --namespace $k8sNamespace --create-namespace") + deployCMD.append(" --version 0.0.1") + deployCMD.append(" --set env.CMD_PARAMS=''") + deployCMD.append(" --set image='$harborIP/$harborRepositorie/$dockerImgTag'") + deployCMD.append(" --set imagePullSecrets='$imagePullSecrets'") + deployCMD.append(" --set containerPort='$containerPort'") + deployCMD.append(" --set nodePort='$nodePort'") + deployCMD.append(" --set labels.logging=$logging") + //deployCMD.append(" --set nodeSelector.enable='true'") + //deployCMD.append(" --set nodeSelector.values\\[0\\]='master1'") + //deployCMD.append(" --set nodeSelector.values\\[1\\]='worker1'") + deployCMD.append(" --set livenessProbe.initialDelaySeconds='10'") + deployCMD.append(" --set readinessProbe.initialDelaySeconds='10'") + sh deployCMD.toString() + } + } + } + } +} diff --git a/nanyao/test/logistic-oms.groovy b/nanyao/test/logistic-oms.groovy new file mode 100644 index 0000000..13562be --- /dev/null +++ b/nanyao/test/logistic-oms.groovy @@ -0,0 +1,117 @@ +//file:noinspection ALL +pipeline { + agent any + + environment { + projectName = 'logistic-oms' + // 源码配置 + gitCredentials = '98b675d5-b623-4b76-85eb-28a6ed865100' + // 构建配置 + baseDir = "${WORKSPACE}/" + dockerImgTag = "$projectName:v$BUILD_NUMBER" + dockerfileTarget = 'test' + // harbor配置 + harborProtocol = 'https://' + harborIP = 'swr.cn-east-3.myhuaweicloud.com' + harborCredentials = credentials('6de05cdf-c772-4658-8e15-94aec51283cd') + harborRepositorie = 'wlyc-dev' + // 部署配置 + imagePullSecrets = 'hw-swr-auth' + k8sNamespace = 'nanyao' + containerPort = '8080' + nodePort = 'false' + logging = 'enable' + springProfiles = 'test' + // 自定义环境变量 + JAVA_HOME = "/usr/local/jdk1.8.0_321" + NODE_HOME = "/usr/local/node-v14.20.1-linux-x64" + PATH = "$JAVA_HOME/bin:$NODE_HOME/bin:$PATH" + } + + stages { + stage('#检查环境') { + steps { + sh """ + java -version + node -v + helm version + """ + } + } + + stage('#拉取代码') { + steps { + checkout([ + $class : 'GitSCM', + branches : [[name: '*/main']], + userRemoteConfigs: [[url: "https://code.50yc.com/yypt/logistic-master.git", credentialsId: "${gitCredentials}"]], + extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: './']], + ]) + checkout([ + $class : 'GitSCM', + branches : [[name: '*/main']], + userRemoteConfigs: [[url: "https://code.50yc.com/yypt/logistic-oms.git", credentialsId: "${gitCredentials}"]], + extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: './logistic-oms/']], + ]) + } + } + + stage('#编译项目') { + steps { + sh """ + chmod +x gradlew + ./gradlew build -x test + """ + } + } + + stage('#构建镜像') { + steps { + sh """ + cd $baseDir + pwd + sudo docker build -f ./Dockerfile-logistic-oms --target $dockerfileTarget -t $dockerImgTag $baseDir + """ + } + } + + stage('#推送镜像') { + steps { + sh 'sudo docker login --username $harborCredentials_USR --password $harborCredentials_PSW $harborProtocol$harborIP' + sh "sudo docker tag $dockerImgTag $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker push $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker rmi $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker rmi $dockerImgTag" + } + } + + stage('#部署服务') { + steps { + sh """ + helm repo add lizw-repo https://gitee.com/LiZhiW/helm-chart/raw/master + helm repo update lizw-repo + """ + script { + def deployCMD = new StringBuilder() + deployCMD.append("helm upgrade --install $projectName lizw-repo/java01") + deployCMD.append(" --namespace $k8sNamespace --create-namespace") + deployCMD.append(" --version 0.0.1") + deployCMD.append(" --set env.SPRING_PROFILES='$springProfiles'") + deployCMD.append(" --set env.JAVA_MEM_OPTS='-server -Xms1024m -Xmx1024m'") + //deployCMD.append(" --set env.JAVA_ADD_OPENS='--add-exports=org.graalvm.truffle/com.oracle.truffle.api.interop=ALL-UNNAMED'") + deployCMD.append(" --set image='$harborIP/$harborRepositorie/$dockerImgTag'") + deployCMD.append(" --set imagePullSecrets='$imagePullSecrets'") + deployCMD.append(" --set containerPort='$containerPort'") + deployCMD.append(" --set nodePort='$nodePort'") + deployCMD.append(" --set labels.logging=$logging") + //deployCMD.append(" --set nodeSelector.enable='true'") + //deployCMD.append(" --set nodeSelector.values\\[0\\]='master1'") + //deployCMD.append(" --set nodeSelector.values\\[1\\]='worker1'") + deployCMD.append(" --set livenessProbe.initialDelaySeconds='60'") + deployCMD.append(" --set readinessProbe.initialDelaySeconds='60'") + sh deployCMD.toString() + } + } + } + } +} diff --git a/nanyao/test/logistic-wms.groovy b/nanyao/test/logistic-wms.groovy new file mode 100644 index 0000000..c569876 --- /dev/null +++ b/nanyao/test/logistic-wms.groovy @@ -0,0 +1,117 @@ +//file:noinspection ALL +pipeline { + agent any + + environment { + projectName = 'logistic-wms' + // 源码配置 + gitCredentials = '98b675d5-b623-4b76-85eb-28a6ed865100' + // 构建配置 + baseDir = "${WORKSPACE}/" + dockerImgTag = "$projectName:v$BUILD_NUMBER" + dockerfileTarget = 'test' + // harbor配置 + harborProtocol = 'https://' + harborIP = 'swr.cn-east-3.myhuaweicloud.com' + harborCredentials = credentials('6de05cdf-c772-4658-8e15-94aec51283cd') + harborRepositorie = 'wlyc-dev' + // 部署配置 + imagePullSecrets = 'hw-swr-auth' + k8sNamespace = 'nanyao' + containerPort = '8080' + nodePort = 'false' + logging = 'enable' + springProfiles = 'test' + // 自定义环境变量 + JAVA_HOME = "/usr/local/jdk1.8.0_321" + NODE_HOME = "/usr/local/node-v14.20.1-linux-x64" + PATH = "$JAVA_HOME/bin:$NODE_HOME/bin:$PATH" + } + + stages { + stage('#检查环境') { + steps { + sh """ + java -version + node -v + helm version + """ + } + } + + stage('#拉取代码') { + steps { + checkout([ + $class : 'GitSCM', + branches : [[name: '*/main']], + userRemoteConfigs: [[url: "https://code.50yc.com/yypt/logistic-master.git", credentialsId: "${gitCredentials}"]], + extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: './']], + ]) + checkout([ + $class : 'GitSCM', + branches : [[name: '*/main']], + userRemoteConfigs: [[url: "https://code.50yc.com/yypt/logistic-wms.git", credentialsId: "${gitCredentials}"]], + extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: './logistic-wms/']], + ]) + } + } + + stage('#编译项目') { + steps { + sh """ + chmod +x gradlew + ./gradlew build -x test + """ + } + } + + stage('#构建镜像') { + steps { + sh """ + cd $baseDir + pwd + sudo docker build -f ./Dockerfile-logistic-wms --target $dockerfileTarget -t $dockerImgTag $baseDir + """ + } + } + + stage('#推送镜像') { + steps { + sh 'sudo docker login --username $harborCredentials_USR --password $harborCredentials_PSW $harborProtocol$harborIP' + sh "sudo docker tag $dockerImgTag $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker push $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker rmi $harborIP/$harborRepositorie/$dockerImgTag" + sh "sudo docker rmi $dockerImgTag" + } + } + + stage('#部署服务') { + steps { + sh """ + helm repo add lizw-repo https://gitee.com/LiZhiW/helm-chart/raw/master + helm repo update lizw-repo + """ + script { + def deployCMD = new StringBuilder() + deployCMD.append("helm upgrade --install $projectName lizw-repo/java01") + deployCMD.append(" --namespace $k8sNamespace --create-namespace") + deployCMD.append(" --version 0.0.1") + deployCMD.append(" --set env.SPRING_PROFILES='$springProfiles'") + deployCMD.append(" --set env.JAVA_MEM_OPTS='-server -Xms1024m -Xmx1024m'") + //deployCMD.append(" --set env.JAVA_ADD_OPENS='--add-exports=org.graalvm.truffle/com.oracle.truffle.api.interop=ALL-UNNAMED'") + deployCMD.append(" --set image='$harborIP/$harborRepositorie/$dockerImgTag'") + deployCMD.append(" --set imagePullSecrets='$imagePullSecrets'") + deployCMD.append(" --set containerPort='$containerPort'") + deployCMD.append(" --set nodePort='$nodePort'") + deployCMD.append(" --set labels.logging=$logging") + //deployCMD.append(" --set nodeSelector.enable='true'") + //deployCMD.append(" --set nodeSelector.values\\[0\\]='master1'") + //deployCMD.append(" --set nodeSelector.values\\[1\\]='worker1'") + deployCMD.append(" --set livenessProbe.initialDelaySeconds='60'") + deployCMD.append(" --set readinessProbe.initialDelaySeconds='60'") + sh deployCMD.toString() + } + } + } + } +} diff --git a/yxt-db-pg/19wms-test-zz-d110.sh b/yxt-db-pg/19wms-test-zz-d110.sh new file mode 100644 index 0000000..6cb9127 --- /dev/null +++ b/yxt-db-pg/19wms-test-zz-d110.sh @@ -0,0 +1,233 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/wms8_test_zz_d110 +gitUrlArr=( + "http://git.galaxis.yvanui.com/wms8/wms8-bench.git" + "http://git.galaxis.yvanui.com/wms8/wms-core.git" + "http://git.yvanui.com/lizhiwei/yvan-framework.git" +) + +branchArr=( + "pgsql_3" + "pgsql_3" + "pgsql" +) +positionArr=( + "." + "wms-core" + "yvan-framework" +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +"1" +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +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 checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 wms-biz/bundle + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/wms-biz/bundle $echoSuffix" + cd "$codePath/wms-biz/bundle" + 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 "wms-biz/bundle 文件未变化" + fi + + # 构建 wms-biz/pda-client + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/wms-biz/pda-client $echoSuffix" + cd "$codePath/wms-biz/pda-client" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix" + yarn link yvan-ext-mobile + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "wms-biz/pda-client 文件未变化" + fi + + # 构建 java + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd $codePath + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" +} + +logPath=/data/logs/wms8_test_zz_d110/wms8_test_zz_d110.log +dirPath=/home/www/deploy/wms8_test_zz_d110/wms-biz/servo/build/libs/ +serverName=wms8_test_zz_d110 + +cmd=$1 +profiles=${2:-"pg-test-d110"} + +#------------------------------------------------------------------- +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" +#------------------------------------------------------------------- + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix" + cd $dirPath../runtime/ + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8110 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8110 >>/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() { + 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 + # 设置 require_config.js 前端版本 + version=$(date +_%Y_%m_%d_%H_%M_%S) + echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/public/require_config.js $echoSuffix" + sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/public/require_config.js + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + # 重启服务 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + # 移动编译后的文件 + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix rm -rf ../runtime $echoSuffix" + rm -rf ../runtime + echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix" + cp -r ./ ../runtime + echo "" + startServer +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +deployYvanUI() { + bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull + bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: pull deploy restart start stop kill log logs +if [ "$cmd" == "pull" ];then + deployYvanUI + deployPull + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs" + fi +elif [ "$cmd" == "deploy" ];then + deployYvanUI + deployServer $pid +elif [ "$cmd" == "restart" ];then + restartServer $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 restart start stop kill log logs" + else + echo "输入操作参数: pull deploy restart start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# 一心堂 测试 10.0.30.225 +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt-db-pg/19wms-test-zz-d110.sh) [cmd profiles]