test-backend/Dockerfile

53 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================
# 后端 Docker 镜像 — 多阶段构建
# Stage 1: Maven 编译(不污染宿主)
# Stage 2: JRE 运行(精简镜像)
# ============================================
# ---- Stage 1: 编译 ----
FROM maven:3.9-eclipse-temurin-17 AS builder
WORKDIR /build
# 先复制 pom.xml利用 Docker 缓存加速依赖下载
COPY pom.xml ./
COPY test-base-core/pom.xml test-base-core/
COPY test-module-system/pom.xml test-module-system/
COPY test-module-system/test-system-api/pom.xml test-module-system/test-system-api/
COPY test-module-system/test-system-biz/pom.xml test-module-system/test-system-biz/
COPY test-module-system/test-system-start/pom.xml test-module-system/test-system-start/
COPY test-module-business/pom.xml test-module-business/
# 下载依赖(这一层在 pom 不变时会被缓存)
RUN mvn dependency:go-offline -B || true
# 复制全部源码
COPY . .
# 编译打包(跳过测试)
RUN mvn package -Dmaven.test.skip=true -T 1C
# ---- Stage 2: 运行 ----
FROM eclipse-temurin:17-jre
LABEL maintainer="ghb-base deploy"
# 时区Debian 系)
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
WORKDIR /app
# 从编译阶段复制 fat jar
COPY --from=builder /build/test-module-system/test-system-start/target/*.jar app.jar
# 上传文件目录
RUN mkdir -p /opt/upFiles
EXPOSE 8081
# JVM 参数可通过环境变量 JAVA_OPTS 覆盖
ENV JAVA_OPTS="-Xms512m -Xmx512m"
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]