2025-07-08 16:27:21 +08:00
|
|
|
|
# —— 第一阶段:Maven 构建 ——
|
2025-07-08 18:08:38 +08:00
|
|
|
|
FROM maven:3.8.7-eclipse-temurin-17-alpine AS builder
|
2025-07-08 16:27:21 +08:00
|
|
|
|
WORKDIR /workspace
|
2025-06-19 20:34:58 +08:00
|
|
|
|
|
2025-07-08 18:08:38 +08:00
|
|
|
|
# 把项目级 settings.xml 复制到容器里
|
|
|
|
|
COPY .mvn/settings.xml /root/.m2/settings.xml
|
|
|
|
|
|
2025-07-08 16:27:21 +08:00
|
|
|
|
# 1. 先只拷贝父 POM 及各模块的 pom.xml,加速依赖下载
|
|
|
|
|
COPY pom.xml ./pom.xml
|
|
|
|
|
COPY group-buying-sys-api/pom.xml ./group-buying-sys-api/pom.xml
|
|
|
|
|
COPY group-buying-sys-domain/pom.xml ./group-buying-sys-domain/pom.xml
|
|
|
|
|
COPY group-buying-sys-infrastructure/pom.xml ./group-buying-sys-infrastructure/pom.xml
|
|
|
|
|
COPY group-buying-sys-trigger/pom.xml ./group-buying-sys-trigger/pom.xml
|
|
|
|
|
COPY group-buying-sys-types/pom.xml ./group-buying-sys-types/pom.xml
|
|
|
|
|
COPY group-buying-sys-app/pom.xml ./group-buying-sys-app/pom.xml
|
2025-06-19 20:34:58 +08:00
|
|
|
|
|
2025-07-08 16:27:21 +08:00
|
|
|
|
# 离线下载所有依赖
|
|
|
|
|
RUN mvn dependency:go-offline -B
|
|
|
|
|
|
|
|
|
|
# 2. 拷贝所有源码
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
# 3. 只打包 main 应用模块(连带编译它依赖的模块),跳过测试,加速构建
|
|
|
|
|
RUN mvn \
|
|
|
|
|
-f pom.xml clean package \
|
|
|
|
|
-pl group-buying-sys-app -am \
|
|
|
|
|
-DskipTests -B
|
2025-06-19 20:34:58 +08:00
|
|
|
|
|
2025-07-08 16:27:21 +08:00
|
|
|
|
# —— 第二阶段:运行时镜像 ——
|
|
|
|
|
FROM openjdk:8-jre-slim
|
|
|
|
|
LABEL maintainer="smile"
|
|
|
|
|
|
|
|
|
|
# 可选:设置时区
|
2025-06-19 20:34:58 +08:00
|
|
|
|
ENV TZ=PRC
|
2025-07-08 16:27:21 +08:00
|
|
|
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
|
|
|
|
|
&& echo $TZ > /etc/timezone
|
2025-06-19 20:34:58 +08:00
|
|
|
|
|
2025-07-08 16:27:21 +08:00
|
|
|
|
# 把构建产物拷过来
|
|
|
|
|
COPY --from=builder \
|
|
|
|
|
/workspace/group-buying-sys-app/target/group-buying-sys-app-*.jar \
|
|
|
|
|
/app.jar
|
2025-06-19 20:34:58 +08:00
|
|
|
|
|
2025-07-08 16:27:21 +08:00
|
|
|
|
# 暴露端口,按需改
|
|
|
|
|
EXPOSE 8091
|
|
|
|
|
|
|
|
|
|
# 启动命令,可通过 -e JAVA_OPTS / -e PARAMS 传参数
|
|
|
|
|
ENV PARAMS=""
|
|
|
|
|
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar /app.jar $PARAMS"]
|