Docker builds Jenkins and deploys spring cloud services
preface
The following tools are required for Jenkin installation and spring cloud release:
Centos7,docker,docker-compose,harbor,jdk1.8,mvn3.5.4 etc;
Here is only about Docker deploying Jenkins and publishing spring cloud services
Docker installation Jenkins
New docker compose Yaml file
version: '3' services: jenkins-server: image: jenkins/jenkins:lts hostname: jenkins-server container_name: jenkins-server restart: always ports: - 8080:8080 volumes: - ./jenkins/data:/var/jenkins_home - ./jenkins/war:/usr/share/jenkins/ - /usr/local/jdk1.8.0_311:/usr/local/jdk1.8.0_311 - /usr/local/apache-maven-3.8.4:/usr/local/apache-maven-3.8.4 - /home/mavenHome:/home/mavenHome networks: dell-net: ipv4_address: 172.19.0.18 # Custom network segment networks: dell-net: ipam: config: - subnet: 172.19.0.0/24
be careful:
volumes:
-
jenkins_home,jenkins starts the war package, and the host jdk,mvn,mvn local warehouse is mounted in the above directory. The reason is that it is troublesome to install various environments inside the container and there are network speed restrictions, so mount it directly after the host is installed;
-
My host directory jenkins is under the home directory, so here's docker - compose Yaml is also in the * * home directory, at the same level as jenkins * *
-
The purpose of attaching the war package path here is to directly put the war package in the war directory of the host machine if Jenkins updates it later;
Run docker compose and start Jenkins
cd /home/ # Start. If docker compose has only one service, do not add the service name after - d docker-compose up -d jenkins-server
be careful:
During startup, please check the startup log of Jenkins. Because Jenkins is started with Jenkins account, the permissions may be insufficient. At this time, you only need to release the permissions of Jenkins and maven local warehouse of the host machine;
chmod 777 /home/jenkins/ chmod 777 /home/mavenHome/
Jenkins configuration
- After Jenkins is installed, visit the browser http://127.0.0.1:8080 , you can see the initialization interface of Jenkins, and just follow the novice operation; You can create your own account or use the default admin;
- After configuration, you can enter the main interface. The following are the three tasks I have configured, which release the back-end, front-end, and manage the startup of some middleware;
- At this point, Jenkins has been installed through Docker, and the next step is to configure their own tasks;
Jenkins deploys spring cloud
Required plug-ins
On the main interface, click - > create task - > select maven project
I put the code on the code cloud. Here, you need to add the global credentials of the code cloud
Package image to harbor
#!/bin/bash # I created a new service folder under the target directory of the project directory, and moved the Dockerfile under the code project directory and the jar package in the target to the service folder to facilitate the packaging and image of docker DOCKERFILE=${WORKSPACE}/target/${module_name} mkdir ${DOCKERFILE} if [ ${module_name} == 'system' ]; then cd ${WORKSPACE}/service/${module_name}/ elif [ ${module_name} == 'resources' ]; then cd ${WORKSPACE}/plugins/${module_name}/ else cd ${WORKSPACE}/${module_name}/ fi cp Dockerfile ${DOCKERFILE}/ cd ${WORKSPACE}/target/ cp ${module_name}.jar ${DOCKERFILE}/
Execute the command remotely and start the service
#!/bin/bash echo '--------------Stop and delete'${module_name}'------------------' docker stop ${module_name} && docker rm ${module_name} echo '--------------Start building'${module_name}'------------------' # Here is the docker compose YML is placed in the code, and the code is pulled down in Jenkins's working directory (current task directory), so I can directly execute it here # If not, you can customize the following docker script cd /home/jenkins/data/workspace/cloud/script docker-compose up -d ${module_name}