2
0

feat: support load application yaml

This commit is contained in:
zhangsz
2025-01-17 11:13:41 +08:00
parent e682b8e7e6
commit 2bb8cdfa50
10 changed files with 239 additions and 31 deletions

View File

@@ -18,7 +18,14 @@ docker_my_conf_file=${docker_mysql_conf_d}/my.cnf
wfc_jar_images=$(docker images --format "{{.Repository}}"|grep -E "docker-wfc-|docker_wfc-")
wfc_modules_images=$(docker images --format "{{.Repository}}"|grep -E "docker-wfc-modules-|docker_wfc-modules-")
conf_dirs="${docker_work_dir}/conf ${docker_work_dir}/wfc/modules/system/conf ${docker_work_dir}/wfc/modules/user/conf ${docker_work_dir}/wfc/modules/job/conf ${docker_work_dir}/wfc/modules/file/conf ${docker_work_dir}/wfc/modules/payment/conf"
conf_dirs="${docker_work_dir}/conf
${docker_work_dir}/wfc/gateway/conf
${docker_work_dir}/wfc/auth/conf
${docker_work_dir}/wfc/modules/system/conf
${docker_work_dir}/wfc/modules/user/conf
${docker_work_dir}/wfc/modules/job/conf
${docker_work_dir}/wfc/modules/file/conf
${docker_work_dir}/wfc/modules/payment/conf"
case "$1" in
env)

View File

@@ -17,7 +17,7 @@ services:
- NACOS_SERVER_NAME=${NACOS_SERVER_NAME}
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- SPRING_CONFIG_LOCATION=classpath:/,file:/home/nacos/conf/
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/home/nacos/conf/
volumes:
- ./nacos/logs/:/home/nacos/logs
- ./nacos/conf/application.yml:/home/nacos/conf/application.yml
@@ -26,6 +26,8 @@ services:
networks:
- wfc-be-network
depends_on:
wfc-redis:
condition: service_healthy
wfc-mysql:
condition: service_healthy
healthcheck:
@@ -82,18 +84,19 @@ services:
wfc-gateway:
image: wfc-java:jre8
container_name: wfc-gateway
# build:
# context: ./wfc/gateway
# dockerfile: dockerfile
ports:
- "${GATEWAY_SERVER_PORT}:${GATEWAY_SERVER_PORT}"
networks:
- wfc-be-network
volumes:
- ./wfc/gateway/jar/wfc-gateway.jar:/opt/wfc/app.jar
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/gateway/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-redis:
condition: service_healthy
wfc-mysql:
condition: service_healthy
wfc-nacos:
condition: service_healthy
environment:
@@ -103,6 +106,7 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- GATEWAY_SERVER_PORT=${GATEWAY_SERVER_PORT}
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:${GATEWAY_SERVER_PORT}/actuator/health || exit 1"]
interval: 30s
@@ -113,18 +117,19 @@ services:
wfc-auth:
image: wfc-java:jre8
container_name: wfc-auth
# build:
# context: ./wfc/auth
# dockerfile: dockerfile
ports:
- "${AUTH_SERVER_PORT}:${AUTH_SERVER_PORT}"
networks:
- wfc-be-network
volumes:
- ./wfc/auth/jar/wfc-auth.jar:/opt/wfc/app.jar
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/auth/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-redis:
condition: service_healthy
wfc-mysql:
condition: service_healthy
wfc-nacos:
condition: service_healthy
wfc-gateway:
@@ -136,6 +141,7 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- AUTH_SERVER_PORT=${AUTH_SERVER_PORT}
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:${AUTH_SERVER_PORT}/actuator/health || exit 1"]
interval: 30s
@@ -146,17 +152,14 @@ services:
wfc-modules-system:
image: wfc-java:jre8
container_name: wfc-modules-system
# build:
# context: ./wfc/modules/system
# dockerfile: dockerfile
ports:
- "${WFC_SYSTEM_PORT}:${WFC_SYSTEM_PORT}"
networks:
- wfc-be-network
volumes:
- ./wfc/modules/system/jar/wfc-modules-system.jar:/opt/wfc/app.jar
- ./wfc/modules/system/conf/application.yml:/opt/wfc/conf/application.yml
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/modules/system/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-redis:
condition: service_healthy
@@ -173,6 +176,7 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- WFC_SYSTEM_PORT=${WFC_SYSTEM_PORT}
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:${WFC_SYSTEM_PORT}/actuator/health || exit 1"]
interval: 30s
@@ -183,17 +187,14 @@ services:
wfc-modules-user:
image: wfc-java:jre8
container_name: wfc-modules-user
# build:
# context: ./wfc/modules/user
# dockerfile: dockerfile
ports:
- "${WFC_USER_PORT}:${WFC_USER_PORT}"
networks:
- wfc-be-network
volumes:
- ./wfc/modules/user/jar/wfc-modules-user.jar:/opt/wfc/app.jar
- ./wfc/modules/user/conf/application.yml:/opt/wfc/conf/application.yml
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/modules/user/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-redis:
condition: service_healthy
@@ -210,6 +211,7 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- WFC_USER_PORT=${WFC_USER_PORT}
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:${WFC_USER_PORT}/actuator/health || exit 1"]
interval: 30s
@@ -228,6 +230,8 @@ services:
- ./wfc/modules/file/jar/wfc-modules-file.jar:/opt/wfc/app.jar
- ./wfc/modules/file/upload:/opt/wfc/upload
- ./wfc/modules/file/logs/:/opt/wfc/logs/
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/modules/file/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-auth:
condition: service_healthy
@@ -240,20 +244,20 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- WFC_FILE_PORT=${WFC_FILE_PORT}
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
restart: ${RESTART_OPTION}
wfc-modules-job:
image: wfc-java:jre8
container_name: wfc-modules-job
# build:
# context: ./wfc/modules/job
# dockerfile: dockerfile
ports:
- "${WFC_JOB_PORT}:${WFC_JOB_PORT}"
networks:
- wfc-be-network
volumes:
- ./wfc/modules/job/jar/wfc-modules-job.jar:/opt/wfc/app.jar
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/modules/job/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-mysql:
condition: service_healthy
@@ -268,22 +272,21 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- WFC_JOB_PORT=${WFC_JOB_PORT}
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
restart: ${RESTART_OPTION}
wfc-modules-payment:
image: wfc-java:jre8
container_name: wfc-modules-payment
# build:
# context: ./wfc/modules/payment
# dockerfile: dockerfile
ports:
- "${WFC_PAYMENT_PORT}:${WFC_PAYMENT_PORT}"
networks:
- wfc-be-network
volumes:
- ./wfc/modules/payment/jar/wfc-modules-payment.jar:/opt/wfc/app.jar
- ./wfc/modules/payment/conf/:/opt/wfc/conf/
- ./wfc/modules/payment/logs/:/opt/wfc/logs/
- ./conf/application-common.yml:/opt/wfc/conf/application-common.yml
- ./wfc/modules/payment/conf/application.yml:/opt/wfc/conf/application.yml
depends_on:
wfc-redis:
condition: service_healthy
@@ -300,7 +303,7 @@ services:
- NACOS_SERVER_IP=${NACOS_SERVER_IP}
- NACOS_SERVER_PORT=${NACOS_SERVER_PORT}
- WFC_PAYMENT_PORT=${WFC_PAYMENT_PORT}
- SPRING_CONFIG_LOCATION=classpath:/,file:/opt/wfc/conf/
- SPRING_CONFIG_LOCATION=optional:classpath:/,optional:file:/opt/wfc/conf/
restart: ${RESTART_OPTION}
wfc-nginx:

View File

@@ -5,7 +5,7 @@ WORKDIR /opt/wfc
# 设置环境变量
ENV JVM_OPTS="-Xms128m -Xmx512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m"
ENV JAVA_OPTS="--spring.config.additional-location=/opt/wfc/conf/application.yml"
ENV JAVA_OPTS="--spring.config.location=optional:classpath:/,optional:file:/opt/wfc/conf/application.yml"
ENV JAR_FILE="app.jar"
# 使用 sh -c 解析环境变量

View File

@@ -42,6 +42,20 @@ http {
proxy_pass http://192.168.13.128:8080/;
}
location /file {
proxy_pass http://192.168.13.128:9201/;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header Content-Type $content_type;
proxy_set_header Content-Length $http_content_length;
}
# 避免actuator暴露
if ($request_uri ~ "/actuator") {
return 403;

View File

@@ -0,0 +1,7 @@
spring:
redis:
host: wfc-redis
port: 6379
password:
config:
import: optional:classpath:application-common.yml

View File

@@ -0,0 +1,87 @@
spring:
redis:
host: wfc-redis
port: 6379
password:
cloud:
gateway:
discovery:
locator:
lowerCaseServiceId: true
enabled: true
routes:
# 认证中心
- id: wfc-auth
uri: lb://wfc-auth
predicates:
- Path=/auth/**
filters:
# 验证码处理
- CacheRequestFilter
- ValidateCodeFilter
- StripPrefix=1
# 代码生成
- id: wfc-gen
uri: lb://wfc-gen
predicates:
- Path=/code/**
filters:
- StripPrefix=1
# 定时任务
- id: wfc-job
uri: lb://wfc-job
predicates:
- Path=/schedule/**
filters:
- StripPrefix=1
# 系统模块
- id: wfc-system
uri: lb://wfc-system
predicates:
- Path=/system/**
filters:
- StripPrefix=1
# 用户模块
- id: wfc-user
uri: lb://wfc-user
predicates:
- Path=/u/**
filters:
- StripPrefix=1
# 文件服务
- id: wfc-file
uri: lb://wfc-file
predicates:
- Path=/file/**
filters:
- StripPrefix=1
# payment
- id: wfc-payment
uri: lb://wfc-payment
predicates:
- Path=/payment/**
filters:
- StripPrefix=1
config:
import: optional:classpath:application-common.yml
# 安全配置
security:
# 验证码
captcha:
enabled: true
type: math
# 防止XSS攻击
xss:
enabled: true
excludeUrls:
- /system/notice
# 不校验白名单
ignore:
whites:
- /auth/logout
- /auth/login
- /auth/register
- /auth/checkRepeat
- /*/v2/api-docs
- /csrf

View File

@@ -0,0 +1,25 @@
# spring配置
spring:
config:
import: optional:classpath:application-common.yml
# 本地文件上传
file:
domain: wfc-file:9201
path: /opt/wfc/upload
prefix: /kyc
gateway: http://192.168.2.116:8080
# FastDFS配置
fdfs:
domain: http://wfc-file
soTimeout: 3000
connectTimeout: 2000
trackerList: wfc-file:22122
# Minio配置
minio:
url: http://wfc-file:9000
accessKey: minioadmin
secretKey: minioadmin
bucketName: test

View File

@@ -0,0 +1,37 @@
# spring配置
spring:
redis:
host: wfc-redis
port: 6379
password:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://wfc-mysql:3306/wfc_system_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
config:
import: optional:classpath:application-common.yml
# mybatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: org.wfc.gen.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml
# swagger配置
swagger:
title: 代码生成接口文档
license: Powered By wfc
licenseUrl: https://wfc.vip
# 代码生成
gen:
# 作者
author: wfc
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName: org.wfc.system
# 自动去除表前缀默认是false
autoRemovePre: false
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
tablePrefix: sys_

View File

@@ -0,0 +1,26 @@
# spring配置
spring:
redis:
host: wfc-redis
port: 6379
password:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://wfc-mysql:3306/wfc_system_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
config:
import: optional:classpath:application-common.yml
# mybatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: org.wfc.job.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml
# swagger配置
swagger:
title: 定时任务接口文档
license: Powered By wfc
licenseUrl: https://wfc.vip

View File

@@ -51,6 +51,8 @@ spring:
# password:
# url:
# driver-class-name:
config:
import: optional:classpath:application-common.yml
# mybatis-plus配置
mybatis-plus: