ci: 👷 调整项目打包结构,分离依赖、配置文件
1.调整 Spring Boot 配置文件到 config 目录 2.移除 Maven Profiles 配置 3.调整项目打包结构,分离依赖、配置文件。如无依赖调整,部署时仅需拷贝程序包,且更方便进行配置修改 4.调整后的项目打包结构,更贴合部署安装程序结构,例如:Tomcat 安装包、Maven 安装包 5.建议在 bin 目录上一级执行程序,以使日志文件能正确生成在 logs 目录下,参考 Dockerfile
This commit is contained in:
parent
5c9e6639db
commit
e679abfccc
12
.github/workflows/deploy.yml
vendored
12
.github/workflows/deploy.yml
vendored
@ -24,17 +24,17 @@ jobs:
|
|||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
# 3、打包
|
# 3、打包
|
||||||
- name: Build
|
- name: Build
|
||||||
run: mvn -B package -P prod --file pom.xml
|
run: mvn -B package --file pom.xml
|
||||||
# 4、拷贝 jar 包到服务器
|
# 4、拷贝到服务器
|
||||||
- name: Copy Jar
|
- name: Copy
|
||||||
uses: garygrossgarten/github-action-scp@release
|
uses: garygrossgarten/github-action-scp@release
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
port: ${{ secrets.SERVER_PORT }}
|
port: ${{ secrets.SERVER_PORT }}
|
||||||
username: ${{ secrets.SERVER_USERNAME }}
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
password: ${{ secrets.SERVER_PASSWORD }}
|
password: ${{ secrets.SERVER_PASSWORD }}
|
||||||
local: continew-admin-webapi/target/continew-admin.jar
|
local: ./continew-admin-webapi/target/app
|
||||||
remote: /docker/continew-admin/server/continew-admin.jar
|
remote: /docker/continew-admin
|
||||||
# 5、启动后端服务
|
# 5、启动后端服务
|
||||||
- name: Start
|
- name: Start
|
||||||
uses: appleboy/ssh-action@master
|
uses: appleboy/ssh-action@master
|
||||||
@ -75,7 +75,7 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
working-directory: ./continew-admin-ui
|
working-directory: ./continew-admin-ui
|
||||||
# 6、拷贝文件到服务器
|
# 6、拷贝到服务器
|
||||||
- name: Copy
|
- name: Copy
|
||||||
uses: garygrossgarten/github-action-scp@release
|
uses: garygrossgarten/github-action-scp@release
|
||||||
with:
|
with:
|
||||||
|
@ -389,7 +389,7 @@ git clone https://github.com/Charles7c/continew-admin.git
|
|||||||
# 5.部署
|
# 5.部署
|
||||||
# 5.1 Docker 部署
|
# 5.1 Docker 部署
|
||||||
# 5.1.1 服务器安装好 docker 及 docker-compose(参考:https://blog.charles7c.top/categories/fragments/2022/10/31/CentOS%E5%AE%89%E8%A3%85Docker)
|
# 5.1.1 服务器安装好 docker 及 docker-compose(参考:https://blog.charles7c.top/categories/fragments/2022/10/31/CentOS%E5%AE%89%E8%A3%85Docker)
|
||||||
# 5.1.2 执行 mvn package -P prod 进行项目打包,将 target 目录下的 continew-admin.jar 放到 /docker/continew-admin/server 目录下
|
# 5.1.2 执行 mvn package 进行项目打包,将 target/app 目录下的所有内容放到 /docker/continew-admin 目录下
|
||||||
# 5.1.3 将 docker 目录上传到服务器 / 目录下,并授权(chmod -R 777 /docker)
|
# 5.1.3 将 docker 目录上传到服务器 / 目录下,并授权(chmod -R 777 /docker)
|
||||||
# 5.1.4 修改 docker-compose.yml 中的 MariaDB 配置、Redis 配置、continew-admin-server 配置、Nginx 配置
|
# 5.1.4 修改 docker-compose.yml 中的 MariaDB 配置、Redis 配置、continew-admin-server 配置、Nginx 配置
|
||||||
# 5.1.5 执行 docker-compose up -d 创建并后台运行所有容器
|
# 5.1.5 执行 docker-compose up -d 创建并后台运行所有容器
|
||||||
|
@ -31,6 +31,18 @@ limitations under the License.
|
|||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<description>API 模块(存放 Controller 层代码,打包部署的模块)</description>
|
<description>API 模块(存放 Controller 层代码,打包部署的模块)</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- ### 打包配置相关 ### -->
|
||||||
|
<!-- 启动类 -->
|
||||||
|
<main-class>top.charles7c.cnadmin.ContiNewAdminApplication</main-class>
|
||||||
|
<!-- 程序 jar 输出目录 -->
|
||||||
|
<bin-path>bin</bin-path>
|
||||||
|
<!-- 配置文件输出目录 -->
|
||||||
|
<config-path>config</config-path>
|
||||||
|
<!-- 依赖 jar 输出目录 -->
|
||||||
|
<lib-path>lib</lib-path>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Liquibase(用于管理数据库版本,跟踪、管理和应用数据库变化) -->
|
<!-- Liquibase(用于管理数据库版本,跟踪、管理和应用数据库变化) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -66,34 +78,77 @@ limitations under the License.
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
<!-- 跳过单元测试 -->
|
||||||
<!-- 根据启用环境执行对应 @Tag 的测试方法 -->
|
<skip>true</skip>
|
||||||
<groups>${profiles.active}</groups>
|
|
||||||
<!-- 排除标签 -->
|
|
||||||
<excludedGroups>exclude</excludedGroups>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Spring Boot 打包插件(将 Spring Boot Maven 应用打包为可执行的 jar 包) -->
|
<!-- Maven 打包插件 -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<!-- 排除配置文件 -->
|
||||||
|
<excludes>
|
||||||
|
<exclude>${config-path}/</exclude>
|
||||||
|
</excludes>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>${main-class}</mainClass>
|
||||||
|
<!-- 为 MANIFEST.MF 中的 Class-Path 加入依赖 jar 目录前缀 -->
|
||||||
|
<classpathPrefix>../${lib-path}/</classpathPrefix>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<!-- jar 包不包含唯一版本标识 -->
|
||||||
|
<useUniqueVersions>false</useUniqueVersions>
|
||||||
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<!--为 MANIFEST.MF 中的 Class-Path 加入配置文件目录前缀 -->
|
||||||
|
<Class-Path>../${config-path}/</Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
<outputDirectory>${project.build.directory}/app/${bin-path}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- 拷贝依赖 jar -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
<id>copy-dependencies</id>
|
||||||
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>repackage</goal>
|
<goal>copy-dependencies</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/app/${lib-path}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<!-- 拷贝配置文件 -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>${config-path}/</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<outputDirectory>${project.build.directory}/app</outputDirectory>
|
||||||
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
|
||||||
<!-- 在新的 JVM 进程中运行打包任务(另注:在使用 devtools 时,如果没有该项配置,热部署可能会失效) -->
|
|
||||||
<fork>true</fork>
|
|
||||||
<excludes>
|
|
||||||
<exclude>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
@ -138,6 +138,13 @@ rsa:
|
|||||||
# 私钥
|
# 私钥
|
||||||
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
||||||
|
|
||||||
|
--- ### 日志配置
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
top.charles7c: DEBUG
|
||||||
|
file:
|
||||||
|
path: ./logs
|
||||||
|
|
||||||
--- ### 接口文档配置
|
--- ### 接口文档配置
|
||||||
springdoc:
|
springdoc:
|
||||||
swagger-ui:
|
swagger-ui:
|
@ -131,6 +131,13 @@ rsa:
|
|||||||
# 私钥
|
# 私钥
|
||||||
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
||||||
|
|
||||||
|
--- ### 日志配置
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
top.charles7c: INFO
|
||||||
|
file:
|
||||||
|
path: ./logs
|
||||||
|
|
||||||
--- ### 接口文档配置
|
--- ### 接口文档配置
|
||||||
springdoc:
|
springdoc:
|
||||||
swagger-ui:
|
swagger-ui:
|
@ -26,10 +26,6 @@ project:
|
|||||||
|
|
||||||
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
|
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
|
||||||
logging:
|
logging:
|
||||||
level:
|
|
||||||
top.charles7c: @logging.level@
|
|
||||||
file:
|
|
||||||
path: @logging.file.path@
|
|
||||||
config: classpath:logback-spring.xml
|
config: classpath:logback-spring.xml
|
||||||
## 系统日志配置
|
## 系统日志配置
|
||||||
system:
|
system:
|
||||||
@ -186,8 +182,7 @@ spring:
|
|||||||
## 环境配置
|
## 环境配置
|
||||||
profiles:
|
profiles:
|
||||||
# 启用的环境
|
# 启用的环境
|
||||||
# 配合 Maven Profile 选择不同配置文件进行启动,在 IntelliJ IDEA 右侧 Maven 工具窗口可以快速切换环境
|
active: dev
|
||||||
active: @profiles.active@
|
|
||||||
main:
|
main:
|
||||||
# 允许定义重名的 bean 对象覆盖原有的 bean
|
# 允许定义重名的 bean 对象覆盖原有的 bean
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
@ -2,10 +2,12 @@ FROM java:8
|
|||||||
|
|
||||||
MAINTAINER Charles7c charles7c@126.com
|
MAINTAINER Charles7c charles7c@126.com
|
||||||
|
|
||||||
ARG JAR_FILE=./server/*.jar
|
ARG JAR_FILE=./bin/*.jar
|
||||||
COPY ${JAR_FILE} app.jar
|
COPY ${JAR_FILE} /app/bin/app.jar
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
ENTRYPOINT ["java", \
|
ENTRYPOINT ["java", \
|
||||||
"-jar", \
|
"-jar", \
|
||||||
"-Djava.security.egd=file:/dev/./urandom", \
|
"-Djava.security.egd=file:/dev/./urandom", \
|
||||||
"app.jar"]
|
"-Dspring.profiles.active=prod", \
|
||||||
|
"./bin/app.jar"]
|
@ -47,9 +47,11 @@ services:
|
|||||||
REDIS_PWD: 你的 Redis 密码
|
REDIS_PWD: 你的 Redis 密码
|
||||||
REDIS_DB: 你的 Redis 数据库索引
|
REDIS_DB: 你的 Redis 数据库索引
|
||||||
volumes:
|
volumes:
|
||||||
- /docker/continew-admin/data/file:/data/file
|
- /docker/continew-admin/config:/app/config
|
||||||
- /docker/continew-admin/data/avatar:/data/avatar
|
- /docker/continew-admin/data/file:/app/data/file
|
||||||
- /docker/continew-admin/logs:/logs
|
- /docker/continew-admin/data/avatar:/app/data/avatar
|
||||||
|
- /docker/continew-admin/logs:/app/logs
|
||||||
|
- /docker/continew-admin/lib:/app/lib
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
- mariadb
|
- mariadb
|
||||||
|
45
pom.xml
45
pom.xml
@ -68,33 +68,6 @@ limitations under the License.
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>dev</id>
|
|
||||||
<!-- 自定义属性配置 -->
|
|
||||||
<properties>
|
|
||||||
<!-- Spring Boot 启用环境 -->
|
|
||||||
<profiles.active>dev</profiles.active>
|
|
||||||
<!-- 日志级别 -->
|
|
||||||
<logging.level>DEBUG</logging.level>
|
|
||||||
<!-- 日志存储位置 -->
|
|
||||||
<logging.file.path>./logs</logging.file.path>
|
|
||||||
</properties>
|
|
||||||
<activation>
|
|
||||||
<!-- 默认启用 -->
|
|
||||||
<activeByDefault>true</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>prod</id>
|
|
||||||
<properties>
|
|
||||||
<profiles.active>prod</profiles.active>
|
|
||||||
<logging.level>INFO</logging.level>
|
|
||||||
<logging.file.path>./logs</logging.file.path>
|
|
||||||
</properties>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
<!-- 全局依赖版本管理 -->
|
<!-- 全局依赖版本管理 -->
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -287,24 +260,6 @@ limitations under the License.
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*.yml</include>
|
|
||||||
</includes>
|
|
||||||
<!-- 启用过滤,即替换对应资源中的变量 -->
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
<!-- 除 YAML 配置文件外,其他配置文件不需要进行变量替换 -->
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/**</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<!-- 远程仓库配置:阿里云 Maven 中央仓库(公共代理仓库,Central 仓和 JCenter 仓的聚合仓,帮助研发人员提高研发生产效率,使用阿里云 Maven 中央仓库作为下载源,速度更快更稳定) -->
|
<!-- 远程仓库配置:阿里云 Maven 中央仓库(公共代理仓库,Central 仓和 JCenter 仓的聚合仓,帮助研发人员提高研发生产效率,使用阿里云 Maven 中央仓库作为下载源,速度更快更稳定) -->
|
||||||
|
Loading…
Reference in New Issue
Block a user