Skip to content

Commit

Permalink
Merge pull request #20 from opensabre/0.1.0
Browse files Browse the repository at this point in the history
0.1.0
  • Loading branch information
zhoutaoo authored Oct 8, 2024
2 parents 85c56cd + cf11540 commit a4c3f40
Show file tree
Hide file tree
Showing 42 changed files with 276 additions and 131 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
# 1. 声明 checkout 仓库代码到工作区
- uses: actions/checkout@v2
# 2. 安装Java 环境 这里会用到的参数就是 Git Action secrets中配置的,
- name: Set up JDK 1.11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 1.11
java-version: 17
# 3.编译打包
- name: Build with Maven
run: mvn -B package javadoc:javadoc --file pom.xml
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Maven Central Repo
uses: actions/setup-java@v1
with:
java-version: 1.11
java-version: 17
server-id: sonatype-nexus-staging
server-username: ${{ secrets.OSSRH_USER }}
server-password: ${{ secrets.OSSRH_PASSWORD }}
Expand Down
143 changes: 117 additions & 26 deletions opensabre-base-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,32 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- 编译 -->
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<lombok.version>1.18.24</lombok.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<lombok.version>1.18.30</lombok.version>
<spring-boot-maven-plugin.version>2.7.5</spring-boot-maven-plugin.version>
<dockerfile-maven-plugin.version>1.4.13</dockerfile-maven-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<!-- 依赖 -->
<spring.boot.version>2.7.18</spring.boot.version>
<spring.cloud.version>2021.0.9</spring.cloud.version>
<spring.cloud.alibaba.version>2021.0.5.0</spring.cloud.alibaba.version>
<spring-boot-starter-data-redis.version>2.7.18</spring-boot-starter-data-redis.version>
<spring.boot.version>3.2.3</spring.boot.version>
<spring.cloud.version>2023.0.0</spring.cloud.version>
<spring.cloud.alibaba.version>2023.0.0.0-RC1</spring.cloud.alibaba.version>
<jetcache-starter-redis.version>2.7.5</jetcache-starter-redis.version>
<springdoc-openapi-ui.version>1.6.12</springdoc-openapi-ui.version>
<swagger-annotations.version>2.2.4</swagger-annotations.version>
<knife4j-openapi3.version>4.4.0</knife4j-openapi3.version>
<swagger-annotations.version>2.2.19</swagger-annotations.version>
<mysql-connector-j.version>8.0.31</mysql-connector-j.version>
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
<mybatis-plus-boot-starter.version>3.5.2</mybatis-plus-boot-starter.version>
<mybatis-spring.version>2.0.7</mybatis-spring.version>
<commons-pool2.version>2.11.1</commons-pool2.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
<mybatis-plus-boot-starter.version>3.5.5</mybatis-plus-boot-starter.version>
<mybatis-spring.version>3.0.3</mybatis-spring.version>
<hutool.version>5.8.18</hutool.version>
<spring-webmvc.version>5.3.31</spring-webmvc.version>
<feign-interceptors>1.1.2</feign-interceptors>
<guava.version>31.1-jre</guava.version>
<jackson-databind.version>2.13.5</jackson-databind.version>
<jackson-annotations.version>2.13.5</jackson-annotations.version>
<jasypt-springboot.version>3.0.5</jasypt-springboot.version>
<!-- 测试 -->
<junit-jupiter.version>5.9.1</junit-jupiter.version>
<spring-test.version>5.3.31</spring-test.version>
<spring-boot-starter-test.version>2.7.18</spring-boot-starter-test.version>
<httpclient5.version>5.2.1</httpclient5.version>
<httpclient5.version>5.2.3</httpclient5.version>
</properties>

<!-- 依赖管理定义 -->
Expand Down Expand Up @@ -94,9 +89,9 @@
</dependency>
<!-- WEB -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- 负载组件 -->
Expand All @@ -106,16 +101,21 @@
<version>${feign-interceptors}</version>
</dependency>
<!-- 服务调用负载 -->
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>${httpclient5.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${httpclient5.version}</version>
</dependency>
<!--springdoc - restfull API文档-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>${knife4j-openapi3.version}</version>
</dependency>
<!--opensabre 组件-->
<dependency>
Expand Down Expand Up @@ -194,7 +194,7 @@
<!--Swagger - RESTFULL API文档-->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>${swagger-annotations.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
Expand Down Expand Up @@ -222,6 +222,14 @@
<!--依赖插件版本定义-->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
<!--springboot官方构建插件,可构建docker image-->
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -266,7 +274,90 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>${git-commit-id-plugin.version}</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<!-- *NOTE*: 默认是initialize阶段执行,可以修改为其他阶段 -->
<phase>initialize</phase>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
<!-- *NOTE*: 默认是打包阶段执行,可以修改为其他 -->
<phase>package</phase>
</execution>
</executions>
<configuration>
<!-- git文件记录,默认是 ${project.basedir}/.git如果非默认,可以指定,例如: ${project.basedir}/../.git -->
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<!-- 属性前缀,可以理解为namespace,默认是git, 例如 `${configured-prefix}.commit.id`.更多信息可以参考 (see
https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/137#issuecomment-418144756
for a full example).
-->
<prefix>git</prefix>
<!-- 默认的日期格式,使用方式(e.g. `git.commit.time` and `git.build.time`). -->
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<!-- 时区(java.util.TimeZone.getDefault().getID()).
*Note*: 指定时区可以如下 `MAVEN_OPTS=-Duser.timezone=UTC mvn clean package`, `mvn clean package -Duser.timezone=UTC`或者使用 Asia/Shanghai 直接指定,该属性会使用在
(e.g. `git.commit.time` and `git.build.time`).
-->
<dateFormatTimeZone>${user.timezone}</dateFormatTimeZone>
<!-- 默认false,构建时打印信息 -->
<verbose>true</verbose>
<!-- 默认false, 如果是true, 会生成properties 文件(填充文件中的属性值),文件配置在 generateGitPropertiesFilename 中, 构建时间使用如下 -->
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<!-- 默认是true,如果打包是pom(e.g. `<packaging>pom</packaging>`),则运行该插件 -->
<skipPoms>true</skipPoms>
<!-- 默认true,说明:当设置为“true”时,此插件将尝试将生成的属性公开到`System.getProperties()`. 设置为{@code'false'}以避免此曝光。注意通过命令行提供的参数(例如`-Dgit.commit.id=值`)仍然有优先权。 -->
<injectIntoSysProperties>true</injectIntoSysProperties>
<!-- 默认false, 指定在找不到.git目录时插件是否应失败。当设置为“false”并且没有找到.git目录时,插件将跳过执行。 -->
<failOnNoGitDirectory>true</failOnNoGitDirectory>
<!-- 默认7,配置缩写git提交id的长度(`git.commit.id.abbrev`)到长度至少为N。`0'具有特殊含义(签出git/git文档描述-描述.md)对于特殊情况,缩写为0)。最大值为“40”,因为最大SHA-1长度。 -->
<abbrevLength>7</abbrevLength>
<!-- 目前,交换机允许两种不同的选择:1默认情况下,此属性设置为“flat”,并将生成以前已知的财产`git.commit.id`就像以前版本的插件一样。保持默认情况下,它将“flat”保留向后兼容性,不需要进一步的操作最终用户调整。2如果将此开关设置为“full”,则插件将导出以前已知的属性`git.commit.id`作为`git.commit.id.full`因此将生成完全有效的导出机制中的json对象。-->
<commitIdGenerationMode>flat</commitIdGenerationMode>
<!-- 可以用作非常强大的版本控制助手, 可以参考https://git-scm.com/docs/git-describe -->
<gitDescribe>
<!-- 默认false, 如果true,则不使用该配置 -->
<skip>false</skip>
<!-- 默认true,在某些情况下,在提交附近找不到标记(例如,通常在执行浅克隆)。如果将其设置为“true”,并且未找到标记,则此属性将改为回退到提交的id(当“true”时,此属性不会变为空)-->
<always>true</always>
<!-- 在describe输出中,哈希的对象id总是缩写为N个字母(默认为7)-->
<abbrev>7</abbrev>
<!-- Default (optional): -dirty 在处于“脏状态”(未提交)的存储库上运行“描述”时更改),说明输出将包含一个附加后缀 -->
<dirty>-dirty</dirty>
</gitDescribe>
<!-- 附加的验证实用程序,可用于验证项目属性是否设置 -->
<validationProperties>
<validationProperty>
<!-- 用于识别验证的描述性名称,不匹配(将显示在错误消息中)-->
<name>validating project version</name>
<!-- 需要验证的值*注意*:为了能够验证在pom本身您可能需要设置配置`<injectAllReactorProjects>true</injectAllReactorProjects>`。 -->
<value>${project.version}</value>
<!-- the expected value -->
<shouldMatchTo><![CDATA[^.*(?<!-SNAPSHOT)$]]></shouldMatchTo>
</validationProperty>
<!-- the next validationProperty you would like to validate -->
</validationProperties>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
12 changes: 8 additions & 4 deletions opensabre-starter-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
</dependency>
<!-- 分布式链路追踪 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<!-- 表单校验-->
<dependency>
Expand All @@ -63,15 +63,19 @@
</dependency>
<!--springdoc - restfull API文档-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
</dependency>
<!-- 提示文件生成 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-setting</artifactId>
</dependency>
<!--热加载-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.opensabre.boot.config;

import cn.hutool.core.io.resource.NoResourceException;
import cn.hutool.setting.dialect.Props;
import io.github.opensabre.boot.metadata.OpensabreCloud;
import io.github.opensabre.boot.metadata.OpensabreVersion;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -8,38 +10,29 @@
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;

import java.util.HashMap;

import static io.github.opensabre.boot.metadata.OpensabreCloud.OPENSABRE_CLOUD_AZ;
import static io.github.opensabre.boot.metadata.OpensabreCloud.OPENSABRE_CLOUD_REGION;
import static io.github.opensabre.boot.metadata.OpensabreVersion.OPENSABRE_FORMATTED_VERSION;
import static io.github.opensabre.boot.metadata.OpensabreVersion.OPENSABRE_VERSION;

/**
* Opensabre环境变更初使化
* 将版本号初使化到环境变更中,方便应用后续扩展使用
*/
@Slf4j
public class OpensabreEnvConfig implements EnvironmentPostProcessor {
/**
* Opensabre版本号环境变更Key
*/
public static final String OPENSABRE_VERSION = "opensabre.version";
/**
* Opensabre完整版本号环境变更Key
*/
public static final String OPENSABRE_FORMATTED_VERSION = "opensabre.formatted-version";
/**
* Opensabre云部署AZ环境变量Key
*/
public static final String OPENSABRE_CLOUD_AZ = "opensabre.cloud.az";
/**
* Opensabre云部署REGION环境变量Key
*/
public static final String OPENSABRE_CLOUD_REGION = "opensabre.cloud.region";

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
log.info("OpensabreEnvConfig init start");
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.addFirst(getVersionEnv());
propertySources.addFirst(getCloudEnv());
propertySources.addFirst(getGitProperties());
}

/**
Expand All @@ -65,5 +58,19 @@ private MapPropertySource getCloudEnv() {
propertyMap.put(OPENSABRE_CLOUD_REGION, OpensabreCloud.getCloudRegion());
return new MapPropertySource("cloud", propertyMap);
}
}

/**
* 加载git.properties构建元数据
*
* @return PropertiesPropertySource
*/
private PropertiesPropertySource getGitProperties() {
Props props = new Props();
try {
props = new Props("git.properties");
} catch (NoResourceException exception) {
log.warn("load git properties: {}", exception.getMessage());
}
return new PropertiesPropertySource("application", props.toProperties());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public BeanFactoryPostProcessor beanFactoryPostProcessor() {
}

@Bean
@ConditionalOnMissingBean
public LogBackDesensitizer regxLogBackDesensitizer() {
return new RegxLogBackDesensitizer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import jakarta.annotation.Resource;

/**
* Swagger配置类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import javax.annotation.Resource;
import jakarta.annotation.Resource;

@Slf4j
public class OpensabreSensitiveDesensitizerProcessor implements BeanPostProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;

import javax.annotation.Resource;
import jakarta.annotation.Resource;

/**
* springboot应用启动完成后,发送Rest注册事件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
* 获取opensabre cloud相关信息,用于支持云原生多活等
*/
public class OpensabreCloud {
/**
* Opensabre云部署AZ环境变量Key
*/
public static final String OPENSABRE_CLOUD_AZ = "opensabre.cloud.az";
/**
* Opensabre云部署REGION环境变量Key
*/
public static final String OPENSABRE_CLOUD_REGION = "opensabre.cloud.region";
/**
* 云部署时环境变量,代表可用区
*/
Expand Down
Loading

0 comments on commit a4c3f40

Please sign in to comment.