Simple project Deployment for Jenkins+docker

Source: Internet
Author: User

How to use Docker to implement the release of new projects, typically in two ways, take a web container as an example:

1: Customize a generic web container image, in logical volume-V mode, associate the WebApp directory to the host, and each time a new version is released, you only need to update the project package for the associated directory on the host (for example, the war package), and then restart the relevant Docker container for the web. Complete the release of the new version.

2: In Dockerfile, each time a new version is released, the corresponding package is passed into the dockerfile, packaged together into a new web container image, stop the old version of the container, and then start the container with a new image. Complete the release of the new version.


Here I want to do a simple automated deployment experiment with Jenkins in a dockerfile way:

First the approximate process on the PO:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/82/25/wKioL1dM-0PhYV94AAByooLmLVU824.png "title=" QQ picture 20160531104215.png "alt=" Wkiol1dm-0phyv94aabyoolmlvu824.png "/>

1: Developers post new code and upload to local gitlab.

2:jenkins started building, pulling in new code, using Dockerfile to get new code into Docker, creating a brand new image, and uploading it to a local Docker private repository.

3: The Project Server pulls the new mirror.

4: Turn off the original container in the running project and use the new mirror to open the container. Project Release Complete


Realize:

Lab Environment:

jenkins:192.168.1.224

Docker Host: 192.168.1.120

Pre-release Status:

Here I use a simple Web page to demonstrate a publishing process that the Web container uses resin.

The currently running Docker container information is as follows:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/26/wKiom1dM--bQwYgYAAAdcg3JVcQ550.png "title=" 2.PNG " alt= "Wkiom1dm--bqwygyaaadcg3jvcq550.png"/>

The currently running Web container image is registry.cmh.cn/test:v2, the container name is TEST_V2, and the 8080 port inside the container maps to the 8080 port of the host.

The current page is displayed as follows: (Hello.txt acts as part of the code to be updated in this example)

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/82/25/wKioL1dM_K_CRcPVAAAoAMKHuCg686.png "title=" 1.PNG " alt= "Wkiol1dm_k_crcpvaaaoamkhucg686.png"/>


Experiment Preparation:

1: Configure the Docker private warehouse to install Jenkins. (Not in this blog category)

2:dockerfile, here Dockerfile custom a resin images, the specific configuration and the wording varies from person to person.

# more /opt/scripts/dockerfile/resin/dockerfile  #create  a images of resin  environment. from centos_javamaintainer chenminghui  "[email protected]" run echo  ' RESIN_HOME=/ Opt/apps/resin '  >> /etc/profile && echo  ' path= $PATH: $JAVA _home/bin/:$ Java_home/jre/bin/'  >> /etc/profle && source /etc/profileenv java_ home=/opt/apps/jdk1.8.0_51/#copy  files to new imagesADD resin-pro-4.0.42.tar.gz  /opt/apps/run cd /opt/apps/resin-pro-4.0.42 && yum install -y gcc  make.x86_64 openssl.x86_64 openssl-devel.x86_64  && ./configure -- prefix=/opt/apps/resin  --libexecdir=/opt/apps/resin/libexec  --enable-jni -- enable-64bit && make && make installcopy pro.jar /opt/apps/ Resin/lib/ copy gzlife-ad.sh /opt/scripts/resin.shcopy gzlife-ad.xml /opt/conf/resin/copy  /webapps/hello.txt /opt/webapps/          ------- ---here to hello.txt the updated code, to the relevant directory of the image, for resin use. Expose 8080entrypoint sh /opt/scripts/resin.sh start && /bin/bash

  3:jenkins the required build script, where the script is relatively simple, mainly the incoming IP, project, version three parameters. Pull the code, make the image, upload the image, pull the image remotely, and start the container. (Specific script you crossing can write their own, here is just a simple example)

#more  /opt/scripts/devops.sh #!/bin/shIP=$1PROJECT=$2VERSION=$3echo  "########### #git  new  code....############# "cd /opt/scripts/dockerfile/resin/webappsgit pull [email  protected]:chenminghui/cmhtest.gitecho  "################ #build  new images and push  to private registry########### "Docker build -t registry.cmh.cn/test:${version}  /opt/scripts/Dockerfile/resindocker push registry.cmh.cn/test:${VERSION}echo  "########### download new images and start new version of project########## "ssh   $IP   "docker pull registry.cmh.cn/test:${version}" container= ' ssh  $IP   "Docker  ps | grep ${project} " | awk  ' {print $1} ' ssh  $IP  " Docker  stop ${container} "ssh  $IP  " Docker run -idt --name=${project}_${version}  -p 8080:8080 registrY.cmh.cn/test:${version} " 

4:jenkins Create a new build project, as follows: (IP for Web container ip,project as project name, version for release information)

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/25/wKioL1dNANijG12sAABDvAbWzMc204.png "style=" float: none; "title=" 3.PNG "alt=" Wkiol1dnanijg12saabdvabwzmc204.png "/>


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/82/27/wKiom1dM_9zDx0AKAAAQUrBZP0A430.png "style=" float: none; "title=" 4.PNG "alt=" Wkiom1dm_9zdx0akaaaqurbzp0a430.png "/>

Once you're ready, you can start running our build process.


To deploy a new project:

1: Update Hello.txt,push new code to Gitlab.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/82/26/wKioL1dNAfXCwgJtAACNaeaZz3s889.png "title=" 5.PNG " alt= "Wkiol1dnafxcwgjtaacnaeazz3s889.png"/>

2:jenkins fill in the relevant parameters and start building:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/82/27/wKiom1dNAaSwoFB1AACCNtPIVLU160.png "title=" 6.PNG " alt= "Wkiom1dnaaswofb1aaccntpivlu160.png"/>

3: Wait for the build to complete: (see build information)

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/82/27/wKiom1dNAhXAusuRAAAdDtSqLG8563.png "title=" 7.PNG " alt= "Wkiom1dnahxausuraaaddtsqlg8563.png"/>

Build if there is no error, you can see the structure of the success, stating that the build deployment is complete.

4: View page:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/82/27/wKiom1dNAnDx4lkeAAAqQ-vpCM0938.png "title=" 8.PNG " alt= "Wkiom1dnandx4lkeaaaqq-vpcm0938.png"/>

You can see that the new code is already in effect.


5: View Container Run status

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/82/26/wKioL1dNBV3AFgBJAAAp3TzeOUo943.png "title=" 9.PNG " alt= "Wkiol1dnbv3afgbjaaap3tzeouo943.png"/>

You can see that a new container is running, with the name Test_v3 and the mirror using REGISTRY.CMH.CN/TEST:V3. The old version of the container TEST_V2 is closed.

If a new version of the publication has an exception, you can stop test_v3 and start test_v2. This makes it possible to quickly implement a version fallback.


Postscript:

This example is only a simple practice, the production environment is certainly more complex, to the specific project to develop different deployment steps and requirements. But this example can provide a simple idea for everyone to refer to.

This example applies to environments that target a single Web deployment.













This article is from "The Clown who plays God" blog, please make sure to keep this source http://icenycmh.blog.51cto.com/4077647/1784735

Simple project Deployment for Jenkins+docker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.