perf: multi-stage Dockerfile + remove Maven from CI — Docker layer caching instead

This commit is contained in:
2026-07-26 23:07:56 +08:00
parent 65ee61c6c9
commit 8ed5631969
2 changed files with 19 additions and 57 deletions
+17 -10
View File
@@ -1,17 +1,24 @@
# 使用官方 OpenJDK 作为基础镜像
FROM eclipse-temurin:17-jre
# 设置工作目录
# Stage 1: Maven 构建(Docker 层缓存自动缓存依赖)
FROM maven:3.9-eclipse-temurin-17 AS builder
WORKDIR /app
# 拷贝打包好的 JAR 文件到容器
COPY target/LPT.jar LPT.jar
# 先复制 pom.xml,单独一层 —— 只要依赖不变,这层就被缓存
COPY pom.xml .
RUN mvn dependency:go-offline -B -q
# 再复制源码构建
COPY src/ ./src/
RUN mvn package -DskipTests -B -q
# Stage 2: 运行时(精简 JRE
FROM eclipse-temurin:17-jre
WORKDIR /app
COPY --from=builder /app/target/LPT.jar LPT.jar
# 暴露应用运行的端口
EXPOSE 8888
# 启动应用
ENTRYPOINT ["java", "-jar", "LPT.jar"]
# 健康检查
HEALTHCHECK --interval=10s --timeout=5s CMD curl --fail http://localhost:8888/actuator/health || exit 1
HEALTHCHECK --interval=10s --timeout=5s \
CMD curl --fail http://localhost:8888/actuator/health || exit 1