build(biji-houdaun): 配置生产环境并优化构建流程
- 新增 production环境配置文件 application-prod.yml - 更新 Dockerfile,设置生产环境变量 - 为 Knife4j 配置添加环境限制,仅在非生产环境激活 - 在 pom.xml 中添加开发和生产环境配置 - 更新编译打包命令文档,增加生产环境构建指令
This commit is contained in:
@@ -174,4 +174,33 @@
|
|||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<!-- 开发环境包含Knife4j -->
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Knife4j API 文档 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||||
|
<version>${knife4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<!-- 生产环境不包含Knife4j -->
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import io.swagger.v3.oas.models.info.Info;
|
|||||||
import org.springdoc.core.models.GroupedOpenApi;
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@Profile("!prod") // 只在非生产环境激活
|
||||||
public class Knife4jConfig {
|
public class Knife4jConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ RUN mkdir -p /data && chmod a+rw /data
|
|||||||
COPY data/mydatabase.db /data/mydatabase.db
|
COPY data/mydatabase.db /data/mydatabase.db
|
||||||
|
|
||||||
# 设置环境变量,test 激活测试环境
|
# 设置环境变量,test 激活测试环境
|
||||||
ENV SPRING_PROFILES_ACTIVE=test \
|
ENV SPRING_PROFILES_ACTIVE=prod \
|
||||||
JAVA_OPTS="-Xmx512m -XX:MaxRAMPercentage=75"
|
JAVA_OPTS="-Xmx512m -XX:MaxRAMPercentage=75"
|
||||||
|
|
||||||
# 暴露应用端口
|
# 暴露应用端口
|
||||||
|
|||||||
12
biji-houdaun/src/main/resources/application-prod.yml
Normal file
12
biji-houdaun/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
driver-class-name: org.sqlite.JDBC
|
||||||
|
url: jdbc:sqlite:/data/mydatabase.db
|
||||||
|
jpa:
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: none
|
||||||
|
show-sql: false
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
format_sql: false
|
||||||
|
dialect: org.hibernate.dialect.SQLiteDialect
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
## 忽略测试用例
|
## 忽略测试用例
|
||||||
`mvn clean package -D maven.test.skip=true -am docker:build`
|
`mvn clean package -D maven.test.skip=true -am docker:build`
|
||||||
|
## 忽略测试用例,指定环境
|
||||||
|
`mvn clean package -P prod -D maven.test.skip=true -am docker:build`
|
||||||
|
|
||||||
# 在dockerfile中已经设置好了启动哪个配置文件
|
# 在dockerfile中已经设置好了启动哪个配置文件
|
||||||
ENV SPRING_PROFILES_ACTIVE=test \
|
ENV SPRING_PROFILES_ACTIVE=test \
|
||||||
|
|||||||
Reference in New Issue
Block a user