分布式监控平台cbj-admin
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-admin</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-webflux</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-server</artifactId>
</dependency>
<!-- Spring Boot Admin 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.admin.AdminApplication</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-admin-1.0.0-SNAPSHOT.jar docker
- cd docker
- docker build -t 192.168.0.39:5000/cbj-admin .
#推送
push:
stage: push
script:
- docker push 192.168.0.39:5000/cbj-admin
#启动服务
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-admin:
restart: always
image: 192.168.0.39:5000/cbj-admin
container_name: cbj-admin
ports:
- 8084:8084
新建Dockerfile
FROM openjdk:8-jre
MAINTAINER yuyingliang <1079226090@qq.com>
RUN mkdir /app
COPY cbj-admin-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 8084
新建src/main/java
新建com.funtl.cbj.admin包
新建AdminApplication启动类
package com.funtl.cbj.admin;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
@EnableAdminServer
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}
}
在main下新建resources目录
新建bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:8888
name: cbj-admin
label: master
profile: dev
bootstrap-test.yml
spring:
cloud:
config:
uri: http://192.168.0.27:8888
name: cbj-admin
label: master
profile: test
bootstrap-prod.yml
spring:
cloud:
config:
uri: http://192.168.0.27:8888
name: cbj-admin
label: master
profile: prod