diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ae08307 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM gradle:8.0.0-jdk17 AS build +WORKDIR /app + +# 将Gradle的配置文件复制到镜像中 +COPY gradlew . +COPY gradle gradle +COPY build.gradle . +COPY settings.gradle . + +COPY src src +# 构建应用 +RUN gradle bootJar + +# 使用官方的Java运行时作为最终的运行环境 +FROM openjdk:17-jdk-slim +WORKDIR /app +COPY --from=build/libs /app/build/libs/*.jar app.jar + +# 设置应用运行的端口 +EXPOSE 8080 + + +# 启动应用 +ENTRYPOINT ["java","-jar","/app/app.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cd2ea84 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.8' + +services: + db: + image: mysql:8.0.30 + restart: always + environment: + MYSQL_ROOT_PASSWORD: example + MYSQL_DATABASE: mydb + MYSQL_USER: myuser + MYSQL_PASSWORD: mypassword + volumes: + - dbdata:/var/lib/mysql + + app: + build: . + ports: + - "8080:8080" + depends_on: + - db + environment: + - SPRING_PROFILES_ACTIVE=prod + +volumes: + dbdata: \ 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..15ab256 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,61 @@ +springdoc: + swagger-ui: + path: /api-docs + +spring: + jackson: + property-naming-strategy: SNAKE_CASE # 驼峰转下划线 + datasource: + url: jdbc:mysql://db:3306/paopao?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true # MySQL连接URL,paopao是数据库名 + driverClassName: com.mysql.cj.jdbc.Driver # MySQL的Driver类名 + username: root # MySQL用户名 + password: root # MySQL密码 + + jpa: + show-sql: true + open-in-view: false + defer-datasource-initialization: true + database-platform: org.hibernate.dialect.MySQL8Dialect # 修改为MySQL的Dialect + hibernate: + ddl-auto: update # 根据需要调整,update适用于开发和某些生产环境 + format_sql: true # 保持原样,用于格式化SQL输出 + # 静态资源目录配置 + resources: + static-locations: classpath:/static/,file:/home/whz/tmp/ # 指定静态资源的位置 + +management: + endpoints: + web: + exposure: + include: "*" +# exclude: "health,metrics,prometheus,info,logfile,loggers,env,env-to-props,env-reactive,configprops,configprops-reactive,threaddump,heapdump,beans,scheduledtasks,mappings,httptrace,sessions,caches,cache,sessions-reactive,caches-reactive,cache-reactive,schedules,schedules-reactive,jolokia,jolokia-reactive,logfile-reactive,loggers-reactive,refresh,flyway,liquibase,liquibase-re + +app: + version: v1 + default: + head-icon: https://assets.paopao.info/public/avatar/default/joshua.png + security: + jwt: + secret-key: uYuVw0mke38MfLhO19wUQyRgwrmYo89ibpQTXPHi4vg= + expiration: 36000000 + white-list: # 白名单 + - path: "/api-docs/**" + methods: ["GET","PUT","POST"] + - path: "/swagger-ui/**" + methods: ["GET"] + - path: "/v3/**" + methods: [ "GET" ] + - path: "/h2/**" + methods: [ "GET","PUT","POST" ] + - path: "/v1/auth/**" + methods: [ "GET","PUT","POST"] + - path: "/upload/**" + methods: [ "GET" ] + - path: "/actuator/**" + methods: [ "GET" ] + allowed-origins: # 允许跨域的域名 + - "http://localhost:5173" + upload: + path: /home/whz/tmp/upload # 上传文件路径 + sub-path-name-length: 2 # 上传文件路径子目录长度 + base-url: http://localhost:8080/upload # 上传文件路径前缀 \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9b7866a..6a73a44 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,9 +27,7 @@ spring: hibernate: ddl-auto: update # 可选值:create-drop,create,update,none. create-drop:每次启动项目都会删除表,然后重新创建表,适合开发环境;create:每次启动项目都会创建表,适合开发环境;update:每次启动项目都会更新表,适合开发环境;none:不执行任何操作,适合生产环境。 - properties: - hibernate: - format_sql: true + # 静态资源目录配置 resources: static-locations: classpath:/static/,file:/home/whz/tmp/ # 指定静态资源的位置