Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature'
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyuanlu committed Oct 7, 2023
2 parents 7a82eb3 + 6552552 commit 499bc07
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 52 deletions.
32 changes: 21 additions & 11 deletions .coding/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ pipeline {
MAVEN_RELEASES_ID = "${CCI_CURRENT_TEAM}-${PROJECT_NAME}-${MAVEN_RELEASES_NAME}"
MAVEN_RELEASES_URL = "${CCI_CURRENT_WEB_PROTOCOL}://${CCI_CURRENT_TEAM}-maven.pkg.${CCI_CURRENT_DOMAIN}/repository/${PROJECT_NAME}/${MAVEN_RELEASES_NAME}/"

DOCKER_REPOSITORY = "shiyindaxiaojie/eden-demo-cola"
MAVEN_SNAPSHOTS_NAME = "maven-snapshots"
MAVEN_RELEASES_NAME = "maven-releases"
DOCKER_REPOSITORY_NAME = "docker"

MAVEN_SNAPSHOTS_ID = "${CCI_CURRENT_TEAM}-${PROJECT_NAME}-${MAVEN_SNAPSHOTS_NAME}"
MAVEN_SNAPSHOTS_URL = "${CCI_CURRENT_WEB_PROTOCOL}://${CCI_CURRENT_TEAM}-maven.pkg.${CCI_CURRENT_DOMAIN}/repository/${PROJECT_NAME}/${MAVEN_SNAPSHOTS_NAME}/"
MAVEN_RELEASES_ID = "${CCI_CURRENT_TEAM}-${PROJECT_NAME}-${MAVEN_RELEASES_NAME}"
MAVEN_RELEASES_URL = "${CCI_CURRENT_WEB_PROTOCOL}://${CCI_CURRENT_TEAM}-maven.pkg.${CCI_CURRENT_DOMAIN}/repository/${PROJECT_NAME}/${MAVEN_RELEASES_NAME}/"
DOCKER_REPOSITORY = "${CCI_CURRENT_TEAM}-docker.pkg.${CCI_CURRENT_DOMAIN}/${PROJECT_NAME}/${DOCKER_REPOSITORY_NAME}"
}
stages {
stage('检出') {
Expand Down Expand Up @@ -99,8 +107,8 @@ pipeline {
}
}
stage('推送到 Maven 制品库') {
steps {
withCredentials([
steps {
withCredentials([
usernamePassword(
credentialsId: env.MAVEN_RELEASES,
usernameVariable: 'MAVEN_RELEASES_USERNAME',
Expand All @@ -125,26 +133,28 @@ pipeline {
sh 'mvn -T 4C -Pcoding deploy -DskipTests -s ./.coding/settings.xml'
}
}
}
}
stage('推送到 Docker 制品库') {
}
}
stage('推送到 Docker 制品库') {
steps {
withCredentials([
usernamePassword(
credentialsId: env.DOCKER_CREDENTIALS,
credentialsId: env.DOCKER_REGISTRY_CREDENTIALS_ID,
usernameVariable: 'DOCKER_USERNAME',
passwordVariable: 'DOCKER_PASSWORD'
)
]) {
withEnv([
"DOCKER_USERNAME=${DOCKER_USERNAME}",
"DOCKER_PASSWORD=${DOCKER_PASSWORD}",
"DOCKER_IMAGE=${DOCKER_REPOSITORY}:${ARTIFACT_VERSION}"
"DOCKER_PASSWORD=${DOCKER_PASSWORD}"
]) {
sh 'mvn -Pcoding -pl eden-demo-layer-start jib:build -Djib.disableUpdateChecks=true -DskipTests -s ./.coding/settings.xml'
sh "docker login ${DOCKER_REPOSITORY} -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}"
sh "docker build -t ${DOCKER_REPOSITORY}/${DEPOT_NAME}:${ARTIFACT_VERSION} -f docker/Dockerfile ."
sh "docker push ${DOCKER_REPOSITORY}/${DEPOT_NAME}:${ARTIFACT_VERSION}"
sh "docker push ${DOCKER_REPOSITORY}/${DEPOT_NAME}:latest"
}
}
}
}
}
}
}
43 changes: 21 additions & 22 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,42 @@

```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-layer/blob/main/eden-demo-layer-start/src/main/resources/config/application-local.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` 关闭自动配置。您可以根据实际情况开启配置,直接完成组件的集成。

## 如何部署

### JAR 程序部署
### FatJar 程序部署

在项目根目录执行以下命令,生成 JAR 可执行程序
执行 `mvn clean package` 打包成一个 fat jar,参考如下命令启动编译后的控制台

```bash
mvn -T 4C -U package
mvn -T 4C deploy # 可选项,发布依赖到私服
java -Dserver.port=8080 -jar target/eden-demo-cola.jar
```

### Jib 镜像部署
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ spring:

## 如何部署

### JAR 程序部署
### FatJar 程序部署

在项目根目录执行以下命令,生成 JAR 可执行程序
执行 `mvn clean package` 打包成一个 fat jar,参考如下命令启动编译后的控制台

```bash
mvn -T 4C -U package
mvn -T 4C deploy # 可选项,发布依赖到私服
java -Dserver.port=8080 -jar target/eden-demo-cola.jar
```

### Jib 镜像部署
Expand Down
19 changes: 14 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ FROM openjdk:11-jdk-slim as builder

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

# 复制应用程序 JAR 文件
COPY $MODULE/target/*.jar application.jar
# 复制必要文件
COPY $MODULE/target/$MODULE.jar application.jar
COPY docker/entrypoint.sh entrypoint.sh

# 使用 Spring Boot 的分层模式提取 JAR 文件的依赖项
RUN java -Djarmode=layertools -jar application.jar extract
Expand All @@ -21,8 +22,14 @@ ARG USER=tmpuser
ARG GROUP=tmpgroup
ARG HOME=/app
ARG LOG=$HOME/logs
ENV WORKDIR $HOME
ENV START_DELAY_SECS 1
ENV JAVA_OPTS "-Xmx512m -Xms512m -Xmn256m"
ENV JVM_DEBUG "n"
ENV JVM_XMS "1g"
ENV JVM_XMX "1g"
ENV JVM_XMN "512m"
ENV JVM_MS "128m"
ENV JVM_MMS "320m"
ENV SPRING_PROFILES_ACTIVE "dev"
ENV SERVER_PORT "8080"
ENV MANAGEMENT_SERVER_PORT "9080"
Expand All @@ -42,6 +49,8 @@ COPY --from=builder /app/organization-dependencies ./
COPY --from=builder /app/modules-dependencies ./
COPY --from=builder /app/snapshot-dependencies/ ./
COPY --from=builder /app/application/ ./
COPY --from=builder /app/entrypoint.sh ./
RUN chmod +x entrypoint.sh

# 设置容器用户并创建日志目录
USER $USER
Expand All @@ -52,4 +61,4 @@ RUN mkdir $LOG \

# 设置启动入口和端口
EXPOSE $SERVER_PORT $MANAGEMENT_SERVER_PORT
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" "$@"
ENTRYPOINT ["./entrypoint.sh"]
13 changes: 13 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

JAVA_OPTS="${JAVA_OPTS} -XX:+UseG1GC"
JAVA_OPTS="${JAVA_OPTS} -server -Xms${JVM_XMS} -Xmx${JVM_XMX} -Xmn${JVM_XMN} -XX:MetaspaceSize=${JVM_MS} -XX:MaxMetaspaceSize=${JVM_MMS}"
JAVA_OPTS="${JAVA_OPTS} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${WORKDIR}/logs/java_heapdump.hprof"
JAVA_OPTS="${JAVA_OPTS} -XX:-UseLargePages"
if [[ "${JVM_DEBUG}" == "y" ]]; then
JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
fi

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" "$@"
16 changes: 11 additions & 5 deletions eden-demo-layer-start/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,33 @@
</entrypoint>
<ports>
<port>8080</port>
<port>9080</port>
</ports>
<environment>
<TZ>Asia/Shanghai</TZ>
<JAVA_OPTS>-Xms512m -Xmx512m -Xmn256m -Dserver.port=8080</JAVA_OPTS>
<START_DELAY_SECS>1</START_DELAY_SECS>
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
<JVM_DEBUG>n</JVM_DEBUG>
<JVM_XMS>1g</JVM_XMS>
<JVM_XMX>1g</JVM_XMX>
<JVM_XMN>512m</JVM_XMN>
<JVM_MS>128m</JVM_MS>
<JVM_MMS>320m</JVM_MMS>
<JAVA_OPTS>-Dserver.port=8080 -Dmanagement.server.port=9080</JAVA_OPTS>
<SPRING_PROFILES_ACTIVE>320m</SPRING_PROFILES_ACTIVE>
</environment>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
<mainClass>${start-class}</mainClass>
</container>
<extraDirectories>
<paths>src/main/docker</paths>
<paths>src/main/docker/jib</paths>
<permissions>
<permission>
<file>/entrypoint.sh</file>
<mode>755</mode>
</permission>
</permissions>
</extraDirectories>
<allowInsecureRegistries>true
</allowInsecureRegistries>
<allowInsecureRegistries>true</allowInsecureRegistries>
</configuration>
</plugin>
</plugins>
Expand Down
4 changes: 0 additions & 4 deletions eden-demo-layer-start/src/main/docker/entrypoint.sh

This file was deleted.

13 changes: 13 additions & 0 deletions eden-demo-layer-start/src/main/docker/jib/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

JAVA_OPTS="${JAVA_OPTS} -XX:+UseG1GC"
JAVA_OPTS="${JAVA_OPTS} -server -Xms${JVM_XMS} -Xmx${JVM_XMX} -Xmn${JVM_XMN} -XX:MetaspaceSize=${JVM_MS} -XX:MaxMetaspaceSize=${JVM_MMS}"
JAVA_OPTS="${JAVA_OPTS} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${WORKDIR}/logs/java_heapdump.hprof"
JAVA_OPTS="${JAVA_OPTS} -XX:-UseLargePages"
if [[ "${JVM_DEBUG}" == "y" ]]; then
JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
fi

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 -cp /app/resources/:/app/classes/:/app/libs/* "org.ylzl.eden.demo.LayerApplication" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,18 @@ dubbo: # 分布式调用组件
base-packages: org.ylzl.eden.demo.adapter # Dubbo 服务扫描
application:
id: ${spring.application.name}
qos-enable: false
qos-port: 21882
protocol:
name: dubbo
port: 20881 # 开发环境可以使用 -1 生成随机端口
port: 20882 # 开发环境可以使用 -1 生成随机端口
registry:
id: ${spring.application.name}
protocol: nacos
address: nacos://${spring.cloud.nacos.discovery.server-addr}?namespace=${spring.cloud.nacos.discovery.namespace}&group=dubbo
check: false # 是否开启服务注册的启动检查
register: true # 是否开启服务注册,设置为 false 表示只订阅不注册
enable-empty-protection: true # 是否开启推空保护
metadata-report:
address: nacos://${spring.cloud.nacos.discovery.server-addr}?namespace=${spring.cloud.nacos.discovery.namespace}&group=dubbo
config-center:
Expand Down

0 comments on commit 499bc07

Please sign in to comment.