57 lines
1.6 KiB
Docker
57 lines
1.6 KiB
Docker
# 第一阶段:使用Maven构建项目
|
||
FROM maven:3.8.7-openjdk-17 AS builder
|
||
|
||
# 设置工作目录
|
||
WORKDIR /workspace
|
||
|
||
# 复制所有POM文件以利用Docker缓存层
|
||
COPY pom.xml .
|
||
COPY aircraft-common/pom.xml ./aircraft-common/
|
||
COPY aircraft-generator/pom.xml ./aircraft-generator/
|
||
COPY aircraft-logging/pom.xml ./aircraft-logging/
|
||
COPY aircraft-system/pom.xml ./aircraft-system/
|
||
COPY aircraft-tools/pom.xml ./aircraft-tools/
|
||
|
||
# 下载依赖项(仅当pom文件更改时才会重新执行)
|
||
RUN mvn -B dependency:go-offline
|
||
|
||
# 复制源代码
|
||
COPY aircraft-common/src ./aircraft-common/src
|
||
COPY aircraft-generator/src ./aircraft-generator/src
|
||
COPY aircraft-logging/src ./aircraft-logging/src
|
||
COPY aircraft-system/src ./aircraft-system/src
|
||
COPY aircraft-tools/src ./aircraft-tools/src
|
||
|
||
# 构建整个项目并跳过测试
|
||
RUN mvn -B package -pl aircraft-system -am -DskipTests
|
||
|
||
# 第二阶段:创建运行时镜像
|
||
FROM eclipse-temurin:17-jre-alpine
|
||
|
||
# 设置元数据
|
||
LABEL maintainer="aircraft-team"
|
||
LABEL module="aircraft-system"
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 从构建阶段复制生成的JAR文件
|
||
COPY --from=builder /workspace/aircraft-system/target/*.jar app.jar
|
||
|
||
# 设置时区
|
||
ENV TZ=Asia/Shanghai
|
||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||
|
||
# 暴露默认端口
|
||
EXPOSE 8000
|
||
|
||
# 设置JVM参数
|
||
ENV JAVA_OPTS="-Xmx512m -Xms256m -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
|
||
|
||
# 健康检查
|
||
HEALTHCHECK --interval=30s --timeout=3s \
|
||
CMD wget -q -O - http://localhost:8000/actuator/health || exit 1
|
||
|
||
# 启动应用
|
||
ENTRYPOINT exec java $JAVA_OPTS -jar app.jar
|