docker
This commit is contained in:
81
pom.xml
81
pom.xml
@@ -1,22 +1,40 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<version>3.0.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.flagnote</groupId>
|
||||
<artifactId>flagnote-gateway</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.0.1</version>
|
||||
<name>flagnote-gateway</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2022.0.1</spring-cloud.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
|
||||
<spring-cloud.version>2022.0.2</spring-cloud.version>
|
||||
<docker.image.prefix>flagnote</docker.image.prefix>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
|
||||
@@ -29,12 +47,7 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
@@ -45,13 +58,6 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.7.22</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@@ -81,10 +87,51 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<showWarnings>true</showWarnings>
|
||||
<fork>true</fork>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<googleContainerRegistryEnabled>false</googleContainerRegistryEnabled>
|
||||
<dockerHost>http://rancher:42375</dockerHost>
|
||||
<imageName>
|
||||
${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>
|
||||
<dockerDirectory>src/main/docker</dockerDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
8
src/main/docker/dockerfile
Normal file
8
src/main/docker/dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM openjdk:17-slim
|
||||
VOLUME /tmp
|
||||
ADD flagnote-gateway-0.0.1.jar app.jar
|
||||
RUN sh -c 'touch /app.jar'
|
||||
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
|
||||
RUN apt-get update && apt-get install -y curl
|
||||
ENV JAVA_OPTS=""
|
||||
ENTRYPOINT [ "sh", "-c", "exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.flagnote.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
||||
|
||||
import com.flagnote.gateway.config.BkrLoadBalancerConfiguration;
|
||||
|
||||
@SpringBootApplication
|
||||
@LoadBalancerClient(name = "noteCommonService", configuration = BkrLoadBalancerConfiguration.class)
|
||||
@EnableAutoConfiguration
|
||||
@EnableDiscoveryClient
|
||||
@LoadBalancerClient(name = "flagnote-service", configuration = BkrLoadBalancerConfiguration.class)
|
||||
public class GatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
server:
|
||||
# address: 127.0.0.1
|
||||
port: 10000
|
||||
spring:
|
||||
application:
|
||||
name: flagnote-gateway
|
||||
profiles:
|
||||
active: dev
|
||||
# config:
|
||||
# import: 'optional:configserver:http://localhost:9999'
|
||||
data:
|
||||
redis:
|
||||
database: 10
|
||||
host: service.flagnote.com
|
||||
port: 16379
|
||||
timeout: 10000
|
||||
poolMaxTotal: 10
|
||||
poolMaxIdle: 10
|
||||
poolMaxWait: 3
|
||||
password: redis1qazx1qazx
|
||||
codec:
|
||||
max-in-memory-size: 10MB
|
||||
servlet:
|
||||
multipart:
|
||||
# 最大支持文件大小
|
||||
max-file-size: 10MB
|
||||
# 最大支持请求大小
|
||||
max-request-size: 10MB
|
||||
|
||||
cloud:
|
||||
discovery:
|
||||
client:
|
||||
simple:
|
||||
instances:
|
||||
noteCommonService: # 一定要带端口
|
||||
- uri: http://127.0.0.1:20000
|
||||
- uri: http://127.0.0.1:20001
|
||||
keyMetaService: # 一定要带端口
|
||||
- uri: http://127.0.0.1:20000
|
||||
- uri: http://127.0.0.1:20001
|
||||
|
||||
loadbalancer:
|
||||
configurations: health-check
|
||||
health-check:
|
||||
path:
|
||||
noteCommonService: /f2w8u47ie56edc93/actuator/health
|
||||
keyMetaService: /f2w8u47ie56edc93/actuator/health
|
||||
initial-delay: 0
|
||||
interval: 5s
|
||||
inetutils:
|
||||
# 指定此客户端的ip
|
||||
default-ip-address: localhost
|
||||
gateway:
|
||||
# globalcors:
|
||||
# corsConfigurations:
|
||||
# '[/**]':
|
||||
# allowedOrigins: "*"
|
||||
# allowedMethods: "*"
|
||||
routes:
|
||||
- id: keyMeta
|
||||
uri: lb://keyMetaService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/keyMeta
|
||||
- Method=GET
|
||||
filters:
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
# 如果返回的key是空的话,false则不进行限流
|
||||
# deny-empty-key: true
|
||||
# status-code: TOO_MANY_REQUESTS
|
||||
# 每秒产生多少个令牌
|
||||
redis-rate-limiter.replenishRate: 1
|
||||
# 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求
|
||||
redis-rate-limiter.burstCapacity: 10
|
||||
# 每次请求申请几个令牌
|
||||
redis-rate-limiter.requestedTokens: 1
|
||||
# IP 地址限流
|
||||
key-resolver: "#{@remoteAddrKeyResolver}"
|
||||
|
||||
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
# 如果返回的key是空的话,false则不进行限流
|
||||
# deny-empty-key: true
|
||||
# status-code: TOO_MANY_REQUESTS
|
||||
# 每秒产生多少个令牌
|
||||
redis-rate-limiter.replenishRate: 1
|
||||
# 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求
|
||||
redis-rate-limiter.burstCapacity: 10
|
||||
# 每次请求申请几个令牌
|
||||
redis-rate-limiter.requestedTokens: 2
|
||||
# IP 地址限流
|
||||
key-resolver: "#{@remoteSessionKeyResolver}"
|
||||
|
||||
|
||||
|
||||
- id: noteMeta
|
||||
uri: lb://noteCommonService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/noteMeta
|
||||
- Method=GET
|
||||
filters:
|
||||
- ValidateNoteKey
|
||||
- id: getNote
|
||||
uri: lb://noteCommonService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}
|
||||
- Method=GET
|
||||
filters:
|
||||
- ValidateNoteKey
|
||||
- id: saveNote
|
||||
uri: lb://noteCommonService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}
|
||||
- Method=POST
|
||||
filters:
|
||||
- ValidateNoteKey
|
||||
- id: deleteNote
|
||||
uri: lb://noteCommonService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/delete
|
||||
- Method=POST
|
||||
filters:
|
||||
- ValidateNoteKey
|
||||
- id: secretKey
|
||||
uri: lb://noteCommonService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/secretKey
|
||||
- Method=POST
|
||||
filters:
|
||||
- ValidateNoteKey
|
||||
- id: getNoteTxt
|
||||
uri: lb://noteCommonService
|
||||
order: -1
|
||||
predicates:
|
||||
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}.txt
|
||||
- Method=GET
|
||||
filters:
|
||||
- ValidateNoteKey
|
||||
|
||||
|
||||
|
||||
|
||||
management:
|
||||
# server:
|
||||
# address: 127.0.0.1
|
||||
# port: 19000
|
||||
endpoint:
|
||||
shutdown:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
show-details: always
|
||||
endpoints:
|
||||
web:
|
||||
base-path: /f2w8u47ie56edc93/actuator
|
||||
exposure:
|
||||
include: shutdown,health
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud.gateway: info
|
||||
org.springframework.cloud.loadbalancer: info
|
||||
org.springframework.web.reactive: info
|
||||
11
src/main/resources/bootstrap.yml
Normal file
11
src/main/resources/bootstrap.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
application:
|
||||
name: flagnote-gateway
|
||||
cloud:
|
||||
config:
|
||||
name: flagnote-gateway
|
||||
profile: prd
|
||||
uri: http://flagnote-config-01:8080/flagnote-config,http://flagnote-config-02:8080/flagnote-config
|
||||
config:
|
||||
import: optional:configserver:http://flagnote-config-01:8080/,optional:configserver:http://flagnote-config-02:8080/
|
||||
|
||||
Reference in New Issue
Block a user