Chapter forty micro-services CICD (5) - gitlab + jenkins + docker + dockerregsitry

First, the overall process

deploy:

  • Development machine (mac)
    • ip:11.11.11.11
    • docker:1.12.1
  • Deployment machine (centos7)
    • ip:10.211.55.4
    • docker:1.12.3
  • Production machine (centos7)
    • ip:10.211.55.3
    • docker: 1.10.3 (when installed k8s1.4 comes installed version)

The overall process:

  • After the development of machine development code submitted to gitlab
  • After triggering by webhook plug constructed jenkins, jenkins labeled docker code image, push the docker-registry,
  • After pushing the image to the production machine. (After introduction K8S, push the mirror into the cloud, the cloud dispensing machines themselves)
    • This step is not here, and after the introduction of k8s before making

Two, gitlab installation

Three, jenkins installation

Four, gitlab notice jenkins build

Five, docker-registry installation

1, the deployment machine (download the image, boot image)

  • docker pull hub.c.163.com/library/registry:latest
  • docker tag 0bb8b1006103 registry
  • docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry registry
    • The default storage directory: / var / lib / registry

2, the development machine

  • First set --insecure-registry (three cases described here)
  • After mirrored to push registry

2.1、mac:

Description: Set insecure registry as otherwise there is a problem https, resulting in not push and pull, after "apply restart" just fine.

  • docker push 10.211.55.4:5000/zhaojigang/jdk8:c7_j8
  • ps -ef | grep docker docker look at the process of setting options no success

2.2、docker1.10.3

OPTIONS modified in / etc / sysconfig / docker in = '- selinux-enabled = false --insecure-registry = 10.211.55.4: 5000'

Modified

  • systemctl daemon-reload
  • systemctl restart docker
  • ps -ef | grep docker docker look at the process of setting options no success

2.3、docker1.12.3

Modify ExecStart = / usr / bin / dockerd --insecure-registry = 10.211.55.4 in the /lib/systemd/system/docker.service: 5000

  • systemctl daemon-reload
  • systemctl restart docker
  • ps -ef | grep dockerd look docker process options set no success

3, the production machine

If necessary to pull the pull Registry mirror, also provided like the upper required, then it may pull.

Six, gitlab

七、jenkins

1, "System Management" -> "System Settings" (already set up): forty-first chapter jenkins + gitlab + webhooks + publish- over-ssh (1)

2, project configuration:

2.1、general

Project Name: myservice1-docker (in fact artifactid project)

2.2, source code management

2.3, build trigger

2.4、Build

  • package: labeled jar package
  • docker: build: beaten Mirror
  • docker: push: push mirrored PW

Eight local development code

1, pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>  2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  3  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  4  5 <modelVersion>4.0.0</modelVersion>  6  7 <groupId>com.xxx</groupId>  8 <artifactId>myservice1-docker</artifactId>  9 <version>1.0-SNAPSHOT</version> 10 11 <properties> 12 <java.version>1.8</java.version><!-- 官方推荐 --> 13 <docker.registry>10.211.55.4:5000</docker.registry> 14 <push.image>true</push.image> 15 </properties> 16 17 <parent> 18 <groupId>org.springframework.boot</groupId> 19 <artifactId>spring-boot-starter-parent</artifactId> 20 <version>1.3.5.RELEASE</version> 21 </parent> 22 23 <!-- 引入实际依赖 --> 24 <dependencies> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-web</artifactId> 28 </dependency> 29 <dependency> 30 <groupId>org.springframework.boot</groupId> 31 <artifactId>spring-boot-starter-actuator</artifactId> 32 </dependency> 33 </dependencies> 34 35 <build> 36 <plugins> 37 <plugin> 38 <groupId>org.springframework.boot</groupId> 39 <artifactId>spring-boot-maven-plugin</artifactId> 40 </plugin> 41 <plugin> 42 <groupId>com.spotify</groupId> 43 <artifactId>docker-maven-plugin</artifactId> 44 <version>0.4.13</version> 45 <configuration> 46 <imageName>${docker.registry}/${project.groupId}/${project.artifactId}:${project.version}</imageName> 47 <dockerDirectory>${basedir}/src/main/docker</dockerDirectory> 48 <pushImage>${push.image}</pushImage> 49 <resources> 50 <resource> 51 <!-- ${project.build.directory},项目构建输出目录,默认为target/ --> 52 <directory>${project.build.directory}</directory> 53 <!-- ${project.build.finalName},打包出来的jar名称,默认为${project.artifactId}-${project.version} --> 54 <include>${project.build.finalName}.jar</include> 55 </resource> 56 </resources> 57 </configuration> 58 </plugin> 59 </plugins> 60 </build> 61 </project>

View Code

Description: thirty-eighth chapter springboot + docker (maven)

2、Dockerfile


1 FROM 10.211.55.4:5000/zhaojigang/jdk8:c7_j8

2 3 ADD myservice1-docker-1.0-SNAPSHOT.jar app.jar

4 5 ENV JAVA_HOME /opt/jdk

6 ENV PATH $PATH:$JAVA_HOME/bin

7 8 CMD ["java","-jar","app.jar"]

View Code

Description: The base image is a locally developed good image, after pushing to the remote registry requires: docker push 10.211.55.4:5000/zhaojigang/jdk8:c7_j8

Note: Actually

1 FROM 10.211.55.4:5000/zhaojigang/jdk8:c7_j8
2 ADD myservice1-docker-1.0-SNAPSHOT.jar app.jar

It should not be hard-coded, you should write

1 FROM @docker.registry@/zhaojigang/jdk8:c7_j8
2 ADD @[email protected] app.jar

But we do not succeed! ! !

3、HelloDockerController.java


1 package com.xxx.docker.myservice1.web;

2 3 import org.springframework.web.bind.annotation.RequestMapping;

4 import org.springframework.web.bind.annotation.RestController;

5 6 @RestController 7 @RequestMapping("/docker")

8 public class HelloDockerController {

9 @RequestMapping("/hello")

10 public String helloDocker(){

11 return "hello docker12!!!";

12 }

13 }

View Code

Nine, git commit code

  • git add --all
  • git commit -m"xxx"
  • git push origin HEAD:dev

After check jenkins compile console, you can see, it will hit the mirror, the mirror will be the last push to the remote registry, the future for the machine to pull.

Original articles published 0 · won praise 37 · views 110 000 +

Guess you like

Origin blog.csdn.net/superviser3000/article/details/104231145