45 lines
1.4 KiB
Docker
Raw Permalink 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.

# —— 第一阶段Maven 构建 ——
FROM maven:3.8.7-eclipse-temurin-17-alpine AS builder
WORKDIR /workspace
# 把项目级 settings.xml 复制到容器里
COPY .mvn/settings.xml /root/.m2/settings.xml
# 1. 先只拷贝父 POM 及各模块的 pom.xml加速依赖下载
COPY pom.xml ./pom.xml
COPY ai-rag-knowledge-api/pom.xml ./ai-rag-knowledge-api/pom.xml
COPY ai-rag-knowledge-trigger/pom.xml ./ai-rag-knowledge-trigger/pom.xml
COPY ai-rag-knowledge-app/pom.xml ./ai-rag-knowledge-app/pom.xml
# 离线下载所有依赖
RUN mvn dependency:go-offline -B
# 2. 只拷源码模块,不拷 data/docs
COPY ai-rag-knowledge-api ai-rag-knowledge-api
COPY ai-rag-knowledge-trigger ai-rag-knowledge-trigger
COPY ai-rag-knowledge-app ai-rag-knowledge-app
# 3. 只打包 main 应用模块(连带编译它依赖的模块),跳过测试,加速构建
RUN mvn \
-f pom.xml clean package \
-pl ai-rag-knowledge-app -am \
-DskipTests -B
# —— 第二阶段:运行时镜像 ——
FROM openjdk:17-jdk-slim
LABEL maintainer="smile"
# 可选:设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 把构建产物拷过来
COPY --from=builder \
/workspace/ai-rag-knowledge-app/target/ai-rag-knowledge-app.jar \
app.jar
# 暴露端口,按需改
EXPOSE 8095
ENTRYPOINT ["java", "-jar", "app.jar"]