# 使用官方 Playwright Java 镜像，内置 Chromium 与运行依赖
FROM mcr.microsoft.com/playwright/java:v1.58.0-noble

# 设置工作目录
WORKDIR /app
ENV TZ=Asia/Shanghai
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 安装报告 PDF 使用的固定字体，避免 Playwright 每次通过 @font-face 加载随包字体
RUN mkdir -p /usr/local/share/fonts/misans
COPY fonts/MiSans-VF.ttf /usr/local/share/fonts/misans/MiSans-VF.ttf
RUN fc-cache -fv \
    && fc-match "MiSans VF" \
    && fc-match "MiSans VF" | grep -q "MiSans-VF.ttf"

# 暴露端口
EXPOSE 8500

# 启动前检查挂载文件，缺失时快速失败
CMD ["sh", "-c", "PROFILE=${SPRING_PROFILES_ACTIVE:-test}; case \"$PROFILE\" in *,*) echo \"Unsupported comma-separated SPRING_PROFILES_ACTIVE: $PROFILE\"; exit 1 ;; esac; test -f /app/dcjxb-ability-center.jar || { echo 'Missing /app/dcjxb-ability-center.jar'; exit 1; }; test -f /app/application.yml || { echo 'Missing /app/application.yml'; exit 1; }; test -f \"/app/application-${PROFILE}.yml\" || { echo \"Missing /app/application-${PROFILE}.yml\"; exit 1; }; exec java -Xms256m -Xmx512m -Djava.net.preferIPv4Stack=true -Dspring.profiles.active=$PROFILE -jar /app/dcjxb-ability-center.jar --spring.config.location=/app/application.yml,/app/application-${PROFILE}.yml"]
