@TOC


Recommend personal Docker articles, very detailed

【 Docker container 1】Dockerd details and installation



Build Jdk, Mysql, Nginx, Redis, Tomcat environment based on Docker in one minute



Deploy the SpringBoot project based on Docker



【 Docker container 4】 Build Docker private server based on Docker, and how to use Docker private server details



How to build Maven private server based on Docker, and how to use Maven private server



Build GitLab management code based on Docker



Automatic construction, deployment, testing and monitoring of projects based on Docker installation Jenkins



What is the Jenkins

Jenkins is an open source, user-friendly continuous integration (CI) tool written in the Java language. It provides a platform for sustainable integration, automatic building/testing of software projects, and web interface for monitoring the operation of external tasks

What is the CI/CD

Continuous Integration (CI) is a kind of software development time. Continuous integration emphasizes building and (unit) testing as soon as developers submit new code. Based on the test results, we can determine whether the new code and the original code are correctly integrated.

Continuous Delivery (CD) is to deploy the integrated code to a more realistic operating environment (production-like environment) on the basis of Continuous integration. For example, after we finish unit testing, we can deploy the code to a Staging environment that connects to the database for more tests. If the code is fine, you can continue to deploy manually to production.

The characteristics of Jenkins

1. Open source Java language development continuous integration tools, support CI, CD;

2, easy installation, deployment and configuration: can be installed through YUM, quick installation and deployment through docker containers, configuration and management through the Web interface;

3. Message notification and test report: integrate RSS/E-mail to publish the build result through RSS or generate JUnit/TestNG test report through E-mail notification when the build is completed;

4. Distributed construction: Support Jenkins to enable multiple computers to build/test together;

5. Document identification :Jenkins can track which JAR is generated for which build, which version of JAR is used for which build, etc.

6, rich plug-in support: support extension plug-ins, you can develop tools suitable for your team to use, such as Git, SVN, Maven, Docker and so on.

7. Support continuous project monitoring and log output

Install Jenkins using Docker

1 Install Jenkins using Docker

# docker run -d -p 8080:8080 -p 5000:50000 -v Jenkins_data :/var/jenkins_home Jenkinsci/blueOceanCopy the code

2 Access Jenkins’ IP address plus port 8080

Disable the 8080 firewallNote: Jenkins will wait about 3-10 minutes while loading during the first boot. The picture below appears.

3 the unlock Jenkins

Enter Jenkins containers for password # docker ps # docker exec - it container id/bin/bash # cat/var/jenkins_home/secrets/initialAdminPasswordCopy the code

Enter the unlock password copied aboveClick install the recommended plug-inJust wait for it to be doneIt will take about 3-10 minutes

4 Create a user

Type it out yourselfClick startThe picture below is successful

Jenkins Global tool configuration

1 configuration JDK

# docker ps # docker exec -it /bin/bash # echo $JAVA_HOMECopy the code

The clickJAVA_HOME = JAVA_HOME = JAVA_HOME = JAVA_HOME = JAVA_HOMEAfter filling in, click Save

Configure the Maven 2

For Maven, just click auto Install

3. Configure the Maven plug-in for the project

The one above is the global Jenkins Maven plug-in. Here I am the Maven plug-in that needs to be configured for the project. Most of the current projects are Maven projects, so they need to be downloaded online during deployment.

Search for the plug-in name: Maven IntegrationCopy the code

Restart after you select installJust wait for it to finish

Automatically package the SpringBoot project using Jenkins

1 Create a SpringBoot project

I just checked WEB developmentAdd this little bit of code

package com.example.demo.api;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestApi {

    @RequestMapping("/test")
    public String test(a){
        System.out.println("Automated Build, deploy, test, and monitor projects based on Docker Installation Jenkins");
        return "Automated Build, deploy, test, and monitor projects based on Docker Installation Jenkins"; }}Copy the code

Port number: 5656Run the visit and see:

2 upload the project to GitLab

Upload using Git, IDEA, or Eclipse to GitLab

Git bash = Git bash = Git bash

Build GitLab management code based on Docker

The whole project comes packaged:

3 Jenkins implements automatic deployment of Springboot project

1 Create a publish task

Select the Maven project and click OK

Note: If there is no Maven option, the above is not completed:3 Configure the Maven plug-in for the project.

2 Configure the Git address and account password

Once you’ve done that, scroll down to source control and click GitConfigure the address parameters insideCopy the above:http://120.77.0.58/root/springboot_test.git

I added the port number here is a little different, I added the port number, because port 80 of my server is not open, I used the port number of my GitLab, if the firewall developed port 80, there is no need to add the port numberWhen configuring the username and password:ID and description need not be filled in, just need to fill in the correct address and username passwordHas yet to be completedStill unfinished!

3 Configure automatic item packaging

Then move down to Build

Fill in the clean installCopy the code

Before I hit SaveWhen finished, click on the build immediatelyClick in the lower left cornerSelect the console to view the packaged logs Here’s what success looks like:The first build can take a long time because some dependent JAR packages need to be downloaded

Finished: SUCCESS. Finished: FAILURECopy the code

ERROR: Maven JVM terminated with exit code 137Because maven is running out of memory, you can run the top command to shut down large processes:Description of the TOP command

4 Locate the project Jenkins packed

Jenkins’ packaged items are in the Jenkins container in Docker. To find the packaged items, you must enter the container to view them

Input: # docker ps # docker exec - it container id/bin/bash # CD/var/jenkins_home/workspace/springboot_test/target / # lsCopy the code

The JAR package can run directly in the Docker container, but we don’t want to run it in the container. We want to realize automatic running after packaging in the visual Jenkins


Use Jenkins to implement package and execute SHLL script to deploy project

1. Choose a project2. Click Configure3. Scroll down to Post Steps and select Add Shall script4, configuration script configuration :(need to modify the first four) service name, Jar package name, Jar package path, Jar package pathIt is recommended to redo the console output to copy and paste up

#! SERVER_NAME=springboot_test SERVER_NAME=springboot_test SERVER_NAME=springboot_test The WAR package can be moved to the Tomcat webapps directory to run, using the JAR package, In Java - jar command execution JAR_NAME = demo - 0.0.1 - the SNAPSHOT JAR_PATH = # source jar path/var/jenkins_home/workspace/springboot_test/target / JAR_WORK_PATH = / var/jenkins_home/workspace/springboot_test/target/echo "query process id - > $SERVER_NAME" PID = ` ps - ef | grep "|" $SERVER_NAME awk '{print $2}' ` echo "get process ID: $PID" echo "for id in $PID do kill -9 $id echo "killed" $ID" done echo "Stop the process finish" echo "copy jar package to execution directory :cp Jar $JAR_WORK_PATH" cp $JAR_PATH/$jar_name. jar $JAR_WORK_PATH echo "Copy jar package completed" CD $JAR_WORK_PATH Chmod 755 $JAR_NAME. Jar BUILD_ID=dontKillMe nohup java -jar $JAR_NAME.jar & java -jar $JAR_NAME.jarCopy the code

5. Click “Build immediately” after saving:Success!

Configure the Docker container to map extranet access

Input: # docker ps # docker exec - it container id/bin/bash # CD/var/jenkins_home/workspace / # springboot_test/target/psCopy the code

The configuration is complete.

However, it cannot be accessed from the external network, even if the firewall is closed. It is necessary to re-map the port number of Jenkins container in Docker

1 Set the Jenkins container mapping port number

1. Restart the container

Enter systemctl restart dockerCopy the code

2. Clear containers that are not running

Enter docker run -d -p 8080:8080 -p 5656:5656 -p 505:50000 -v jenkins_data:/var/jenkins_home Jenkinsci/blueOceanCopy the code

Port number 5656 is my project port number

2 Rebuild the project

Wait for the reboot to complete and build immediately at the second clickWait for the build to complete

Extranet access test

Enter: IP address + port number + interface pathDone!

What is an automated deployment project

1. The current project input looks like this:2, modify the source code

3. Use Git to resubmit the project4. Click close and click Build5. Visit here to viewSuccess!