Process
Development upload code through git push, with the cooperation of Git and Jenkins, program deployment and release are automatically completed, without the participation of operation and maintenance personnel throughout the process
Technical ideas for continuous deployment
In this example, assume that the name of our JAVA project is hello. The brief technical idea is as follows
In this case, it is assumed that the code is hosted on git.oschina.com, and Jenkins and Docker Registry (similar to yum source) each run in a Docker container. The JAVA project itself runs separately in a container called hello.
The continuous deployment scheme adopted in this article is to pull code from the private Docker Reistry. Some workarounds are to put the code on the host and let the container read it through volume group mapping. The reason why this method is not recommended is to split the code out of the container, which violates Docker's container principle:
This also leads to increased loading and unloading complexity. From the perspective of freight workers, the overall situation is the most economical. In this way, a true container-level migration can be realized.
In other words, in the container era, abandoning the thought of file distribution in the past is the right way. The question-and-answer session at the end of this article explains more about this.
The container is the process. The reason and significance of our use of the above solution for Docker continuous deployment lies in this. The life cycle of the container should be much shorter than that of the virtual machine. If there is a problem with the container, it should be killed immediately instead of trying to recover.
Show results
The effect before the program code update
Submit program code update
Upload the new code to Git, after quietly waiting for a few minutes, the new code has indeed been automatically deployed
accomplish
Jenkins configuration Git source
Create a new project java-app in Jenkins and configure to pull program code from Git. details as follows:
Jenkins configuration remote build
Configure the token in Jenkins for use in git remote calls
Git open hook
How to make Git send messages and tasks to Jenkins after receiving the updated code from the user? This is very simple to configure with the help of Git's hook function, as follows
Configure Jenkins to automatically update the code
After receiving the message from Git, Jekins triggers a remote build (to the target server), performs a series of tasks according to the predefined task list, and rebuilds the container. Details are as follows:
The most critical shell script content
test
Git commit code
At this time, the Git server will be triggered to send an operation request to the corresponding Jenkins server. This work is too fast and there is nothing to say. Let’s see what Jenkins does.
Look at the specific operation log (receiving tasks from Git)
Download Maven-related packages (this process is slow)
After the download is complete, start using the new hello project package of maven BUILD
Then rebuild the Maven container, build a new Image and Push to the Docker private library
Finally, pull up the Docker container again
Post comment 取消回复