Skip to content

Commit 33aee81

Browse files
author
guoyuanlu
committed
update
1 parent 4cf0a50 commit 33aee81

17 files changed

+191
-109
lines changed

Diff for: README-zh-CN.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,49 @@ spring:
7878
datasource: # 数据源管理
7979
username:
8080
password:
81-
url: jdbc:mysql://host:port/schema?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
81+
url: jdbc:mysql://host:port/schema?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
8282
driver-class-name: com.mysql.cj.jdbc.Driver
8383
```
8484

8585
此外,本项目还罗列了 `Redis` 缓存、`RocketMQ` 消息队列、`ShardingSphere` 分库分表等常用组件的使用方案,默认通过 `xxx.enabled` 关闭自动配置。您可以根据实际情况开启配置,直接完成组件的集成。
8686

87+
## 如何部署
88+
89+
### JAR 程序部署
90+
91+
在项目根目录执行以下命令,生成 JAR 可执行程序。
92+
93+
```bash
94+
mvn -T 4C -U package
95+
mvn -T 4C deploy # 可选项,发布依赖到私服
96+
```
97+
98+
### Jib 镜像部署
99+
100+
Google Jib 插件允许您在没有安装 Docker 下完成镜像的构建。
101+
102+
```bash
103+
mvn -T 4C -U package
104+
mvn -pl eden-demo-layer-start jib:build -Djib.disableUpdateChecks=true -DskipTests
105+
```
106+
107+
### Docker 容器部署
108+
109+
本项目使用了 Spring Boot 的镜像分层特性优化了镜像的构建效率,请确保正确安装了 Docker 工具,然后执行以下命令。
110+
111+
```bash
112+
docker build -f docker/Dockerfile -t eden-demo-layer:{tag} .
113+
```
114+
115+
### Helm 打包部署
116+
117+
以应用为中心,建议使用 Helm 统一管理所需部署的 K8s 资源描述文件,请参考以下命令完成应用的安装和卸载。
118+
119+
```bash
120+
helm install eden-demo-layer ./helm # 部署资源
121+
helm uninstall eden-demo-layer # 卸载资源
122+
```
123+
87124
## 版本规范
88125

89126
项目的版本号格式为 `x.y.z` 的形式,其中 x 的数值类型为数字,从 0 开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用 0,即版本号为 `0.x.x` 的格式。

Diff for: README.md

+55-18
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,71 @@
5656

5757
```yaml
5858
spring:
59-
cloud:
60-
nacos:
61-
discovery: # 注册中心
62-
enabled: true # 默认关闭,请按需开启
63-
config: # 配置中心
64-
enabled: true # 默认关闭,请按需开启
59+
cloud:
60+
nacos:
61+
discovery: # 注册中心
62+
enabled: true # 默认关闭,请按需开启
63+
config: # 配置中心
64+
enabled: true # 默认关闭,请按需开启
6565
```
6666
6767
**修改默认的数据源**:本项目默认使用 `H2` 内存数据库启动,基于 `Liquibase` 在项目启动时自动初始化 SQL 脚本。如果您使用的是外部的 MySQL 数据库,可以从此处调整下数据库的连接信息:[application-local.yml](https://github.com/shiyindaxiaojie/eden-demo-layer/blob/main/eden-demo-layer-start/src/main/resources/config/application-local.yml),请删除任何与 `H2` 有关的配置。
6868

6969
```yaml
7070
spring:
71-
# h2: # 内存数据库
72-
# console:
73-
# enabled: true # 线上环境请勿设置
74-
# path: /h2-console
75-
# settings:
76-
# trace: false
77-
# web-allow-others: false
78-
datasource: # 数据源管理
79-
username:
80-
password:
81-
url: jdbc:mysql://host:port/schema?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
82-
driver-class-name: com.mysql.cj.jdbc.Driver
71+
# h2: # 内存数据库
72+
# console:
73+
# enabled: true # 线上环境请勿设置
74+
# path: /h2-console
75+
# settings:
76+
# trace: false
77+
# web-allow-others: false
78+
datasource: # 数据源管理
79+
username:
80+
password:
81+
url: jdbc:mysql://host:port/schema?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
82+
driver-class-name: com.mysql.cj.jdbc.Driver
8383
```
8484

8585
此外,本项目还罗列了 `Redis` 缓存、`RocketMQ` 消息队列、`ShardingSphere` 分库分表等常用组件的使用方案,默认通过 `xxx.enabled` 关闭自动配置。您可以根据实际情况开启配置,直接完成组件的集成。
8686

87+
## 如何部署
88+
89+
### JAR 程序部署
90+
91+
在项目根目录执行以下命令,生成 JAR 可执行程序。
92+
93+
```bash
94+
mvn -T 4C -U package
95+
mvn -T 4C deploy # 可选项,发布依赖到私服
96+
```
97+
98+
### Jib 镜像部署
99+
100+
Google Jib 插件允许您在没有安装 Docker 下完成镜像的构建。
101+
102+
```bash
103+
mvn -T 4C -U package
104+
mvn -pl eden-demo-layer-start jib:build -Djib.disableUpdateChecks=true -DskipTests
105+
```
106+
107+
### Docker 容器部署
108+
109+
本项目使用了 Spring Boot 的镜像分层特性优化了镜像的构建效率,请确保正确安装了 Docker 工具,然后执行以下命令。
110+
111+
```bash
112+
docker build -f docker/Dockerfile -t eden-demo-layer:{tag} .
113+
```
114+
115+
### Helm 打包部署
116+
117+
以应用为中心,建议使用 Helm 统一管理所需部署的 K8s 资源描述文件,请参考以下命令完成应用的安装和卸载。
118+
119+
```bash
120+
helm install eden-demo-layer ./helm # 部署资源
121+
helm uninstall eden-demo-layer # 卸载资源
122+
```
123+
87124
## 版本规范
88125

89126
项目的版本号格式为 `x.y.z` 的形式,其中 x 的数值类型为数字,从 0 开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用 0,即版本号为 `0.x.x` 的格式。

Diff for: docker/Dockerfile

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 使用基础镜像
2-
FROM openjdk:8-jdk-alpine as builder
2+
FROM openjdk:11-jdk-slim as builder
33

44
# 设置工作目录并指定构建模块
55
WORKDIR /app
6-
ARG MODULE=eden-demo-layer-start
6+
ARG MODULE=eden-demo-cola-start
77

88
# 复制应用程序 JAR 文件
99
COPY $MODULE/target/*.jar application.jar
@@ -12,12 +12,13 @@ COPY $MODULE/target/*.jar application.jar
1212
RUN java -Djarmode=layertools -jar application.jar extract
1313

1414
# 创建容器镜像
15-
FROM openjdk:8-jdk-alpine
15+
FROM openjdk:11-jdk-slim
1616

1717
# 定义镜像元数据和环境变量
1818
LABEL maintainer="梦想歌 <[email protected]>"
1919
LABEL version="1.0.0"
2020
ARG USER=tmpuser
21+
ARG GROUP=tmpgroup
2122
ARG HOME=/app
2223
ARG LOG=$HOME/logs
2324
ENV START_DELAY_SECS 1
@@ -27,9 +28,11 @@ ENV SERVER_PORT "8080"
2728
ENV MANAGEMENT_SERVER_PORT "9080"
2829

2930
# 创建普通用户并设置工作目录
30-
RUN addgroup --gid 1000 "$USER" \
31-
&& adduser -u 1000 -G "$USER" -h "$HOME" "$USER" --disabled-password \
32-
&& chown $USER:$USER $HOME
31+
RUN groupadd -g 1000 $GROUP \
32+
&& useradd -u 1000 -g $GROUP -d $HOME -s /bin/bash $USER \
33+
&& mkdir $HOME \
34+
&& chown -R $USER:$GROUP $HOME \
35+
&& chmod -R a+rwX $HOME
3336
WORKDIR $HOME
3437

3538
# 复制应用程序依赖项和模块
@@ -49,4 +52,4 @@ RUN mkdir $LOG \
4952

5053
# 设置启动入口和端口
5154
EXPOSE $SERVER_PORT $MANAGEMENT_SERVER_PORT
52-
ENTRYPOINT exec java $JAVA_OPTS -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom "org.springframework.boot.loader.JarLauncher" "$@"
55+
ENTRYPOINT echo "The application will start in ${START_DELAY_SECS}s..." && sleep ${START_DELAY_SECS} && exec java $JAVA_OPTS -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom "org.springframework.boot.loader.JarLauncher" "$@"

Diff for: docs/config/datasource.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spring:
66
driver-class-name: org.h2.Driver
77
# username: root
88
# password: demo@123
9-
# url: jdbc:mysql://localhost:3306/demo?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
9+
# url: jdbc:mysql://localhost:3306/demo?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
1010
# driver-class-name: com.mysql.cj.jdbc.Driver
1111
type: com.zaxxer.hikari.HikariDataSource
1212
hikari:

Diff for: docs/config/dynamic-datasource.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ spring:
88
ds1:
99
username:
1010
password:
11-
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
11+
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
1212
driver-class-name: com.mysql.cj.jdbc.Driver
1313
type: com.zaxxer.hikari.HikariDataSource
1414
ds2:
1515
username:
1616
password:
17-
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
17+
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
1818
driver-class-name: com.mysql.cj.jdbc.Driver
1919
type: com.zaxxer.hikari.HikariDataSource

Diff for: docs/config/sharding-sphere.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ spring:
66
ds1:
77
username: root
88
password: demo@123
9-
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
9+
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
1010
driver-class-name: com.mysql.cj.jdbc.Driver
1111
type: com.zaxxer.hikari.HikariDataSource
1212
ds2:
1313
username: root
1414
password: demo@123
15-
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
15+
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
1616
driver-class-name: com.mysql.cj.jdbc.Driver
1717
type: com.zaxxer.hikari.HikariDataSource

Diff for: eden-demo-layer-start/src/main/resources/config/application-dev.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spring:
1515
driver-class-name: org.h2.Driver
1616
# username: root
1717
# password: demo@123
18-
# url: jdbc:mysql://localhost:3306/demo?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
18+
# url: jdbc:mysql://localhost:3306/demo?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
1919
# driver-class-name: com.mysql.cj.jdbc.Driver
2020
dynamic: # 多数据源,使用 @DS 切换
2121
enabled: false # 默认关闭,请按需开启
@@ -25,13 +25,13 @@ spring:
2525
ds1:
2626
username: root
2727
password: demo@123
28-
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
28+
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
2929
driver-class-name: com.mysql.cj.jdbc.Driver
3030
type: com.zaxxer.hikari.HikariDataSource
3131
ds2:
3232
username: root
3333
password: demo@123
34-
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
34+
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
3535
driver-class-name: com.mysql.cj.jdbc.Driver
3636
type: com.zaxxer.hikari.HikariDataSource
3737
shardingsphere: # 分库分表组件
@@ -41,13 +41,13 @@ spring:
4141
ds1:
4242
username: root
4343
password: demo@123
44-
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
44+
url: jdbc:mysql://localhost:3306/ds1?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
4545
driver-class-name: com.mysql.cj.jdbc.Driver
4646
type: com.zaxxer.hikari.HikariDataSource
4747
ds2:
4848
username: root
4949
password: demo@123
50-
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
50+
url: jdbc:mysql://localhost:3306/ds2?rewriteBatchedStatements=true&useSSL=false&useOldAliasMetadataBehavior=true&useUnicode=true&serverTimezone=GMT%2B8
5151
driver-class-name: com.mysql.cj.jdbc.Driver
5252
type: com.zaxxer.hikari.HikariDataSource
5353
rules:

Diff for: helm/Chart.yaml

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
apiVersion: v2
2-
name: helm
3-
description: Eden* demo cola for kubernetes
2+
name: eden-demo-layer
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
413
type: application
5-
version: 0.0.1-SNAPSHOT
6-
appVersion: ">=1.16.0-0"
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.0.0"

Diff for: helm/templates/NOTES.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
{{- end }}
77
{{- end }}
88
{{- else if contains "NodePort" .Values.service.type }}
9-
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "helm.fullname" . }})
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "eden-demo-layer.fullname" . }})
1010
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
1111
echo http://$NODE_IP:$NODE_PORT
1212
{{- else if contains "LoadBalancer" .Values.service.type }}
1313
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14-
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "helm.fullname" . }}'
15-
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helm.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "eden-demo-layer.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "eden-demo-layer.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
1616
echo http://$SERVICE_IP:{{ .Values.service.port }}
1717
{{- else if contains "ClusterIP" .Values.service.type }}
18-
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "helm.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "eden-demo-layer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
1919
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
2020
echo "Visit http://127.0.0.1:8080 to use your application"
2121
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT

Diff for: helm/templates/_helpers.tpl

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{/*
22
Expand the name of the chart.
33
*/}}
4-
{{- define "helm.name" -}}
4+
{{- define "eden-demo-layer.name" -}}
55
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
66
{{- end }}
77

@@ -10,7 +10,7 @@ Create a default fully qualified app name.
1010
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1111
If release name contains chart name it will be used as a full name.
1212
*/}}
13-
{{- define "helm.fullname" -}}
13+
{{- define "eden-demo-layer.fullname" -}}
1414
{{- if .Values.fullnameOverride }}
1515
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
1616
{{- else }}
@@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
2626
{{/*
2727
Create chart name and version as used by the chart label.
2828
*/}}
29-
{{- define "helm.chart" -}}
29+
{{- define "eden-demo-layer.chart" -}}
3030
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
3131
{{- end }}
3232

3333
{{/*
3434
Common labels
3535
*/}}
36-
{{- define "helm.labels" -}}
37-
helm.sh/chart: {{ include "helm.chart" . }}
38-
{{ include "helm.selectorLabels" . }}
36+
{{- define "eden-demo-layer.labels" -}}
37+
helm.sh/chart: {{ include "eden-demo-layer.chart" . }}
38+
{{ include "eden-demo-layer.selectorLabels" . }}
3939
{{- if .Chart.AppVersion }}
4040
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4141
{{- end }}
@@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
4545
{{/*
4646
Selector labels
4747
*/}}
48-
{{- define "helm.selectorLabels" -}}
49-
app.kubernetes.io/name: {{ include "helm.name" . }}
48+
{{- define "eden-demo-layer.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "eden-demo-layer.name" . }}
5050
app.kubernetes.io/instance: {{ .Release.Name }}
5151
{{- end }}
5252

5353
{{/*
5454
Create the name of the service account to use
5555
*/}}
56-
{{- define "helm.serviceAccountName" -}}
56+
{{- define "eden-demo-layer.serviceAccountName" -}}
5757
{{- if .Values.serviceAccount.create }}
58-
{{- default (include "helm.fullname" .) .Values.serviceAccount.name }}
58+
{{- default (include "eden-demo-layer.fullname" .) .Values.serviceAccount.name }}
5959
{{- else }}
6060
{{- default "default" .Values.serviceAccount.name }}
6161
{{- end }}

0 commit comments

Comments
 (0)