diff --git a/docs/dev-ops/docker-compose-app.yml b/docs/dev-ops/docker-compose-app.yml index 3cb9cf7..b9f0c12 100644 --- a/docs/dev-ops/docker-compose-app.yml +++ b/docs/dev-ops/docker-compose-app.yml @@ -63,7 +63,10 @@ services: # 4. Java 后端 group-buying-sys: - image: smile/group-buying-sys + build: + context: .. # 从 docs/ 回到项目根 + dockerfile: group-buying-sys-app/Dockerfile + image: smile/group-buying-sys:latest container_name: group-buying-sys restart: on-failure depends_on: diff --git a/group-buying-sys-app/Dockerfile b/group-buying-sys-app/Dockerfile index 4b19354..66705c3 100644 --- a/group-buying-sys-app/Dockerfile +++ b/group-buying-sys-app/Dockerfile @@ -1,17 +1,45 @@ -# 基础镜像 +# —— 第一阶段:Maven 构建 —— +FROM maven:3.8.7-openjdk-8-slim AS builder +WORKDIR /workspace + +# 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 + +# 离线下载所有依赖 +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 + +# —— 第二阶段:运行时镜像 —— FROM openjdk:8-jre-slim +LABEL maintainer="smile" -# 作者 -MAINTAINER zy - -# 配置 -ENV PARAMS="" - -# 时区 +# 可选:设置时区 ENV TZ=PRC -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ + && echo $TZ > /etc/timezone -# 添加应用 -ADD target/group-buying-sys-app.jar /group-buying-sys-app.jar +# 把构建产物拷过来 +COPY --from=builder \ + /workspace/group-buying-sys-app/target/group-buying-sys-app-*.jar \ + /app.jar -ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /group-buying-sys-app.jar $PARAMS"] \ No newline at end of file +# 暴露端口,按需改 +EXPOSE 8091 + +# 启动命令,可通过 -e JAVA_OPTS / -e PARAMS 传参数 +ENV PARAMS="" +ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar /app.jar $PARAMS"] diff --git a/group-buying-sys-app/build.sh b/group-buying-sys-app/build.sh deleted file mode 100644 index cabd846..0000000 --- a/group-buying-sys-app/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -# 普通镜像构建,随系统版本构建 amd/arm -docker build -t smile/group-buying-sys-app -f ./Dockerfile . - -# 兼容 amd、arm 构建镜像 -# docker buildx build --load --platform liunx/amd64,linux/arm64 -t xiaofuge/xfg-frame-archetype-app:1.0 -f ./Dockerfile . --push \ No newline at end of file