# ============================================================
# 构建阶段 - 创建包含 LibreOffice 的基础镜像
# ============================================================
FROM openjdk:8-jre-slim as base-builder

ENV LANG=zh_CN.UTF-8 \
    LANGUAGE=zh_CN:zh \
    LC_ALL=zh_CN.UTF-8 \
    DEBIAN_FRONTEND=noninteractive

# 用 echo 逐行写入清华源（兼容旧版 Docker Builder，不支持 heredoc）
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" > /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free" >> /etc/apt/sources.list && \
    cat /etc/apt/sources.list

# 关键：加 -o Acquire::Check-Valid-Until=false 绕过 Release 过期检查
RUN apt-get update -o Acquire::Check-Valid-Until=false && \
    apt-get install -y --no-install-recommends \
        fonts-liberation \
        fonts-dejavu-core \
        fonts-wqy-microhei \
        fonts-noto-cjk \
        fontconfig \
        locales \
        libreoffice-core \
        libreoffice-writer \
        libreoffice-l10n-zh-cn && \
    echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen && \
    locale-gen zh_CN.UTF-8 && \
    fc-cache -f -v && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir -p /home/app
WORKDIR /home/app

# ============================================================
# 最终阶段
# ============================================================
FROM base-builder

# 拷贝 Spring Boot 可执行 JAR
COPY target/yd-oss-api-1.0-SNAPSHOT-exec.jar /home/app/yd-oss-api.jar

# 启动命令，设置 JVM 内存参数
ENTRYPOINT ["java", "-Xmx1024m", "-Xms512m", "-jar", "/home/app/yd-oss-api.jar"]

EXPOSE 9106