48 lines
1.4 KiB
Docker
48 lines
1.4 KiB
Docker
# syntax=docker/dockerfile:1
|
||
|
||
# ==================== 第一阶段:编译 ====================
|
||
FROM maven:3.8-openjdk-17 AS builder
|
||
WORKDIR /build
|
||
|
||
# 阿里云 Maven 镜像加速
|
||
COPY settings.xml /root/.m2/settings.xml
|
||
|
||
# 先拷贝 pom 利用 Docker 缓存层(依赖不变时跳过下载)
|
||
COPY pom.xml .
|
||
COPY common/pom.xml common/pom.xml
|
||
COPY manager/pom.xml manager/pom.xml
|
||
COPY client-api/pom.xml client-api/pom.xml
|
||
|
||
# 拷贝源码
|
||
COPY . .
|
||
|
||
# 构建(从父 pom 编译,client-api 依赖 common 和 manager)
|
||
RUN --mount=type=cache,target=/root/.m2/repository \
|
||
mvn clean package -pl client-api -am -DskipTests
|
||
|
||
# ==================== 第二阶段:运行 ====================
|
||
FROM alibabadragonwell/dragonwell:17-anolis
|
||
|
||
ENV TZ=Asia/Shanghai
|
||
ENV PROFILES_ACTIVE=prod
|
||
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 \
|
||
-XX:+UseG1GC \
|
||
-XX:+HeapDumpOnOutOfMemoryError \
|
||
-XX:HeapDumpPath=/app/logs/heapdump.hprof \
|
||
-Dfile.encoding=UTF-8 \
|
||
-Duser.timezone=Asia/Shanghai"
|
||
|
||
# 时区 + curl(健康检查用)
|
||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
|
||
&& yum install -y curl && yum clean all
|
||
|
||
RUN mkdir -p /app/logs
|
||
|
||
WORKDIR /app
|
||
|
||
EXPOSE 8080
|
||
|
||
COPY --from=builder /build/client-api/target/client-api.jar ./client-api.jar
|
||
|
||
CMD java $JAVA_OPTS -jar client-api.jar
|