本地机器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #!/bin/bash echo 'building fat jar' git pull mvn clean package -Dmaven.test.skip
echo 'building tarball' image_name='' tag=`date +%s` docker_file_path='' jar_loaction='' properties_location='' resources_location='' server_host='' deploy_script='' key_location='' pod_deploy_script=''
rm -rf ./deploy makdir -p ./deploy/app makdir -p ./deploy/app/config cp ${deploy_script} ./deploy/deploy.sh cp ${docker_file_path} ./deploy/Dockerfile cp ${pod_deploy_script} ./deploy/pod-deploy.sh cp ${jar_loaction} ./deploy/app/app.jar cp ${properties_location} ./deploy/app/config/application.properties cp -r ${resources_location} ./deploy/app tar czvf deploy.tar.gz ./deploy --force-local && rm -f ./deploy
echo 'uploading tarball to server' chmod 600 ${key_location} scp -i ${key_location} ./deploy.tar.gz root@${server_host}:~/deploy.tar.gz && rm -f ./deploy.tar.gz ssh -i ${key_location} root@${server_host} makdir ~/${image_name}-${tag} && tar xzvf ~/deploy.tar.gz -C ~/${image_name}-${tag} && chmod +x ~/${image_name}-${tag}/deploy.sh && bash ~/${image_name}-${tag}/deploy.sh ${image_name} ${tag} localhost 9999 echo 'server is executing'
|
Dockerfile
1 2 3 4 5 6 7 8 9 10 11
| FROM openjdk:8u242-jre ENV LANG=zh_CN.UTF-8 ENV JAVA_TOOL_OPTIONS -Dfile.encoding=UTF-8 RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone EXPOSE 8080 WORKDIR /data HEALTHCHECK --retries=10 --interval=10s --timeout=30s --start-period=30s CMD curl -f -s "" COPY config/* /data/config COPY applaiction.properties /data/ COPY main.jar /data/ CMD ["java","-jar","main.jar","--server.port=8080","--management.server.port=8099"]
|
跳板机
1 2 3 4 5 6 7 8 9 10 11 12 13
| #!/bin/bash image_name=$1 tag=$2 target=$3 port=$4
echo 'building image' podman build -t ${image_name}:${tag} ~/${image_name}-${tag}/deploy/app podman save -o ~/${image_name}-${tag}/pod-${image_name}-${tag}.tar ${image_name}:${tag} podman image rm ${image_name}:${tag} scp ~/${image_name}-${tag}/pod-${image_name}-${tag}.tar root@${target}:~/deploy scp ~/${image_name}-${tag}/deploy/pod-deploy.sh root@${target}:~/deploy/pod-deploy.sh ssh root@${target} chmod +x ~/deploy/pod-deploy.sh && bash ~/deploy/pod-deploy.sh ${image_name} ${tag} ${port}
|
部署机器
1 2 3 4 5 6 7 8 9 10 11 12 13
| #!/bin/bash image_name=$1 tag=$2 port=$3
podman image prune -a echo 'loading image' podman load -i ~/deploy/pod-${image_name}-${tag}.tar echo 'loaded image' podman stop ${image_name} sleep 5 podman run --restart=on-failure:3 -d -p ${port}:8080 --mount type=bind,source=/src/webapp,target=/usr/share/nginx/html --name ${image_name} ${image_name}:${tag} echo 'container started'
|