Spring boot docker Jenkins automatic deployment and image upload

Keywords: Java Docker jenkins snapshot SpringBoot

springboot + docker + jenkins automatic deployment project. jenkins, mysql and redis are all operated by docker without using virtual machine. They are running on Alibaba cloud server (centos7)

1. Don't talk about the preparatory work

2. Create a new Dockerfile in the root directory of the project

The contents of the Dockerfile file are:

#base image 
FROM openjdk:12
MAINTAINER demo <demo@qq.com>

#Specify the configuration file and the path of the jar package on the server
ENTRYPOINT ["java","-Dspring.profiles.active=prod","-jar","/lcy/work/tools/tools.jar"]
#Exposed port

3. Find a directory on the server and create a new. sh file

echo '================Start building images=============='
#Image name
#Packed at jenkins address
#Address of Dockerfile to execute jar package

echo '================copy JAR package==================='
echo $SOURCE_PATH/target/tools-0.0.1-SNAPSHOT.jar
cp $SOURCE_PATH/target/tools-0.0.1-SNAPSHOT.jar $BASE_PATH/tools.jar
chmod -R 777 $BASE_PATH/tools.jar
echo '================copy complete===================='

echo '================current docker Edition=============='
docker -v

echo '================Build image start================'
docker build -t $IMAGE_NAME -f $SOURCE_PATH/Dockerfile .
echo '================End of building image================'
#Enter the address to push the image, and copy it according to the address prompted by the image warehouse
echo '================Push image start================'
docker login --username=??? --password=??? registry-vpc.cn-beijing.aliyuncs.com
docker push $IMAGE_NAME
echo '================Push image end================'

echo '================Get container id=================='
CID=$(docker ps | grep "$IMAGE_NAME" | awk '{print $1}')
echo container id=$CID

echo '================Get image id=================='
IID=$(docker images | grep "$IMAGE_NAME" | awk '{print $3}')
echo image id=$IID

if [ -n "$CID" ]; then
    echo existence $IMAGE_NAME container,Stop container and delete
    docker stop tools
    docker rm tools
    echo non-existent $IMAGE_NAME container,Start up
    docker run -p 8092:8092 -d --name tools -v $BASE_PATH:$BASE_PATH $IMAGE_NAME

4. Configure jenkins, execute the new. sh file (remember to give permission), and other configurations will not be mentioned, such as github configuration

5. Operation results

This article is based on the platform of blog one article multiple sending OpenWrite release!

Posted by MyWebAlias on Mon, 04 May 2020 02:13:46 -0700