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

# 如没有私服，可删掉
COPY .mvn/settings.xml /root/.m2/settings.xml

# 先拉依赖
COPY pom.xml .
RUN mvn -B dependency:go-offline

# 打包
COPY src src
RUN mvn -B clean package spring-boot:repackage -DskipTests


# ---------- runtime ----------
# 继续用 slim，体积小；手动装字体
FROM openjdk:17-jdk-slim AS runtime
ENV TZ=Asia/Shanghai \
    LANG=C.UTF-8 \
    LANGUAGE=C.UTF-8

# 换国内源，解决 timeout
RUN sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list

# 安装 fontconfig + 基础西文 + CJK 字体
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        fontconfig fonts-dejavu-core fonts-noto-cjk; \
    rm -rf /var/lib/apt/lists/*

# 设置时区
RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone

ARG JAR_FILE=smile-picture-backend.jar
COPY --from=builder /workspace/target/${JAR_FILE} /app.jar

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