From 14190ef94c4eb13041556fb3c9ce04906e83cd71 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 09:19:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=87=BA=E4=BA=8B=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 31 +++ Dockerfile | 10 + pom.xml | 127 +++++++++++ rzl_adapter_run.sh | 30 +++ setup_dev.sh | 27 +++ setup_production.sh | 20 ++ setup_test.sh | 27 +++ .../DipperPositionApplication.java | 24 +++ .../controller/DipperPositionController.java | 30 +++ src/main/resources/bootstrap-dev.yaml | 10 + src/main/resources/bootstrap-pro.yaml | 10 + src/main/resources/bootstrap-test.yaml | 10 + src/main/resources/bootstrap.yaml | 10 + src/main/resources/log/logback-spring.xml | 197 ++++++++++++++++++ 14 files changed, 563 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 pom.xml create mode 100644 rzl_adapter_run.sh create mode 100644 setup_dev.sh create mode 100644 setup_production.sh create mode 100644 setup_test.sh create mode 100644 src/main/java/com/telpo/dipperposition/DipperPositionApplication.java create mode 100644 src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java create mode 100644 src/main/resources/bootstrap-dev.yaml create mode 100644 src/main/resources/bootstrap-pro.yaml create mode 100644 src/main/resources/bootstrap-test.yaml create mode 100644 src/main/resources/bootstrap.yaml create mode 100644 src/main/resources/log/logback-spring.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4dfde6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..839622d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM java:8 +MAINTAINER king <1609724385@qq.com> +VOLUME /tmp +COPY target/dipperposition.jar dipperposition.jar +COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas +ENV TimeZone=Asia/Shanghai +ENV active=dev +ENV JAVA_OPTS="-Xmx256M -Xms256M" +RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone +ENTRYPOINT java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /dipperposition.jar --spring.profiles.active=$active \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3a9aa0a --- /dev/null +++ b/pom.xml @@ -0,0 +1,127 @@ + + + 4.0.0 + com.telpo + dipperposition + 1.0-SNAPSHOT + dipperposition + 北斗定位服务 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.2.5.RELEASE + + + + UTF-8 + UTF-8 + 1.8 + UTF-8 + 2.2.0.RELEASE + Hoxton.RELEASE + true + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.projectlombok + lombok + true + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + org.apache.commons + commons-lang3 + 3.10 + + + + + de.codecentric + spring-boot-admin-starter-client + 2.2.4 + + + + com.alibaba + fastjson + 1.2.28 + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + true + + + + + repackage + + + + + + + \ No newline at end of file diff --git a/rzl_adapter_run.sh b/rzl_adapter_run.sh new file mode 100644 index 0000000..a50a29f --- /dev/null +++ b/rzl_adapter_run.sh @@ -0,0 +1,30 @@ +#!/bin/bash +environment=$1 +version=$2 +echo "环境变量为${environment},版本为$version!" +if [[ ${environment} == 'production' ]]; then + echo "开始远程构建容器" + docker stop dipperposition_service || true + docker rm dipperposition_service || true + docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/rzl_adapter | awk '{print $3}') + docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com + docker pull registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version + docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version + #删除产生的None镜像 + docker rmi -f $(docker images | grep none | awk '{print $3}') + docker ps -a +else +if [[ ${environment} == 'test' ]]; then + #echo "开始远程构建容器" + docker stop dipperposition_service || true + docker rm dipperposition_service || true + + docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}') + docker pull 139.224.254.18:5000/rzl_adapter:$version + docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version + + #删除产生的None镜像 + docker rmi -f $(docker images | grep none | awk '{print $3}') + docker ps -a +fi +fi diff --git a/setup_dev.sh b/setup_dev.sh new file mode 100644 index 0000000..9c709f8 --- /dev/null +++ b/setup_dev.sh @@ -0,0 +1,27 @@ +#!/bin/bash +mvn clean +mvn package -Dmaven.test.skip=true +#image_version=$(date +%Y%m%d%H%M) +image_version=$version +docker stop dipperposition_service || true +docker rm dipperposition_service || true + +# 删除镜像 +docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') + +docker build . -t telpo/rzl_adapter:$image_version + +#TODO:推送镜像到私有仓库 +echo '=================开始推送镜像=======================' +docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version +docker push 139.224.254.18:5000/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' + +#删除产生的None镜像 +docker rmi -f $(docker images | grep none | awk '{print $3}') +# 查看镜像列表 +docker images +# 启动容器 +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +# 查看日志 +# docker logs dipperposition_service diff --git a/setup_production.sh b/setup_production.sh new file mode 100644 index 0000000..7de562d --- /dev/null +++ b/setup_production.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +mvn clean +mvn package -Dmaven.test.skip=true +image_version=$version +# 删除镜像 +docker rmi -f $( + docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service | awk '{print $3}' +) +# 构建telpo/mrp:$image_version镜像 +docker build . -t telpo/dipperposition_service:$image_version +#TODO:推送镜像到阿里仓库 +echo '=================开始推送镜像=======================' +docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com +docker tag telpo/dipperposition_service:$image_version registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$image_version +docker push registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' +#删除产生的None镜像 +docker rmi -f $(docker images | grep none | awk '{print $3}') +# 查看镜像列表 +docker images diff --git a/setup_test.sh b/setup_test.sh new file mode 100644 index 0000000..19c0b24 --- /dev/null +++ b/setup_test.sh @@ -0,0 +1,27 @@ +#!/bin/bash +mvn clean +mvn package -Dmaven.test.skip=true +#image_version=$(date +%Y%m%d%H%M) +image_version=$version +docker stop dipperposition_service || true +docker rm dipperposition_service || true + +# 删除镜像 +docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}') + +docker build . -t telpo/dipperposition_service:$image_version + +#TODO:推送镜像到私有仓库 +echo '=================开始推送镜像=======================' +docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version +docker push 139.224.254.18:5000/dipperposition_service:$image_version +echo '=================推送镜像完成=======================' + +#删除产生的None镜像 +docker rmi -f $(docker images | grep none | awk '{print $3}') +# 查看镜像列表 +docker images +# 启动容器 +docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version +# 查看日志 +# docker logs dipperposition_service diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java new file mode 100644 index 0000000..be9dc30 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java @@ -0,0 +1,24 @@ +package com.telpo.dipperposition; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * @program: gateway + * @description: 网关启动类 + * @author: linwl + * @create: 2020-06-18 16:39 + */ +@SpringBootApplication +@EnableDiscoveryClient +@Slf4j +public class DipperPositionApplication { + + public static void main(String[] args) { + SpringApplication.run(DipperPositionApplication.class, args); + log.info("北斗定位服务启动!"); + } +} diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java new file mode 100644 index 0000000..dd96b62 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -0,0 +1,30 @@ +package com.telpo.dipperposition.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + * @program: DipperPositionController + * @description: 北斗定位 + * @author: linwl + * @create: 2020-07-10 14:01 + */ +@RestController +@Slf4j +public class DipperPositionController { + + @RequestMapping("/getPos") + public String getCampusListJson() { + return "Helle world!"; + } +} diff --git a/src/main/resources/bootstrap-dev.yaml b/src/main/resources/bootstrap-dev.yaml new file mode 100644 index 0000000..6f36d67 --- /dev/null +++ b/src/main/resources/bootstrap-dev.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.16.192.26:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/bootstrap-pro.yaml b/src/main/resources/bootstrap-pro.yaml new file mode 100644 index 0000000..721abc4 --- /dev/null +++ b/src/main/resources/bootstrap-pro.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.19.42.38:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/bootstrap-test.yaml b/src/main/resources/bootstrap-test.yaml new file mode 100644 index 0000000..e8e687a --- /dev/null +++ b/src/main/resources/bootstrap-test.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.19.42.44:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml new file mode 100644 index 0000000..6f36d67 --- /dev/null +++ b/src/main/resources/bootstrap.yaml @@ -0,0 +1,10 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: dipperposition-service + cloud: + nacos: + config: + server-addr: 172.16.192.26:8848 + file-extension: yml \ No newline at end of file diff --git a/src/main/resources/log/logback-spring.xml b/src/main/resources/log/logback-spring.xml new file mode 100644 index 0000000..e461b86 --- /dev/null +++ b/src/main/resources/log/logback-spring.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + debug + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + + + ${log.path}/log_debug.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + debug + ACCEPT + DENY + + + + + + + ${log.path}/log_info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${log.path}/log_warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + warn + ACCEPT + DENY + + + + + + + + ${log.path}/log_error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file