docker
This commit is contained in:
parent
1354597863
commit
9eae7e424f
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -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"]
|
25
docker-compose.yml
Normal file
25
docker-compose.yml
Normal file
@ -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:
|
61
src/main/resources/application-prod.yml
Normal file
61
src/main/resources/application-prod.yml
Normal file
@ -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 # 上传文件路径前缀
|
@ -27,9 +27,7 @@ spring:
|
|||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: update
|
ddl-auto: update
|
||||||
# 可选值:create-drop,create,update,none. create-drop:每次启动项目都会删除表,然后重新创建表,适合开发环境;create:每次启动项目都会创建表,适合开发环境;update:每次启动项目都会更新表,适合开发环境;none:不执行任何操作,适合生产环境。
|
# 可选值:create-drop,create,update,none. create-drop:每次启动项目都会删除表,然后重新创建表,适合开发环境;create:每次启动项目都会创建表,适合开发环境;update:每次启动项目都会更新表,适合开发环境;none:不执行任何操作,适合生产环境。
|
||||||
properties:
|
|
||||||
hibernate:
|
|
||||||
format_sql: true
|
|
||||||
# 静态资源目录配置
|
# 静态资源目录配置
|
||||||
resources:
|
resources:
|
||||||
static-locations: classpath:/static/,file:/home/whz/tmp/ # 指定静态资源的位置
|
static-locations: classpath:/static/,file:/home/whz/tmp/ # 指定静态资源的位置
|
||||||
|
Loading…
Reference in New Issue
Block a user