#!/bin/bash set -x KL_FILE="/opt/pro_swagger/project/kl-project/kl-project-zhiying/kl-project-zhiying-c-swagger/target/kl-project-zhiying-c-swagger-1.0.0-SNAPSHOT.jar" KL_DIR="/opt/pro_swagger/project/kl-project/kl-project-zhiying/kl-project-zhiying-c-swagger/target/" JAR_NAME="kl-project-zhiying-c-swagger-1.0.0-SNAPSHOT.jar" TAG=`date +%Y%m%d_%H` cd if [ -f "$KL_FILE" ] then cd $KL_DIR deploy_file=`ls | grep jar$` else echo "JAR FILE NO EXIST" exit 100 fi cd $KL_DIR pwd cat << EOF > pro-swagger_Dockerfile FROM fbff214414b1 ENV TZ=Asia/Shanghai WORKDIR /opt/apps ENV JAVA_OPTS='-Xmx2g -Xms2g -Xss10m -XX:+UseG1GC -Xloggc:/opt/swagger/gclog/gc.log ' COPY $deploy_file /opt/apps expose 9082 VOLUME ["/opt/apps/logs"] CMD ["sh", "-c", "java \$JAVA_OPTS -XX:+UseG1GC -Xloggc:/data/logs/gc.log -jar /opt/apps/$deploy_file --server.port=9082 --spring.profiles.active=pro" ] EOF docker build -t harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG} -f pro-swagger_Dockerfile . docker push harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG} docker rmi -f harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG} echo $TAG echo "***********************images push sucess*************************" echo "******start docker deploy ***" ssh -p 2233 node1 "docker pull harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG}" ssh -p 2233 node2 "docker pull harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG}" node1_port=`ssh -p 2233 node1 "netstat -lntp |grep 9082"` node2_port=`ssh -p 2233 node2 "netstat -lntp |grep 9082"` if [ ! -z "$node1_port" ] && [ ! -z "$node2_port" ] then ssh -p 2233 node1 "docker stop swagger-pro" ssh -p 2233 node1 "docker rm swagger-pro" ssh -p 2233 node1 "docker run -dit --name swagger-pro --net=host -v /data/swagger/logs:/opt/apps/logs -p 9082:9082 -e TZ="Asia/Shanghai" -d harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG}" sleep 10s if [ ! -z "$node2_port" ] then ssh -p 2233 node2 "docker stop swagger-pro" ssh -p 2233 node2 "docker rm swagger-pro" ssh -p 2233 node2 "docker run -dit --name swagger-pro --net=host -v /data/swagger/logs:/opt/apps/logs -p 9082:9082 -d harbor.kuailaizhiying.com/zhiying/swagger_pro:${TAG}" echo -e "\033[42;37m deploy is ok \033[0m" else echo "请检查node1服务是否正常" fi else echo "is swagger no ha runing" fi
标签:滚动,部署,pro,project,ssh,zhiying,docker,swagger From: https://www.cnblogs.com/niwajiang1/p/16906493.html