Continuous integration (CI) and container management learning notes

Posted by LacOniC on Mon, 01 Nov 2021 18:56:52 +0100

1. DockerMaven plug-in

Microservice deployment method:

  1. Manual deployment: package and generate jar s based on the source code and upload them to the server.
  2. Automatic deployment through Maven plug-in.

1.1 automatic deployment steps of Maven plug-in:

  1. Modify the docker configuration of the host so that it can be accessed remotely. Add - h after ExecStart = in docker.service file tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
vi /lib/systemd/system/docker.service	

  1. Refresh the configuration and restart the service
systemctl daemon-reload
sudo systemctl restart docker
docker start registry
  1. Add the following to the pox.xml file
<build>
    <finalName>dockerDemo</finalName>
    <plugins>
        <!-- springboot maven plug-in unit -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!-- docker plug-in unit -->
        <plugin>
            <!-- Version information -->
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.13</version>
            <!-- configuration information -->
            <configuration>
                <!-- docker Generated image name -->
                <imageName>192.168.2.11:5000/${project.artifactId}:${project.version}</imageName>
                <!-- base image  == Dockerfile Medium FROM jdk1.8 -->
                <baseImage>jdk1.8</baseImage>
                <!-- entry point -->
                <entryPoint>["java","-jar","/${project.build.finalName}.jar"]</entryPoint>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
                <dockerHost>http://192.168.2.11:2375</dockerHost>
            </configuration>
        </plugin>
    </plugins>
</build>

The above configuration will automatically generate Dockerfile files

FROM jdk1.8
ADD dockerDemo.jar /
ENTRIPOINT ["java","-jar","/dockerDemo.jar"]
  1. Under cmd, enter the project to package and upload the image.
mvn clean package docker:build -DpushImage

Example:

[INFO] Building image 192.168.2.11:5000/springboot-demo:0.0.1-SNAPSHOT
Step 1/3 : FROM jdk1.8

 ---> 79f8c221d4f6
Step 2/3 : ADD /dockerDemo.jar //

 ---> d0a85948e94f
Step 3/3 : ENTRYPOINT ["java","-jar","/dockerDemo.jar"]

 ---> Running in ded9a19061e8
Removing intermediate container ded9a19061e8
 ---> 61d57ebbc410
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 61d57ebbc410
Successfully tagged 192.168.2.11:5000/springboot-demo:0.0.1-SNAPSHOT
[INFO] Built 192.168.2.11:5000/springboot-demo:0.0.1-SNAPSHOT
[INFO] Pushing 192.168.2.11:5000/springboot-demo:0.0.1-SNAPSHOT
The push refers to repository [192.168.2.11:5000/springboot-demo]
9f8f970adb5a: Pushed
5739a69f0bb7: Mounted from jdk1.8
f967d613a659: Mounted from jdk1.8
174f56854903: Mounted from jdk1.8
0.0.1-SNAPSHOT: digest: sha256:39f341edef265ddfbfab7227c63ffa12e41862e5601198f7a530cbc29061ab79 size: 1161
null: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  37.979 s
[INFO] Finished at: 2021-11-01T23:16:33+08:00
[INFO] --------------------------------------------------------
  1. Enter the host centos to view the image: docker images
  2. Start container:
docker run -di --name=dockerDemo -p 88:8080 192.168.2.11:5000/springboot-demo:0.0.1-SNAPSHOT
  1. visit: http://192.168.2.11:88/hello

Note: a SpringBoot program is written here.

@RestController
public class HiController {
    @RequestMapping("/hello")
    public String k8s(){
        return "<h1>HELLO</h1> <h1>HUATHY</h1>";
    }
}

2. Continuous integration with Jenkins

2.1 what is continuous integration

  1. Continuous integration, CI for short
  2. How to better work together to ensure the quality of software development. Agile development, how to ensure quality in changing requirements.
  3. Continuous integration is a development practice for such problems. Advocacy teams often integrate. Each integration is verified through automatic construction, including automatic compilation, release and testing, so as to find integration errors as soon as possible and enable the team to develop cohesive software faster.
  4. Features of continuous integration:
    • It is an automatic periodic integration testing process, which is automatically completed from code checking out, compilation and construction, test running, result recording, test statistics, etc. without manual intervention.
    • A dedicated integration server is required to perform the integration build.
    • Code hosting tool support is required, eg: GitHub, Gitee, GitLab and Gogs.
  5. Role of continuous integration:
    • Ensure the quality of code submission of team developers and reduce the pressure of software release.
    • Any link in continuous integration is completed automatically without too much manual intervention, which is conducive to reducing repeated processes and saving time, cost and workload.

2.2 introduction to Jenkins

  1. Open source continuous integration tool.
  2. characteristic:
    • Easy to install: java -jar jenkins.war can run. No database required.
    • Easy to configure: provide friendly GUI interface.
    • Change support: Jenkins can obtain the generated code update list from SVN / CVs and output it to the compilation output information.
    • Support permanent connection: users access Jenkins through the web. The web address is permanent and can be used in various documents.
    • Integration E-Mail, RSS, IM: when an integration is completed, these tools can tell the integration results in real time.
    • Junit/TestNG test report: provides detailed test report functions in the form of charts.
    • Support distributed construction: Jenkins can distribute integration construction and other work to multiple computers.
    • File fingerprint information: Jenkins will save construction records such as which jars files are generated in which integration construction, which version of jars files are used in which integration construction;
    • Support for third-party plug-ins: making Jenkins more and more powerful.

//TODO unfinished to be continued

Topics: Operation & Maintenance Docker jenkins