From 32c3be920ec2692d9c54590bfebe525e1c22d1e6 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Thu, 14 Aug 2025 14:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86docker=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile => Dockerfile-env | 2 +- Dockerfile-prod | 41 +++++++++ .../example/caseData/CaseDataApplication.java | 2 +- src/main/resources/application-dev.yml | 86 +++++++++++++++++++ src/main/resources/application-prod.yml | 86 +++++++++++++++++++ 5 files changed, 215 insertions(+), 2 deletions(-) rename Dockerfile => Dockerfile-env (94%) create mode 100644 Dockerfile-prod create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-prod.yml diff --git a/Dockerfile b/Dockerfile-env similarity index 94% rename from Dockerfile rename to Dockerfile-env index 6f29fed..5e9798f 100644 --- a/Dockerfile +++ b/Dockerfile-env @@ -38,4 +38,4 @@ COPY --from=builder /app/target/caseData-1.0.0.jar app.jar EXPOSE 5477 # 启动应用 -ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=dev"] \ No newline at end of file diff --git a/Dockerfile-prod b/Dockerfile-prod new file mode 100644 index 0000000..9c9f093 --- /dev/null +++ b/Dockerfile-prod @@ -0,0 +1,41 @@ +# 第一阶段:构建 JAR 包 +FROM maven:3.9.2-eclipse-temurin-17-alpine AS builder + +WORKDIR /app + +# 添加国内 Maven 镜像源 +RUN mkdir -p /root/.m2 && \ + echo ' \ + \ + \ + aliyun \ + * \ + aliyun maven \ + https://maven.aliyun.com/repository/public \ + \ + \ + ' > /root/.m2/settings.xml + +# 将 pom.xml 和 src 目录复制到容器 +COPY pom.xml . +COPY src ./src + +# 执行 Maven 打包 +RUN mvn clean package -DskipTests + +# 第二阶段:运行镜像 +FROM eclipse-temurin:17-jdk-alpine + +WORKDIR /app + +# 将构建好的 JAR 包从构建阶段复制到运行阶段 +COPY --from=builder /app/target/caseData-1.0.0.jar app.jar + +# 暴露端口 +EXPOSE 5477 + +# 启动应用 +ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=prod"] \ No newline at end of file diff --git a/src/main/java/com/example/caseData/CaseDataApplication.java b/src/main/java/com/example/caseData/CaseDataApplication.java index 84111eb..7e78300 100644 --- a/src/main/java/com/example/caseData/CaseDataApplication.java +++ b/src/main/java/com/example/caseData/CaseDataApplication.java @@ -1,5 +1,6 @@ package com.example.caseData; +import jakarta.annotation.PostConstruct; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -16,5 +17,4 @@ public class CaseDataApplication { SpringApplication.run(CaseDataApplication.class, args); } - } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..901aa0b --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,86 @@ +server: + port: 5477 + +# DataSource Config +spring: + application: + name: caseData + profiles: + active: dev + datasource: + driver-class-name: com.p6spy.engine.spy.P6SpyDriver + url: jdbc:p6spy:mysql://42.193.16.243:30001/case?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 + username: root + password: gdxz123456^%$d + data: + redis: + host: '139.155.127.177' + port: 30002 + password: gdxz2022&dj. + database: 9 + timeout: 3000 + jackson: + time-zone: Asia/Shanghai + default-property-inclusion: always + redis: + dev: + host: '139.155.127.177' + port: 30002 + password: gdxz2022&dj. + database: 9 + prod: + host: '139.155.127.177' + port: 30002 + password: gdxz2022&dj. + database: 10 + + +# MyBatis-Plus 配置 +mybatis-plus: + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 开启 SQL 日志 + map-underscore-to-camel-case: true + mapper-locations: "classpath:mapper/*.xml" + +# oss配置 +oss: + access-key: LTAI5tKmFrVCghcxX7yHyGhm + access-key-secret: q1aiIZCJJuf92YbKk2cSXnPES4zx26 + bucket: caseplatform + endpoint: oss-cn-beijing.aliyuncs.com + custom-domain-name: https://caseplatform.oss-cn-beijing.aliyuncs.com + +# [阿里大鱼短信] +dysms: + access-key: LTAI4GGygjsKhyBwvvC3CghV + access-secret: rcx7lO9kQxG10m8NqNPEfEtT9IS8EI + +# jwt配置 +jwt: + sign-key: 123456899 # 私钥 + ttl: 720 # 过期时间 小时 + algo: HS256 # 加密方式 + +# 日志 +logging: + level: + root: info # 全局日志级别 + file: + name: logs/app.log # 自定义日志文件路径 + pattern: + file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" + +# 微信 +wechat: + miniapp: + appid: wx152ad667d5075f27 + secret: 0b86e725d8f372fa05dad95a91d41c72 + +# [app] +app: + apiUrl: https://dev-wx.igandan.com + secretKey: nmBCF@hEK6eN&h03dYUin@AU3%bMf%$O + imagePrefix: https://dev-doc.igandan.com/app + platform: case-storge + platformPointAccount: GDXZadmin01 + access-token: XUUHml5iQ9mlFsa8QqOwyBrLI2nGGGxJ \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..6a48310 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,86 @@ +server: + port: 5477 + +# DataSource Config +spring: + application: + name: caseData + profiles: + active: dev + datasource: + driver-class-name: com.p6spy.engine.spy.P6SpyDriver + url: jdbc:p6spy:mysql://172.27.16.10:3306/case?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 + username: root + password: sKptsVOiTf6m3lt_ + data: + redis: + host: '139.155.127.177' + port: 30002 + password: gdxz2022&dj. + database: 9 + timeout: 3000 + jackson: + time-zone: Asia/Shanghai + default-property-inclusion: always + redis: + dev: + host: '139.155.127.177' + port: 30002 + password: gdxz2022&dj. + database: 9 + prod: + host: '139.155.127.177' + port: 30002 + password: gdxz2022&dj. + database: 10 + + +# MyBatis-Plus 配置 +mybatis-plus: + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 开启 SQL 日志 + map-underscore-to-camel-case: true + mapper-locations: "classpath:mapper/*.xml" + +# oss配置 +oss: + access-key: LTAI5tKmFrVCghcxX7yHyGhm + access-key-secret: q1aiIZCJJuf92YbKk2cSXnPES4zx26 + bucket: caseplatform + endpoint: oss-cn-beijing.aliyuncs.com + custom-domain-name: https://caseplatform.oss-cn-beijing.aliyuncs.com + +# [阿里大鱼短信] +dysms: + access-key: LTAI4GGygjsKhyBwvvC3CghV + access-secret: rcx7lO9kQxG10m8NqNPEfEtT9IS8EI + +# jwt配置 +jwt: + sign-key: 123456899 # 私钥 + ttl: 720 # 过期时间 小时 + algo: HS256 # 加密方式 + +# 日志 +logging: + level: + root: info # 全局日志级别 + file: + name: logs/app.log # 自定义日志文件路径 + pattern: + file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" + +# 微信 +wechat: + miniapp: + appid: wx152ad667d5075f27 + secret: 0b86e725d8f372fa05dad95a91d41c72 + +# [app] +app: + apiUrl: https://wx.igandan.com + secretKey: nmBCF@hEK6eN&h03dYUin@AU3%bMf%$O + imagePrefix: https://doc.igandan.com/app + platform: case-storge + platformPointAccount: GDXZadmin01 + access-token: XUUHml5iQ9mlFsa8QqOwyBrLI2nGGGxJ \ No newline at end of file