Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyuanlu committed Aug 15, 2024
1 parent 4996e51 commit 7c2d12e
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yaml,yml,bat}]
[*.{yaml,yml,bat,md}]
indent_size = 2

[*.md]
Expand Down
65 changes: 39 additions & 26 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,53 @@

```yaml
spring:
cloud:
nacos:
discovery: # 注册中心
enabled: true # 默认关闭,请按需开启
config: # 配置中心
enabled: true # 默认关闭,请按需开启
cloud:
nacos:
discovery: # 注册中心
enabled: true # 默认关闭,请按需开启
config: # 配置中心
enabled: true # 默认关闭,请按需开启
```

**修改默认的数据源**:本项目默认使用 `H2` 内存数据库启动,基于 `Liquibase` 在项目启动时自动初始化 SQL 脚本。如果您使用的是外部的 MySQL 数据库,可以从此处调整下数据库的连接信息:[application-local.yml](https://github.com/shiyindaxiaojie/eden-demo-cola/blob/main/eden-demo-cola-start/src/main/resources/config/application-local.yml),请删除任何与 `H2` 有关的配置。
**修改默认的数据源**:本项目默认使用 `H2` 内存数据库启动,基于 `Liquibase` 在项目启动时自动初始化 SQL 脚本。如果您使用的是外部的 MySQL 数据库,可以从此处调整下数据库的连接信息:[application-dev.yml](https://github.com/shiyindaxiaojie/eden-demo-cola/blob/main/eden-demo-cola-start/src/main/resources/config/application-dev.yml),请删除任何与 `H2` 有关的配置。

```yaml
spring:
# h2: # 内存数据库
# console:
# enabled: true # 线上环境请勿设置
# path: /h2-console
# settings:
# trace: false
# web-allow-others: false
datasource: # 数据源管理
username:
password:
url: jdbc:mysql://host:port/schema?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
driver-class-name: com.mysql.cj.jdbc.Driver
# h2: # 内存数据库
# console:
# enabled: true # 线上环境请勿设置
# path: /h2-console
# settings:
# trace: false
# web-allow-others: false
datasource: # 数据源管理
username:
password:
url: jdbc:mysql://host:port/schema?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
driver-class-name: com.mysql.cj.jdbc.Driver
```
此外,本项目还罗列了 `Redis` 缓存、`RocketMQ` 消息队列、`ShardingSphere` 分库分表等常用组件的使用方案,默认通过 `xxx.enabled` 关闭自动配置。您可以根据实际情况开启配置,直接完成组件的集成。

## 如何部署

### FatJar 程序部署
### FatJar 简易部署

执行 `mvn clean package` 打包成一个 fat jar,参考如下命令启动编译后的控制台。
执行 `mvn -T 4C clean package` 打包成一个可运行的 fat jar,参考如下命令启动编译后的控制台。

```bash
java -Dserver.port=8080 -jar target/eden-demo-cola.jar
java -Dserver.port=8081 -jar target/eden-demo-cola-start.jar
```

### Assembly 打包部署

执行 `mvn -P assembly -T 4C clean package` 打包成压缩包,选择下列压缩包复制一份到您期望部署的目录。

* target/eden-demo-cola-start-assembly.zip
* target/eden-demo-cola-start-assembly.tar.gz

解压文件后,您可以在 `bin` 目录下找到 `startup.sh` 或者 `startup.bat`脚本,直接运行即可。

### Jib 镜像部署

Google Jib 插件允许您在没有安装 Docker 下完成镜像的构建。
Expand All @@ -107,13 +116,13 @@ mvn -pl eden-demo-cola-start jib:build -Djib.disableUpdateChecks=true -DskipTest

### Docker 容器部署

本项目使用了 Spring Boot 的镜像分层特性优化了镜像的构建效率,请确保正确安装了 Docker 工具,然后执行以下命令。
基于 Spring Boot 的分层特性构建镜像,请确保正确安装了 Docker 工具,然后执行以下命令。

```bash
docker build -f docker/Dockerfile -t eden-demo-cola:{tag} .
```

### Helm 打包部署
### Helm 应用部署

以应用为中心,建议使用 Helm 统一管理所需部署的 K8s 资源描述文件,请参考以下命令完成应用的安装和卸载。

Expand All @@ -138,16 +147,20 @@ helm uninstall eden-demo-cola # 卸载资源

## 持续集成

> CI/CD 工具选型:Jenkins、Zadig、Codeup、CODING
> CI/CD 工具选型:Jenkins、Zadig、CODING、Codeup

### CODING 持续交付
### CODING 持续集成

下图演示基于 CODING 实现持续构建、持续部署的效果。[传送门](https://www.yuque.com/mengxiangge/action/coding)

![](https://cdn.jsdelivr.net/gh/shiyindaxiaojie/images/common/coding-cicd.png)

![](https://cdn.jsdelivr.net/gh/shiyindaxiaojie/images/common/coding-test-report.png)

### Codeup 持续集成

> TODO, Coming soon

## 最佳实践

### DDD 领域驱动设计
Expand Down
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ spring:
enabled: true # 默认关闭,请按需开启
```
**修改默认的数据源**:本项目默认使用 `H2` 内存数据库启动,基于 `Liquibase` 在项目启动时自动初始化 SQL 脚本。如果您使用的是外部的 MySQL 数据库,可以从此处调整下数据库的连接信息:[application-local.yml](https://github.com/shiyindaxiaojie/eden-demo-cola/blob/main/eden-demo-cola-start/src/main/resources/config/application-local.yml),请删除任何与 `H2` 有关的配置。
**修改默认的数据源**:本项目默认使用 `H2` 内存数据库启动,基于 `Liquibase` 在项目启动时自动初始化 SQL 脚本。如果您使用的是外部的 MySQL 数据库,可以从此处调整下数据库的连接信息:[application-dev.yml](https://github.com/shiyindaxiaojie/eden-demo-cola/blob/main/eden-demo-cola-start/src/main/resources/config/application-dev.yml),请删除任何与 `H2` 有关的配置。

```yaml
spring:
Expand All @@ -88,14 +88,23 @@ spring:

## 如何部署

### FatJar 程序部署
### FatJar 简易部署

执行 `mvn clean package` 打包成一个 fat jar,参考如下命令启动编译后的控制台。
执行 `mvn -T 4C clean package` 打包成一个可运行的 fat jar,参考如下命令启动编译后的控制台。

```bash
java -Dserver.port=8080 -jar target/eden-demo-cola.jar
java -Dserver.port=8081 -jar target/eden-demo-cola-start.jar
```

### Assembly 打包部署

执行 `mvn -P assembly -T 4C clean package` 打包成压缩包,选择下列压缩包复制一份到您期望部署的目录。

* target/eden-demo-cola-start-assembly.zip
* target/eden-demo-cola-start-assembly.tar.gz

解压文件后,您可以在 `bin` 目录下找到 `startup.sh` 或者 `startup.bat`脚本,直接运行即可。

### Jib 镜像部署

Google Jib 插件允许您在没有安装 Docker 下完成镜像的构建。
Expand All @@ -107,13 +116,13 @@ mvn -pl eden-demo-cola-start jib:build -Djib.disableUpdateChecks=true -DskipTest

### Docker 容器部署

本项目使用了 Spring Boot 的镜像分层特性优化了镜像的构建效率,请确保正确安装了 Docker 工具,然后执行以下命令。
基于 Spring Boot 的分层特性构建镜像,请确保正确安装了 Docker 工具,然后执行以下命令。

```bash
docker build -f docker/Dockerfile -t eden-demo-cola:{tag} .
```

### Helm 打包部署
### Helm 应用部署

以应用为中心,建议使用 Helm 统一管理所需部署的 K8s 资源描述文件,请参考以下命令完成应用的安装和卸载。

Expand All @@ -138,16 +147,20 @@ helm uninstall eden-demo-cola # 卸载资源

## 持续集成

> CI/CD 工具选型:Jenkins、Zadig、Codeup、CODING
> CI/CD 工具选型:Jenkins、Zadig、CODING、Codeup

### CODING 持续交付
### CODING 持续集成

下图演示基于 CODING 实现持续构建、持续部署的效果。[传送门](https://www.yuque.com/mengxiangge/action/coding)

![](https://cdn.jsdelivr.net/gh/shiyindaxiaojie/images/common/coding-cicd.png)

![](https://cdn.jsdelivr.net/gh/shiyindaxiaojie/images/common/coding-test-report.png)

### Codeup 持续集成

> TODO, Coming soon

## 最佳实践

### DDD 领域驱动设计
Expand Down
16 changes: 8 additions & 8 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

if exist "%JAVA_HOME%" (
echo Java Path: %JAVA_HOME%
echo Java Version:
echo Java Version:
java -version
)

if exist "%E3_HOME%" (
echo Maven Path: %E3_HOME%
echo Maven Version:
echo Maven Version:
call mvn -version
)

Expand Down Expand Up @@ -47,25 +47,25 @@ goto targetTests
:targetTests
echo Please choose whether to skip the test before building. Y: Yes, N: No
set /p skipTests=Please press the above numbers to enter the options and press Enter to confirm:
if /i "%skipTests%"=="" goto skipTests
if /i "%skipTests%"=="Y" goto skipTests
if /i "%skipTests%"=="y" goto skipTests
if /i "%skipTests%"=="" goto skipTests
if /i "%skipTests%"=="Y" goto skipTests
if /i "%skipTests%"=="y" goto skipTests
if /i "%skipTests%"=="N" goto doTests
if /i "%skipTests%"=="n" goto doTests

:skipTests
:skipTests
echo Test skip selected
set "skipTests=-DskipTests=true"
goto build

:doTests
:doTests
echo Test exec selected
set "skipTests="
goto build

:build
echo Start building, please wait. . . . . .
echo Command: mvn clean compile package -e -P %profile% %skipTests%
echo Command: mvn clean package -e -P %profile% %skipTests%
call mvn clean compile package -e -P %profile% %skipTests%
echo.&echo The build is complete, you can copy executable program from %cd%/target, press any key to exit &pause>nul
exit
Expand Down
18 changes: 18 additions & 0 deletions eden-demo-cola-start/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@
</plugins>
</build>

<profiles>
<profile>
<id>assembly</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<!-- 适配层依赖 -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion eden-demo-cola-start/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>modules</outputDirectory>
<outputDirectory>app</outputDirectory>
<fileMode>0755</fileMode>
<includes>
<include>${project.build.finalName}.jar</include>
Expand Down
4 changes: 2 additions & 2 deletions eden-demo-cola-start/src/main/assembly/bin/catalina.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

set APP_DIR=..\target
set APP_DIR=..\app
set APP_PATTERN=%APP_DIR%\*.jar
for /f "delims=\" %%a in ('dir /b /a-d /o-d %APP_PATTERN%') do (
set APP_NAME=%APP_DIR%\%%a
Expand All @@ -13,7 +13,7 @@ if "%1" == "start" (
java -version
)
echo start %APP_NAME%
start "%APP_NAME%" java -server -Xms512m -Xmx512m -Dfile.encoding=UTF-8 -jar %APP_NAME% --spring.config.additional-location=../conf/ --logging.file.path=../logs/
start "%APP_NAME%" java -server -Xms1g -Xmx1g -Dfile.encoding=UTF-8 -jar %APP_NAME% --spring.config.additional-location=../conf/ --logging.file.path=../logs/
) else if "%1" == "stop" (
echo stop %APP_NAME%
taskkill /fi "WINDOWTITLE eq %APP_NAME%"
Expand Down
4 changes: 2 additions & 2 deletions eden-demo-cola-start/src/main/assembly/bin/catalina.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# limitations under the License.
#

APP_DIR="../target"
APP_DIR="../app"
APP_PATTERN="$APP_DIR/*.jar"
APP_NAME=$(ls -l $APP_PATTERN | awk '{print $9}')
APP_JVM="-server -Xms512m -Xmx512m"
APP_JVM="-server -Xms1g -Xmx1g"
APP_PID=$(ps -ef | grep java | grep $APP_NAME | grep -v grep | awk '{print $2}')

if [ $1 == "start" ]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright 2012-2019 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Client Error Code
REQ-ERROR-400=Bad request
REQ-LIMIT-429=Request limit
REQ-FLOW-429=Flow block
REQ-DEGRADE-429=Server degrade
REQ-PARAM-429=Param flow control block
REQ-BLOCK-429=System block
REQ-AUTH-429=Authority block
REQ-REPEAT-409=Duplicate request limit
REQ-UNIQUE-401=Idempotent token required
REQ-UNIQUE-403=Invalid idempotent token
REQ-UNIQUE-409=Idempotent request repetition limit
USER-DISABLED-403=User not active
USER-ACCESS-403=User has no permission
USER-LOGIN-401=Login session has expired
USER-FOUND-404=User not found or deleted
USER-AUTH-400=Authentication failed
PWD-INVALID-400=Invalid password
# Server Error Code
SYS-ERROR-500=Internal server error
PROP-REQUIRED-500=Property '{}' is required
MQ-PRODUCE-500=Message produce failed
MQ-CONSUME-500=Message consume failed
DUBBO-DEGRADE-429=Trigger dubbo degrade
ZK-ERROR-500=Zookeeper error
LOCK-ACQUIRE-500=Acquire lock failed
LOCK-RELEASE-500=Release lock failed
LOCK-TIMEOUT-500=Acquire lock timeout
EXT-LOAD-404=Extension not found named '{}'
# Third Error Code
SMS-SEND-500=Send sms failed
SMS-SERVER-500=Sms server error
SMS-SERVER-502=Send sms to server timeout
MAIL-SEND-500=Send mail failed
MAIL-SERVER-500=Mail server error
MAIL-SERVER-502=Send mail to server timeout
Loading

0 comments on commit 7c2d12e

Please sign in to comment.