Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +40 -10
Dockerfile
CHANGED
|
@@ -11,6 +11,10 @@ RUN apt-get update && apt-get install -y \
|
|
| 11 |
libfreetype6 \
|
| 12 |
fontconfig \
|
| 13 |
fonts-wqy-zenhei \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
&& rm -rf /var/lib/apt/lists/* \
|
| 15 |
&& fc-cache -fv
|
| 16 |
|
|
@@ -20,7 +24,7 @@ ENV KKFILEVIEW_SECURITY_TRUST_HOST=default
|
|
| 20 |
ENV AUTH_USERNAME=admin
|
| 21 |
ENV AUTH_PASSWORD=yourpassword
|
| 22 |
|
| 23 |
-
# 3. JVM配置
|
| 24 |
# - 堆内存: 4GB
|
| 25 |
# - G1GC: 低延迟垃圾回收
|
| 26 |
# - 元空间: 256MB
|
|
@@ -39,7 +43,14 @@ ENV JAVA_OPTS="-server \
|
|
| 39 |
-Dserver.tomcat.accept-count=50 \
|
| 40 |
-Dserver.tomcat.max-connections=200"
|
| 41 |
|
| 42 |
-
# 4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
|
| 44 |
printf 'server {\n\
|
| 45 |
listen 7860 default_server;\n\
|
|
@@ -52,7 +63,7 @@ RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
|
|
| 52 |
# 文件上传限制\n\
|
| 53 |
client_max_body_size 500M;\n\
|
| 54 |
\n\
|
| 55 |
-
#
|
| 56 |
location ~ ^/(demo|file|static)/ {\n\
|
| 57 |
auth_basic off;\n\
|
| 58 |
proxy_pass http://127.0.0.1:8012;\n\
|
|
@@ -64,7 +75,7 @@ RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
|
|
| 64 |
proxy_read_timeout 300s;\n\
|
| 65 |
}\n\
|
| 66 |
\n\
|
| 67 |
-
#
|
| 68 |
location / {\n\
|
| 69 |
proxy_pass http://127.0.0.1:8012;\n\
|
| 70 |
proxy_set_header Host $http_host;\n\
|
|
@@ -83,11 +94,11 @@ RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
|
|
| 83 |
}\n\
|
| 84 |
}\n' > /etc/nginx/conf.d/kkfileview.conf
|
| 85 |
|
| 86 |
-
#
|
| 87 |
RUN printf '#!/bin/bash\n\
|
| 88 |
set -e\n\
|
| 89 |
\n\
|
| 90 |
-
echo "=== Starting KKFileView (EPS Fix) for HuggingFace Spaces ==="\n\
|
| 91 |
\n\
|
| 92 |
# 查找 KKFileView 启动脚本\n\
|
| 93 |
STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
|
|
@@ -96,11 +107,25 @@ KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\
|
|
| 96 |
# 生成 htpasswd 文件\n\
|
| 97 |
htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
|
| 98 |
\n\
|
| 99 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
echo "Starting Xvfb..."\n\
|
| 101 |
Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
|
| 102 |
export DISPLAY=:99\n\
|
| 103 |
sleep 2\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
\n\
|
| 105 |
# 启动 KKFileView\n\
|
| 106 |
echo "Starting KKFileView on port 8012..."\n\
|
|
@@ -139,18 +164,23 @@ for i in {1..60}; do\n\
|
|
| 139 |
sleep 2\n\
|
| 140 |
done\n\
|
| 141 |
\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# 启动 Nginx\n\
|
| 143 |
echo "Starting Nginx on port 7860..."\n\
|
| 144 |
nginx -g "daemon off;"\n' > /start.sh && \
|
| 145 |
chmod +x /start.sh
|
| 146 |
|
| 147 |
-
#
|
| 148 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 149 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 150 |
|
| 151 |
-
#
|
| 152 |
EXPOSE 7860
|
| 153 |
|
| 154 |
-
#
|
| 155 |
ENTRYPOINT []
|
| 156 |
CMD ["/start.sh"]
|
|
|
|
| 11 |
libfreetype6 \
|
| 12 |
fontconfig \
|
| 13 |
fonts-wqy-zenhei \
|
| 14 |
+
libreoffice \
|
| 15 |
+
libreoffice-writer \
|
| 16 |
+
libreoffice-calc \
|
| 17 |
+
libreoffice-impress \
|
| 18 |
&& rm -rf /var/lib/apt/lists/* \
|
| 19 |
&& fc-cache -fv
|
| 20 |
|
|
|
|
| 24 |
ENV AUTH_USERNAME=admin
|
| 25 |
ENV AUTH_PASSWORD=yourpassword
|
| 26 |
|
| 27 |
+
# 3. JVM 配置
|
| 28 |
# - 堆内存: 4GB
|
| 29 |
# - G1GC: 低延迟垃圾回收
|
| 30 |
# - 元空间: 256MB
|
|
|
|
| 43 |
-Dserver.tomcat.accept-count=50 \
|
| 44 |
-Dserver.tomcat.max-connections=200"
|
| 45 |
|
| 46 |
+
# 4. LibreOffice 配置
|
| 47 |
+
ENV office.plugin.server.ports=2001,2002,2003,2004,2005
|
| 48 |
+
ENV office.plugin.task.timeout=5m
|
| 49 |
+
ENV office.preview.type=pdf
|
| 50 |
+
ENV office.timeout=300000
|
| 51 |
+
ENV file.dir=/opt/kkFileView/file/
|
| 52 |
+
|
| 53 |
+
# 5. Nginx 配置
|
| 54 |
RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
|
| 55 |
printf 'server {\n\
|
| 56 |
listen 7860 default_server;\n\
|
|
|
|
| 63 |
# 文件上传限制\n\
|
| 64 |
client_max_body_size 500M;\n\
|
| 65 |
\n\
|
| 66 |
+
# 静态文件目录)\n\
|
| 67 |
location ~ ^/(demo|file|static)/ {\n\
|
| 68 |
auth_basic off;\n\
|
| 69 |
proxy_pass http://127.0.0.1:8012;\n\
|
|
|
|
| 75 |
proxy_read_timeout 300s;\n\
|
| 76 |
}\n\
|
| 77 |
\n\
|
| 78 |
+
# 反向代理到 KKFileView\n\
|
| 79 |
location / {\n\
|
| 80 |
proxy_pass http://127.0.0.1:8012;\n\
|
| 81 |
proxy_set_header Host $http_host;\n\
|
|
|
|
| 94 |
}\n\
|
| 95 |
}\n' > /etc/nginx/conf.d/kkfileview.conf
|
| 96 |
|
| 97 |
+
# 6. 启动脚本
|
| 98 |
RUN printf '#!/bin/bash\n\
|
| 99 |
set -e\n\
|
| 100 |
\n\
|
| 101 |
+
echo "=== Starting KKFileView (EPS + CAD Fix) for HuggingFace Spaces ==="\n\
|
| 102 |
\n\
|
| 103 |
# 查找 KKFileView 启动脚本\n\
|
| 104 |
STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
|
|
|
|
| 107 |
# 生成 htpasswd 文件\n\
|
| 108 |
htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
|
| 109 |
\n\
|
| 110 |
+
# 创建文件存储目录\n\
|
| 111 |
+
mkdir -p /opt/kkFileView/file\n\
|
| 112 |
+
chmod 755 /opt/kkFileView/file\n\
|
| 113 |
+
\n\
|
| 114 |
+
# 启动 Xvfb\n\
|
| 115 |
echo "Starting Xvfb..."\n\
|
| 116 |
Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
|
| 117 |
export DISPLAY=:99\n\
|
| 118 |
sleep 2\n\
|
| 119 |
+
echo "✓ Xvfb started on DISPLAY=:99"\n\
|
| 120 |
+
\n\
|
| 121 |
+
# 启动 LibreOffice 进程池\n\
|
| 122 |
+
echo "Starting LibreOffice process pool..."\n\
|
| 123 |
+
for port in 2001 2002 2003 2004 2005; do\n\
|
| 124 |
+
soffice --headless --accept="socket,host=127.0.0.1,port=$port;urp;" --nofirststartwizard >/dev/null 2>&1 &\n\
|
| 125 |
+
echo " - LibreOffice process started on port $port"\n\
|
| 126 |
+
done\n\
|
| 127 |
+
sleep 3\n\
|
| 128 |
+
echo "✓ LibreOffice process pool ready"\n\
|
| 129 |
\n\
|
| 130 |
# 启动 KKFileView\n\
|
| 131 |
echo "Starting KKFileView on port 8012..."\n\
|
|
|
|
| 164 |
sleep 2\n\
|
| 165 |
done\n\
|
| 166 |
\n\
|
| 167 |
+
# 验证 LibreOffice 进程池\n\
|
| 168 |
+
echo "Verifying LibreOffice process pool..."\n\
|
| 169 |
+
LIBREOFFICE_COUNT=$(ps aux | grep soffice | grep -v grep | wc -l)\n\
|
| 170 |
+
echo " - LibreOffice processes running: $LIBREOFFICE_COUNT"\n\
|
| 171 |
+
\n\
|
| 172 |
# 启动 Nginx\n\
|
| 173 |
echo "Starting Nginx on port 7860..."\n\
|
| 174 |
nginx -g "daemon off;"\n' > /start.sh && \
|
| 175 |
chmod +x /start.sh
|
| 176 |
|
| 177 |
+
# 7. 健康检查
|
| 178 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 179 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 180 |
|
| 181 |
+
# 8. 暴露端口
|
| 182 |
EXPOSE 7860
|
| 183 |
|
| 184 |
+
# 9. 启动命令
|
| 185 |
ENTRYPOINT []
|
| 186 |
CMD ["/start.sh"]
|