第 05章 开发前的准备(5.4)

创建分布式链路追踪cbj-zipkin
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.funtl</groupId>
        <artifactId>cbj-dependencies</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../cbj-dependencies/pom.xml</relativePath>
    </parent>

    <artifactId>cbj-zipkin</artifactId>
    <packaging>jar</packaging>


    <dependencies>
        <!-- Spring Boot Begin -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Spring Boot End -->

        <!-- Spring Cloud Begin -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <!-- Spring Cloud End -->

        <!-- Spring Boot Admin Begin -->
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>
        <!-- Spring Boot Admin End -->

        <!-- ZipKin Begin -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-log4j2</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
        </dependency>
        <!-- ZipKin End -->
    </dependencies>
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>http://192.168.0.15:8081/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>

    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.funtl.cbj.zipkin.ZipKinApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

创建.gitlab-ci.yml

#步骤
stages:
  - build
  - push
  - run
  - clean
#构建
build:
  stage: build
  script:
    - /usr/local/maven/apache-maven-3.5.3/bin/mvn clean package
    - cp target/cbj-zipkin-1.0.0-SNAPSHOT.jar docker
    - cd docker
    - docker build -t 192.168.0.39:5000/cbj-zipkin .

#推送
push:
  stage: push
  script:
    - docker push  192.168.0.39:5000/cbj-zipkin

#启动服务
run:
  stage: run
  script:
    - cd docker
    - docker-compose up -d

#删除多余镜像
clean :
   stage: clean
   script:
     - docker rmi $(docker images -q -f dangling=true)

新建docker目录
新建docker-compose.yml

version: "3.1"
services:
  cbj-zipkin:
      restart: always
      image: 192.168.0.39:5000/cbj-zipkin
      container_name: cbj-zipkin
      ports:
        - 9411:9411

新建Dockerfile文件

FROM openjdk:8-jre

MAINTAINER yuyingliang <1079226090@qq.com>

RUN mkdir /app

COPY cbj-zipkin-1.0.0-SNAPSHOT.jar /app/app.jar

ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar","--spring.profiles.active=test"]


EXPOSE 9411

新建src/main/java目录
新建com.funtl.cbj.zipkin包
新建ZipKinApplication启动类

package com.funtl.cbj.zipkin;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import zipkin.server.internal.EnableZipkinServer;


@SpringBootApplication
@EnableEurekaClient
@EnableZipkinServer
public class ZipKinApplication {
    public static void main(String[] args) {
        SpringApplication.run(ZipKinApplication.class, args);
    }

}

新建resources文件目录
bootstrap.yml

spring:
  cloud:
    config:
      uri: http://localhost:8888
      name: cbj-zipkin
      label: master
      profile: dev

bootstrap-test.yml

spring:
  cloud:
    config:
      uri: http://192.168.0.27:8888
      name: cbj-zipkin
      label: master
      profile: test

bootstrap-prod.yml

spring:
  cloud:
    config:
      uri: http://192.168.0.27:8888
      name: cbj-zipkin
      label: master
      profile: prod

猜你喜欢

转载自blog.csdn.net/weixin_42242494/article/details/82217345
今日推荐