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

image.png

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

image.png

Submit program code update

image.png

Upload the new code to Git, after quietly waiting for a few minutes, the new code has indeed been automatically deployed

image.png

accomplish

Jenkins configuration Git source

Create a new project java-app in Jenkins and configure to pull program code from Git. details as follows:

image.png

Jenkins configuration remote build

Configure the token in Jenkins for use in git remote calls

image.png

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

image.png

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:

image.png

The most critical shell script content

image.png

test

Git commit code

image.png

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.

image.png

Look at the specific operation log (receiving tasks from Git)

image.png

Download Maven-related packages (this process is slow)

image.png

After the download is complete, start using the new hello project package of maven BUILD

image.png

Then rebuild the Maven container, build a new Image and Push to the Docker private library

image.png

Finally, pull up the Docker container again

image.png

点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部