53 lines
1.8 KiB
Docker
53 lines
1.8 KiB
Docker
# ============================================
|
||
# Demo Cloud 微服务 — 多阶段构建
|
||
# Stage 1: Maven 编译全项目(SpringCloud profile)
|
||
# Stage 2: JRE 运行
|
||
# ============================================
|
||
|
||
# ---- Stage 1: 编译 ----
|
||
FROM maven:3.9-eclipse-temurin-17 AS builder
|
||
|
||
WORKDIR /build
|
||
|
||
# 先复制 pom.xml,利用 Docker 缓存加速依赖下载
|
||
COPY pom.xml ./
|
||
COPY ghb-base-core/pom.xml ghb-base-core/
|
||
COPY ghb-module-system/pom.xml ghb-module-system/
|
||
COPY ghb-module-system/ghb-system-api/pom.xml ghb-module-system/ghb-system-api/
|
||
COPY ghb-module-system/ghb-system-biz/pom.xml ghb-module-system/ghb-system-biz/
|
||
COPY ghb-module-system/ghb-system-start/pom.xml ghb-module-system/ghb-system-start/
|
||
COPY ghb-module-business/pom.xml ghb-module-business/
|
||
COPY ghb-server-cloud/pom.xml ghb-server-cloud/
|
||
COPY test-server-cloud/test-cloud-gateway/pom.xml test-server-cloud/test-cloud-gateway/
|
||
COPY test-server-cloud/test-system-cloud-start/pom.xml test-server-cloud/test-system-cloud-start/
|
||
COPY ghb-server-cloud/ghb-demo-cloud-start/pom.xml ghb-server-cloud/ghb-demo-cloud-start/
|
||
COPY test-server-cloud/test-cloud-nacos/pom.xml test-server-cloud/test-cloud-nacos/
|
||
|
||
# 下载依赖(pom 不变时缓存)
|
||
RUN mvn dependency:go-offline -B -P SpringCloud,dev || true
|
||
|
||
# 复制全部源码
|
||
COPY . .
|
||
|
||
# 编译全项目(SpringCloud profile,跳过测试)
|
||
RUN mvn package -P SpringCloud,dev -Dmaven.test.skip=true -T 1C
|
||
|
||
# ---- Stage 2: 运行 ----
|
||
FROM eclipse-temurin:17-jre
|
||
|
||
LABEL maintainer="ghb-base deploy"
|
||
|
||
ENV TZ=Asia/Shanghai
|
||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
|
||
|
||
WORKDIR /app
|
||
|
||
# 从编译阶段复制 demo-cloud jar
|
||
COPY --from=builder /build/ghb-server-cloud/ghb-demo-cloud-start/target/*.jar app.jar
|
||
|
||
EXPOSE 7002
|
||
|
||
ENV JAVA_OPTS="-Xms256m -Xmx512m"
|
||
|
||
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
|