# —— builder 阶段 ——
FROM maven:3.8.7-eclipse-temurin-17-alpine AS builder
WORKDIR /workspace

# ① 如没有私服，可删掉这行；否则保留
COPY .mvn/settings.xml /root/.m2/settings.xml

# ② 先拷 POM 并预拉依赖，提升缓存命中率
COPY pom.xml .
RUN mvn -B dependency:go-offline

# ③ 再拷源码并真正打包，显式执行 spring-boot:repackage
COPY src src
RUN mvn -B clean package spring-boot:repackage -DskipTests

# —— runtime 阶段 ——
FROM openjdk:17-jdk-slim
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 指向你在 pom.xml 里定义的 finalName
ARG JAR_FILE=smile-picture-backend.jar
COPY --from=builder /workspace/target/${JAR_FILE} /app.jar

EXPOSE 8096
ENTRYPOINT ["java", "-jar", "/app.jar"]
