# 使用 OpenJDK 17 作为基础镜像 FROM openjdk:17-jdk-slim AS builder # 设置工作目录 WORKDIR /app # 安装必要的构建工具 RUN apt-get update && apt-get install -y \ git \ curl \ gradle \ maven # 克隆项目代码 RUN git clone https://github.com/Stirling-Tools/Stirling-PDF.git . # 构建项目 RUN ./gradlew build # 运行阶段 FROM openjdk:17-jdk-slim # 创建应用用户和必要目录 RUN useradd -m -d /home/appuser appuser && \ mkdir -p /home/appuser/.cache/dconf && \ chown -R appuser:appuser /home/appuser && \ mkdir -p /app/logs /app/configs /app/customFiles /usr/share/tessdata && \ chmod -R 777 /app/logs /app/configs /app/customFiles /usr/share/tessdata # 设置工作目录 WORKDIR /app # 复制构建的 JAR 文件到运行镜像 COPY --from=builder /app/build/libs/*.jar /app/stirling-pdf.jar # 安装运行时依赖 RUN apt-get update && apt-get install -y \ libreoffice \ poppler-utils \ tesseract-ocr \ tesseract-ocr-eng \ wget \ python3 \ python3-pip && \ pip3 install --no-cache-dir unoconv WeasyPrint pdf2image pillow && \ cd /usr/share/tessdata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_sim.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_tra.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/jpn.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/kor.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/rus.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/fra.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/deu.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/spa.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/ita.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/por.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/vie.traineddata && \ wget https://github.com/tesseract-ocr/tessdata/raw/main/tha.traineddata && \ rm -rf /var/lib/apt/lists/* # 设置环境变量 ENV HOME=/home/appuser \ XDG_RUNTIME_DIR=/tmp/runtime-appuser \ LIBREOFFICE_CONFIG_DIR=/tmp/libreoffice # 设置目录权限 RUN mkdir -p ${XDG_RUNTIME_DIR} ${LIBREOFFICE_CONFIG_DIR} && \ chown -R appuser:appuser ${XDG_RUNTIME_DIR} ${LIBREOFFICE_CONFIG_DIR} && \ chmod 777 ${XDG_RUNTIME_DIR} ${LIBREOFFICE_CONFIG_DIR} # 切换用户 USER appuser # 暴露端口 7860 EXPOSE 7860 # 启动应用程序 CMD ["java", "-Dserver.port=7860", "-Dserver.address=0.0.0.0", "-Dfile.encoding=UTF-8", "-jar", "/app/stirling-pdf.jar"]