diff --git a/00base/CI-CD/.dockerignore b/00base/CI-CD/.dockerignore new file mode 100644 index 0000000..61057cf --- /dev/null +++ b/00base/CI-CD/.dockerignore @@ -0,0 +1,28 @@ +# IDEA 默认排除的 +*.class +*.log +*.ctxt +.mtj.tmp/ +hs_err_pid* + +# 常见的包文件 +*.zip +*.tar.gz +*.rar +*.ear +*.war + +# 自定义排除的文件 +*.java +*.xml +*.iml +*.properties + +# 自定义排除的文件夹 +.git +.idea +classes +generated-sources +maven-archiver +maven-status +gateway-Gemini.jar diff --git a/00base/CI-CD/Dockerfile b/00base/CI-CD/Dockerfile new file mode 100644 index 0000000..142b859 --- /dev/null +++ b/00base/CI-CD/Dockerfile @@ -0,0 +1,4 @@ +FROM 10.100.166.50:15001/library/jdk:1.8.0_341 as dev +ADD gateway-Gemini-exec.jar app.jar +ENTRYPOINT ["java", "-server", "-jar", "app.jar", "--spring.profiles.active=global", "--server.port=8080"] +EXPOSE 8080 \ No newline at end of file diff --git a/00base/CI-CD/Jenkinsfile.groovy b/00base/CI-CD/Jenkinsfile.groovy new file mode 100644 index 0000000..501fb83 --- /dev/null +++ b/00base/CI-CD/Jenkinsfile.groovy @@ -0,0 +1,73 @@ +String Dockerfile = """ +FROM 10.100.166.50:15001/library/jdk:1.8.0_341 as dev +ADD gateway-Gemini-exec.jar app.jar +ENTRYPOINT ["java", "-server", "-jar", "app.jar", "--spring.profiles.active=global", "--server.port=8080"] +EXPOSE 8080 +""".trim() + +pipeline { + agent any + + environment { + // 源码配置 + git = 'http://git.galaxis.yvanui.com/thinking/thinkingframework.git' + gitCredentials = 'lizw(git.galaxis.yvanui.com)' + // 构建配置 + target = "${WORKSPACE}/cloud/gateway/target" + dockerImgTag = "wms-gateway:v$BUILD_NUMBER" + // harbor配置 + harbor = 'http://10.100.166.50:15001' + harborCredentials = credentials('admin(10.100.166.50:15001)') + harborRepositorie = 'wms' + // 自定义环境变量 + JAVA_HOME = '/home/www/jenkins/jdk1.8.0_341' + MAVEN_HOME = '/home/www/jenkins/apache-maven-3.8.6' + NODE_HOME = '/home/www/jenkins/node-v16.17.0-linux-x64' + PATH = "$JAVA_HOME/bin:$MAVEN_HOME/bin:$NODE_HOME/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin" + } + + stages { + stage('#检查环境') { + steps { + sh 'java -version' + sh 'mvn --version' + } + } + + stage('#拉去代码') { + steps { + checkout([ + $class : 'GitSCM', + branches : [[name: '*/develop']], + userRemoteConfigs: [[url: "${git}", credentialsId: "${gitCredentials}"]], + extensions : [], + ]) + } + } + + stage('#编译项目') { + steps { + sh 'mvn clean package -Dmaven.test.skip=true' + } + } + + stage('#构建镜像') { + steps { + sh """ + cd $target + pwd + echo '$Dockerfile' > Dockerfile + sudo docker build --target dev -t $dockerImgTag $target + """ + } + } + + stage('#推送镜像') { + steps { + sh 'sudo docker login --username $harborCredentials_USR --password $harborCredentials_PSW $harbor' + sh "sudo docker tag $dockerImgTag ${harbor.replaceAll('https?://', '')}/$harborRepositorie/$dockerImgTag" + sh "sudo docker push ${harbor.replaceAll('https?://', '')}/$harborRepositorie/$dockerImgTag" + } + } + } +} diff --git a/00base/CI-CD/wms-gateway.yml b/00base/CI-CD/wms-gateway.yml new file mode 100644 index 0000000..6456d13 --- /dev/null +++ b/00base/CI-CD/wms-gateway.yml @@ -0,0 +1,187 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + deployment.kubernetes.io/revision: "1" + field.cattle.io/creatorId: user-6fxhv + field.cattle.io/publicEndpoints: '[{"addresses":["10.100.166.50"],"port":30188,"protocol":"TCP","serviceName":"wms:wms-gateway-nodeport","allNodes":true}]' + creationTimestamp: "2022-09-23T05:49:52Z" + generation: 2 + labels: + cattle.io/creator: norman + workload.user.cattle.io/workloadselector: deployment-wms-wms-gateway + managedFields: + - apiVersion: apps/v1 + fieldsType: FieldsV1 + fieldsV1: + f:metadata: + f:annotations: + f:field.cattle.io/publicEndpoints: {} + manager: agent + operation: Update + time: "2022-09-23T05:49:52Z" + - apiVersion: apps/v1 + fieldsType: FieldsV1 + fieldsV1: + f:metadata: + f:annotations: + f:deployment.kubernetes.io/revision: {} + f:status: + f:conditions: + .: {} + k:{"type":"Available"}: + .: {} + f:lastTransitionTime: {} + f:lastUpdateTime: {} + f:message: {} + f:reason: {} + f:status: {} + f:type: {} + k:{"type":"Progressing"}: + .: {} + f:lastTransitionTime: {} + f:lastUpdateTime: {} + f:message: {} + f:reason: {} + f:status: {} + f:type: {} + f:observedGeneration: {} + f:replicas: {} + f:unavailableReplicas: {} + f:updatedReplicas: {} + manager: kube-controller-manager + operation: Update + subresource: status + time: "2022-09-23T05:49:52Z" + - apiVersion: apps/v1 + fieldsType: FieldsV1 + fieldsV1: + f:metadata: + f:annotations: + .: {} + f:field.cattle.io/creatorId: {} + f:labels: + .: {} + f:cattle.io/creator: {} + f:workload.user.cattle.io/workloadselector: {} + f:spec: + f:progressDeadlineSeconds: {} + f:replicas: {} + f:revisionHistoryLimit: {} + f:selector: {} + f:strategy: + f:rollingUpdate: + .: {} + f:maxSurge: {} + f:maxUnavailable: {} + f:type: {} + f:template: + f:metadata: + f:annotations: + .: {} + f:cattle.io/timestamp: {} + f:field.cattle.io/ports: {} + f:labels: + .: {} + f:workload.user.cattle.io/workloadselector: {} + f:spec: + f:containers: + k:{"name":"wms-gateway"}: + .: {} + f:image: {} + f:imagePullPolicy: {} + f:name: {} + f:ports: + .: {} + k:{"containerPort":8080,"protocol":"TCP"}: + .: {} + f:containerPort: {} + f:name: {} + f:protocol: {} + f:resources: {} + f:securityContext: + .: {} + f:allowPrivilegeEscalation: {} + f:capabilities: {} + f:privileged: {} + f:readOnlyRootFilesystem: {} + f:runAsNonRoot: {} + f:stdin: {} + f:terminationMessagePath: {} + f:terminationMessagePolicy: {} + f:tty: {} + f:dnsPolicy: {} + f:restartPolicy: {} + f:schedulerName: {} + f:securityContext: {} + f:terminationGracePeriodSeconds: {} + manager: rancher + operation: Update + time: "2022-09-23T05:49:52Z" + name: wms-gateway + namespace: wms + resourceVersion: "77237" + uid: 0a3900e8-060c-4b63-83c0-88bdaca4fd84 +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 10 + selector: + matchLabels: + workload.user.cattle.io/workloadselector: deployment-wms-wms-gateway + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + template: + metadata: + annotations: + cattle.io/timestamp: "2022-09-23T05:49:51Z" + field.cattle.io/ports: '[[{"containerPort":8080,"dnsName":"wms-gateway-nodeport","hostPort":0,"kind":"NodePort","name":"8080tcp01","protocol":"TCP","sourcePort":0}]]' + creationTimestamp: null + labels: + workload.user.cattle.io/workloadselector: deployment-wms-wms-gateway + spec: + containers: + - image: 10.100.166.50:15001/wms/wms-gateway@sha256:6e8c061d45420800a12ea0335e9ecd4c9c2154fd84d2d6554740716255772a45 + imagePullPolicy: Always + name: wms-gateway + ports: + - containerPort: 8080 + name: 8080tcp01 + protocol: TCP + resources: {} + securityContext: + allowPrivilegeEscalation: false + capabilities: {} + privileged: false + readOnlyRootFilesystem: false + runAsNonRoot: false + stdin: true + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + tty: true + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 +status: + conditions: + - lastTransitionTime: "2022-09-23T05:49:52Z" + lastUpdateTime: "2022-09-23T05:49:52Z" + message: Deployment does not have minimum availability. + reason: MinimumReplicasUnavailable + status: "False" + type: Available + - lastTransitionTime: "2022-09-23T05:49:52Z" + lastUpdateTime: "2022-09-23T05:49:52Z" + message: ReplicaSet "wms-gateway-5f8f6fd8c6" is progressing. + reason: ReplicaSetUpdated + status: "True" + type: Progressing + observedGeneration: 2 + replicas: 1 + unavailableReplicas: 1 + updatedReplicas: 1 diff --git a/hua_wei_yun/10wms86-test.sh b/hua_wei_yun/10wms86-test.sh new file mode 100644 index 0000000..67422f7 --- /dev/null +++ b/hua_wei_yun/10wms86-test.sh @@ -0,0 +1,207 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/wms85std_test +gitUrlArr=( + "www@git.yvanui.com:jztd/wms85std.git" + # "http://git.yvanui.com/jztd/wms85std.git" + "www@git.yvanui.com:lizhiwei/yvan-framework.git" + # "http://git.yvanui.com/lizhiwei/yvan-framework.git" + "www@git.yvanui.com:luoyifan/yvan-ui.git" + # "http://git.yvanui.com/luoyifan/yvan-ui.git" +) + +branchArr=( + "master" + "8.6" + "master" +) +positionArr=( + "." + "yvan-framework" + "yvan-ui" +) +# 是否需要构建,-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() { + # 构建 yvan-ui + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/yvan-ui $echoSuffix" + cd "$codePath/yvan-ui" + echo -e "$echoPrefix yarn run init $echoSuffix" + yarn run init + # echo -e "$echoPrefix yarn run dev2 $echoSuffix" + # yarn run dev2 + echo "" + else + echo "yvan-ui 文件未变化" + 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/wms85std_test/server.log +dirPath=/home/www/deploy/wms85std_test/wms/wms-application/build/libs/ +serverName=wms85std_test + +cmd=$1 +profiles=${2:-"test"} + +#------------------------------------------------------------------- +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" +#------------------------------------------------------------------- + +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 ./wms-application-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8004 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./wms-application-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8004 >>/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 + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + # 重启服务 + if [ ! -z $pid ];then + stopServer $pid + sleep 8s + 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 +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: pull deploy restart start stop kill log logs +if [ "$cmd" == "pull" ];then + deployPull + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs" + fi +elif [ "$cmd" == "deploy" ];then + 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 + +# wms85测试 +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/hua_wei_yun/03wms84-test.sh) [cmd profiles]