This practical case explanation ——JAVA How to pass the project Docker Realize continuous deployment ( Just four simple steps ),

Namely : Development passed git push Upload code , through Git and Jenkins coordination , Automate program deployment , release , Operation and maintenance personnel are not required to participate in the whole process .

This is a true container level implementation , The benefits of this , It's not just efficiency , It is also a change :

For the first time, developers are really responsible for their own code —— Finally, we can skip the O & M and testing departments , Self maintenance operation environment ( The first is testing / development environment ).

Difficult people won't , It's not difficult for people to meet . Through simple 4 Configurations , You can achieve continuous deployment gracefully . This article is routinely placed in the table of contents , Please enjoy . Technical idea of continuous deployment

Effect display

to configure Git and Jenkins linkage

to configure Jenkins Automatically update code

Effect graphic explanation

FAQ

ok , We officially begin .

1. Technical idea of continuous deployment

In this case , Suppose we JAVA The name of the project is hello. The brief technical ideas are as follows .

In this case, it is assumed that the code is hosted in git.oschina.com upper ,Jenkins and Docker
Registry( be similar to yum source ) Each running in one Docker In container .JAVA The project itself also runs independently in a place called hello In the container of .

The continuous deployment scheme adopted in this paper , From private Docker
Reistry Pull code . Some flexible solutions , Put the code on the host computer , Let the container read through volume group mapping . The reason why this method is not recommended is , Split code out of container , It's against Docker Container principle of :

This also leads to increased handling complexity . From the perspective of freight workers , The whole is the most economical . such , Only in this way can we realize the real container level migration .

Or say , Container age , Abandon the idea of document distribution in the past , Is the right way . The last question and answer session of this article has more elaboration on this .

Container as process . We adopt the above scheme Docker Reasons and significance of continuous deployment , That's why . Container lifecycle , Should be much shorter than virtual machines , There is a problem with the container , It should be killed immediately , Instead of trying to recover .

2. Effect display

The final effect of this paper , How amazing is it ? Let's see the following demonstration .

2.1 Effect before program code update

We use time stamps for simplicity , Express program updates explicitly .

2.2 Submit program code updates

In this example , We put the timestamp of the home page from 201506181750, Change to 201506191410( See below ).

2.3 Upload new code to Git

Perform the following operations in sequence , Enter the correct git Account password .

so what ?

Then you don't have to do anything . Serve a cup of tea ( If you don't like coffee ), Wait quietly for automatic deployment to occur , Watch a series of automatically triggered processes , Run like a robot ( Please describe later ).

Why 3~5 minute ? Just because in this case JAVA project , Need to come from abroad download
Maven Package , For Jenkins Call and compile JAVA. In the formal application environment , Can put Maven The source is placed in the domestic or computer room . If you just need to PHP Continuous deployment of the project , That's faster .

2.4 View the effect of code update

After waiting quietly for a few minutes , The new code has indeed been automatically deployed .

that , How did all this happen ? Is it complicated ? Otherwise . Just follow these steps , It can be realized quickly .

3. to configure Git and Jenkins linkage

This process is also difficult , It's not difficult for people to meet . It is mainly divided into the following three steps .

3.1 Jenkins to configure Git source

Jenkins New project in java-app, And configure from Git Pull program code . The details are as follows :

3.2 Jenkins Configure remote build

Jenkins Medium configuration token, For git Use when calling remotely .

3.3 Git Open hook

How to let Git After receiving the updated code from the user , Deliver messages and tasks to Jenkins And ? With the help of Git of hook function , Configuration is also very simple , as follows .

4. to configure Jenkins Automatically update code

Jekins Received at Git After the message delivered , Trigger another remote build ( To the target server ), According to the predefined task list , Perform a series of work , Rebuild containers, etc . See below for details :

We put the most critical Shell Extract the script content .

5. Effect graphic explanation

stay 2.3 In this chapter , Our operation at that time was as follows , The purpose is to Git Submit update code .

At that time, he didn't elaborate on the subsequent events , Now that the above has made the principle clear , Then we can talk about what actually happened next .

5.1 Upload code to Git

It seems that the whole process has been completed and smoothly exited . actually , The backstage work has just begun .

This will trigger Git The server sends the corresponding Jenkins The server sends an operation request , This work is too fast , There's nothing to say , Let's see next Jenkins What are you doing .

5.2 Jenkins Wonderful interaction

1)Jenkins A build task will automatically appear .

2) Let's come in at , Look at the specific operation log . yes , Accepting from Git Task of .

3) download Maven Related software packages ( The process is slow ).

4) After downloading , Start using maven BUILD new hello Project package .

5) Then rebuild Maven container , Build new Image and Push reach Docker In private library .

6) last , Reset Docker Pull up the container . such , It's new again . ha-ha

Technology
Daily Recommendation