xjf666 commited on
Commit
7f0588c
·
verified ·
1 Parent(s): 8cabcf9

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +79 -0
Dockerfile ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用 OpenJDK 17 作为基础镜像
2
+ FROM openjdk:17-jdk-slim AS builder
3
+
4
+ # 设置工作目录
5
+ WORKDIR /app
6
+
7
+ # 安装必要的构建工具
8
+ RUN apt-get update && apt-get install -y \
9
+ git \
10
+ curl \
11
+ gradle \
12
+ maven
13
+
14
+ # 克隆项目代码
15
+ RUN git clone https://github.com/Stirling-Tools/Stirling-PDF.git .
16
+
17
+ # 构建项目
18
+ RUN ./gradlew build
19
+
20
+ # 运行阶段
21
+ FROM openjdk:17-jdk-slim
22
+
23
+ # 创建应用用户和必要目录
24
+ RUN useradd -m -d /home/appuser appuser && \
25
+ mkdir -p /home/appuser/.cache/dconf && \
26
+ chown -R appuser:appuser /home/appuser && \
27
+ mkdir -p /app/logs /app/configs /app/customFiles /usr/share/tessdata && \
28
+ chmod -R 777 /app/logs /app/configs /app/customFiles /usr/share/tessdata
29
+
30
+ # 设置工作目录
31
+ WORKDIR /app
32
+
33
+ # 复制构建的 JAR 文件到运行镜像
34
+ COPY --from=builder /app/build/libs/*.jar /app/stirling-pdf.jar
35
+
36
+ # 安装运行时依赖
37
+ RUN apt-get update && apt-get install -y \
38
+ libreoffice \
39
+ poppler-utils \
40
+ tesseract-ocr \
41
+ tesseract-ocr-eng \
42
+ wget \
43
+ python3 \
44
+ python3-pip && \
45
+ pip3 install --no-cache-dir unoconv WeasyPrint pdf2image pillow && \
46
+ cd /usr/share/tessdata && \
47
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_sim.traineddata && \
48
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_tra.traineddata && \
49
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata && \
50
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/jpn.traineddata && \
51
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/kor.traineddata && \
52
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/rus.traineddata && \
53
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/fra.traineddata && \
54
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/deu.traineddata && \
55
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/spa.traineddata && \
56
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/ita.traineddata && \
57
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/por.traineddata && \
58
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/vie.traineddata && \
59
+ wget https://github.com/tesseract-ocr/tessdata/raw/main/tha.traineddata && \
60
+ rm -rf /var/lib/apt/lists/*
61
+
62
+ # 设置环境变量
63
+ ENV HOME=/home/appuser \
64
+ XDG_RUNTIME_DIR=/tmp/runtime-appuser \
65
+ LIBREOFFICE_CONFIG_DIR=/tmp/libreoffice
66
+
67
+ # 设置目录权限
68
+ RUN mkdir -p ${XDG_RUNTIME_DIR} ${LIBREOFFICE_CONFIG_DIR} && \
69
+ chown -R appuser:appuser ${XDG_RUNTIME_DIR} ${LIBREOFFICE_CONFIG_DIR} && \
70
+ chmod 777 ${XDG_RUNTIME_DIR} ${LIBREOFFICE_CONFIG_DIR}
71
+
72
+ # 切换用户
73
+ USER appuser
74
+
75
+ # 暴露端口 7860
76
+ EXPOSE 7860
77
+
78
+ # 启动应用程序
79
+ CMD ["java", "-Dserver.port=7860", "-Dserver.address=0.0.0.0", "-Dfile.encoding=UTF-8", "-jar", "/app/stirling-pdf.jar"]