Abstract: Manual compilation, packaging, and deployment can no longer meet the needs of data resource center software project development, so
DevOps is introduced to shorten software development delivery time, improve delivery quality, and coordinate the work of development and operation and maintenance personnel. Continuous integration tool Jenkins can automatically download code from sVN/Git, compile, package, and deploy, which saves a lot of repetitive work and improves efficiency. Jenkins can also encapsulate the application and its operating environment in a
Docker image, making software delivery more concise. Integrate the sonar, a quality control tool, to ensure improved quality in the delivery process.
Keywords: continuous integration; JenkinsDocker
1 Overview
In the development of existing software projects in the
data resource center, developers download the latest code from SVN or GitLab, compile, deploy, and test locally, and then manually upload the local jar or war package manually to the test or formal through the command line script Server, execute iava-jar or start web service to complete deployment. In the later stages of project development, because of frequent changes in requirements, there are so many bug fixes that such repetitive activities need to be performed frequently. Leaders and customers also hope to see the latest functions and effects of the project at any time.
Projects deployed in a formal environment often need to be upgraded. Since customers do not want to restart Tomcat when upgrading, developers often directly copy the compiled incremental class and jsp files directly to the Tomcat path. Such operations are very confusing, and many errors are frequently generated.
Whether it is a development or an online project upgrade, a major cry is to reduce the deployment time and errors during the deployment process, and show the latest features in a timely and high-quality manner in front of leaders and customers, so we introduced DevOps. Automating through construction, testing, packaging and deployment, with a view to achieving continuous delivery and deployment, and improving the quality of software project development.
The
microservice project will develop many services in the form of jar packages, and each jar package will be deployed on the same or different servers. Each service will also have its own environment, if you want to install these environments, it is more cumbersome. Therefore, we introduce Docker to encapsulate the service and its operating environment, and take the encapsulated product as a deliverable.
To ensure quality during continuous delivery, we use Sonar, a code quality control tool.
2DevOps introduction
2.1 Why DevOps
DevOps (combination of Development and Operations) is a set of practical methods to shorten the time from system submission to deployment to production environment while ensuring high quality, with IT automation and continuous integration (CI), continuous deployment (CD) Based on it, based on the automatic continuous software delivery process, the behaviors such as compilation, packaging, release, and testing can be more efficient and stable.
In many cases, the programs normally run by project developers on their own computers will have many problems when deployed to the official server. This is due to the differences in configuration and environment between the software development environment and the official operating environment, so you need to ensure that the build product Always in the operating environment.
Developers like to release new code frequently, but operation and maintenance personnel believe that system changes are full of risks and require stability and reliability. The quality of the changes to the system during deployment is important, and all tests must be passed before production. Therefore, DevOps is a high degree of coordination between software development, operation and maintenance, and quality assurance, so as to complete frequent deployments while improving the reliability, stability, and security of the production environment.
Jenkins and Docker are tools that support DevOps behind them.
2.2 Why Jenkins
Continuous integration (Continous Integration) is a simple and repetitive labor. It is time-consuming and labor-intensive to operate by people. Using automated integration technology can quickly build code and automatically test, thereby improving the efficiency and quality of code and saving a lot of manpower.
Developers submit code to Git, automatically build Maven, deploy or publish it into Docker containers, this series of automated processes requires a coordinator, and Jenkin is the coordinator.
Jenkins is an open source continuous integration software that is highly scalable and can be combined with most software, such as Maven, Git, Docker. It does not require too much manual intervention, reduces repetitive work, saves time, and ensures that software can be automatically compiled, deployed, tested, and released at any point in time.
The goal of continuous integration is to get the recently built packages from Jenkins at any time and publish them to the server at any time. If the package can be packaged in a Docker container and automatically released to the server, the delivery efficiency will be improved to a greater extent.
2.3 Why Docker
Different applications in the data resource center will depend on a different operating environment. For example, the JDK version is different, some development languages are different, and the server environment has limitations. It is very troublesome and time-consuming for operation and maintenance personnel to provide a running environment for each application. Therefore, it is necessary for us to encapsulate the service and its operating environment in a
Docker image. To publish the service, simply start the container according to the image, and the delivery method is changed from the application to the Docker image, which is more concise and convenient.
Docker is an open source container engine. Docker containers are a key technology closely related to DevOps. Jenkins can be combined with Docker to automate the release of service images. 3 using Jenkins to achieve automated build and deployment
For traditional Java Web applications, the war package generated by the build, we can deploy this war package to run in the Tomcat container. For the sDringBoot application, the jar package generated by the build, the iar package also contains an embedded Tomcat container, which can be run directly. In this section, we will automatically deploy Jar or War through Jenkins.
1) New Jenkins task
The Maven project selects "Build a maven project", and ordinary projects can select "Build a free-style software project". Then configure to download the code from SVN or Git in source code management.
2) Build trigger
Select Build periodically, we can specify Jenkins to perform tasks at a certain point in time, in order to reduce the pressure on the server, generally choose at night.
3) Perform the build
For Maven projects, just execute the maven command in Build, and for traditional web projects, you can run Ant scripts to build through InvokeAnt.
4) Turn on password-free login
Generally, the deployment server of the application is not the same as the Jenkins server. You need to configure a password-free login between the two servers to allow Jenkins to log in to the remote machine through the SSH service to execute the script. The specific method is not repeated here.
5) Remote deployment to Tomcat
To publish the compiled war package to tomcat, you first need to install the "Deploy to container Plugin" plugin. After the operation, select "Deploy war/earto a container", select container as tomcat, and then configure tomcat's ip as shown below, log in User name, password, war path to be deployed, etc.
The user name and password here must be consistent with tomcat-user.xml in the croft directory of the remote tomcat, and have administrator rights.
6) Remotely execute the deployment script
For the springBoot project, tomcat is embedded, and the jar package can be executed through java-jar. Select Send build artifacts over SSH in Post Steps to configure the target server through Jenkins ssh as shown in the figure below. BUILD_ID=DONT-KILLME is to solve the problem of Jenkins killing child processes.
4Jenkins combined with Docker to achieve automated build and deployment
We want Jenkins to build and start the Docker container automatically. This process is: the code is on Git or SVN. Jenkins downloads the code and calls Ma-yen to execute the build. Jenkins encapsulates the package generated by the build into the Docker image and starts The corresponding Docker containers form the corresponding test or production environment.
4.1 Several concepts of Docker
1) Dockerfile
Docker provides us with script files that can be used to write image build scripts to automate image building.
2) Docker Registry
A mirror registration center can be built locally to manage more and more mirrors.
4.2 Jenkins releases Docker image
Jenkins can also generate Docker images when building applications, and use this
6 Summary
The implementation of DevOps has greatly improved the delivery speed and quality of software projects in the data resource center. Efficient, high-quality, and automated delivery of the latest features is the fastest and continuous to customers and leaders, coordinating development, operation, maintenance and testing personnel. work. Continuous integration tool Jenkins automatically downloads code from Git or SVN, compiles, packages, deploys, and can set the task execution time automatically. Jenkins can integrate Sonar to ensure the quality of the software during the continuous delivery process, and can publish the software build products and their operating environment into Docker images to make the delivery more concise.