Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +41 -80
Dockerfile
CHANGED
|
@@ -40,93 +40,54 @@ ENV JAVA_OPTS="-server \
|
|
| 40 |
-Dserver.tomcat.max-connections=200"
|
| 41 |
|
| 42 |
# 4. Nginx 配置
|
| 43 |
-
RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/*
|
| 44 |
-
printf '
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
pid /var/run/nginx.pid;\n\
|
| 48 |
-
\n\
|
| 49 |
-
events {\n\
|
| 50 |
-
worker_connections 2048;\n\
|
| 51 |
-
multi_accept on;\n\
|
| 52 |
-
use epoll;\n\
|
| 53 |
-
}\n\
|
| 54 |
-
\n\
|
| 55 |
-
http {\n\
|
| 56 |
-
include /etc/nginx/mime.types;\n\
|
| 57 |
-
default_type application/octet-stream;\n\
|
| 58 |
-
\n\
|
| 59 |
-
log_format main '"'"'$remote_addr - $remote_user [$time_local] "$request" '"'"'\n\
|
| 60 |
-
'"'"'$status $body_bytes_sent "$http_referer" '"'"'\n\
|
| 61 |
-
'"'"'"$http_user_agent" rt=$request_time'"'"';\n\
|
| 62 |
\n\
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
tcp_nopush on;\n\
|
| 67 |
-
tcp_nodelay on;\n\
|
| 68 |
-
keepalive_timeout 65;\n\
|
| 69 |
-
keepalive_requests 100;\n\
|
| 70 |
\n\
|
|
|
|
| 71 |
client_max_body_size 500M;\n\
|
| 72 |
-
client_body_buffer_size 1M;\n\
|
| 73 |
-
client_body_timeout 300s;\n\
|
| 74 |
-
\n\
|
| 75 |
-
proxy_buffering on;\n\
|
| 76 |
-
proxy_buffer_size 8k;\n\
|
| 77 |
-
proxy_buffers 4 16k;\n\
|
| 78 |
-
proxy_connect_timeout 60s;\n\
|
| 79 |
-
proxy_send_timeout 300s;\n\
|
| 80 |
-
proxy_read_timeout 300s;\n\
|
| 81 |
\n\
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
\n\
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}\n\
|
| 94 |
\n\
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
auth_basic_user_file /etc/nginx/.htpasswd;\n\
|
| 101 |
-
\n\
|
| 102 |
-
location / {\n\
|
| 103 |
-
proxy_pass http://kkfileview;\n\
|
| 104 |
-
proxy_http_version 1.1;\n\
|
| 105 |
-
proxy_set_header Connection "";\n\
|
| 106 |
-
proxy_set_header Host $http_host;\n\
|
| 107 |
-
proxy_set_header X-Real-IP $remote_addr;\n\
|
| 108 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
| 109 |
-
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
|
| 110 |
-
\n\
|
| 111 |
-
proxy_buffering on;\n\
|
| 112 |
-
proxy_buffer_size 8k;\n\
|
| 113 |
-
proxy_buffers 4 16k;\n\
|
| 114 |
-
proxy_read_timeout 300s;\n\
|
| 115 |
-
}\n\
|
| 116 |
-
\n\
|
| 117 |
-
location /health {\n\
|
| 118 |
-
auth_basic off;\n\
|
| 119 |
-
return 200 "OK";\n\
|
| 120 |
-
add_header Content-Type text/plain;\n\
|
| 121 |
-
}\n\
|
| 122 |
}\n\
|
| 123 |
-
}\n' > /etc/nginx/
|
| 124 |
|
| 125 |
# 5. 启动脚本
|
| 126 |
RUN printf '#!/bin/bash\n\
|
| 127 |
set -e\n\
|
| 128 |
\n\
|
| 129 |
-
echo "=== Starting KKFileView (
|
| 130 |
\n\
|
| 131 |
# 查找 KKFileView 启动脚本\n\
|
| 132 |
STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
|
|
@@ -135,7 +96,7 @@ KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\
|
|
| 135 |
# 生成 htpasswd 文件\n\
|
| 136 |
htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
|
| 137 |
\n\
|
| 138 |
-
# 启动 Xvfb
|
| 139 |
echo "Starting Xvfb..."\n\
|
| 140 |
Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
|
| 141 |
export DISPLAY=:99\n\
|
|
@@ -165,16 +126,16 @@ done\n\
|
|
| 165 |
\n\
|
| 166 |
# 等待 KKFileView 启动\n\
|
| 167 |
echo "Waiting for KKFileView to start..."\n\
|
| 168 |
-
for i in {1..
|
| 169 |
if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
|
| 170 |
echo "✓ KKFileView is ready on port 8012!"\n\
|
| 171 |
break\n\
|
| 172 |
fi\n\
|
| 173 |
-
if [ $i -eq
|
| 174 |
-
echo "ERROR: KKFileView failed to start within
|
| 175 |
exit 1\n\
|
| 176 |
fi\n\
|
| 177 |
-
echo "Waiting... ($i/
|
| 178 |
sleep 2\n\
|
| 179 |
done\n\
|
| 180 |
\n\
|
|
@@ -192,4 +153,4 @@ EXPOSE 7860
|
|
| 192 |
|
| 193 |
# 8. 启动命令
|
| 194 |
ENTRYPOINT []
|
| 195 |
-
CMD ["/start.sh"]
|
|
|
|
| 40 |
-Dserver.tomcat.max-connections=200"
|
| 41 |
|
| 42 |
# 4. Nginx 配置
|
| 43 |
+
RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
|
| 44 |
+
printf 'server {\n\
|
| 45 |
+
listen 7860 default_server;\n\
|
| 46 |
+
server_name _;\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
\n\
|
| 48 |
+
# 默认需要认证\n\
|
| 49 |
+
auth_basic "Restricted Access";\n\
|
| 50 |
+
auth_basic_user_file /etc/nginx/.htpasswd;\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
\n\
|
| 52 |
+
# 文件上传限制\n\
|
| 53 |
client_max_body_size 500M;\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
\n\
|
| 55 |
+
# 静态文件目录\n\
|
| 56 |
+
location ~ ^/(demo|file|static)/ {\n\
|
| 57 |
+
auth_basic off;\n\
|
| 58 |
+
proxy_pass http://127.0.0.1:8012;\n\
|
| 59 |
+
proxy_set_header Host $http_host;\n\
|
| 60 |
+
proxy_set_header X-Real-IP $remote_addr;\n\
|
| 61 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
| 62 |
+
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
|
| 63 |
+
proxy_buffering off;\n\
|
| 64 |
+
proxy_read_timeout 300s;\n\
|
| 65 |
+
}\n\
|
| 66 |
\n\
|
| 67 |
+
# 反向代理到\n\
|
| 68 |
+
location / {\n\
|
| 69 |
+
proxy_pass http://127.0.0.1:8012;\n\
|
| 70 |
+
proxy_set_header Host $http_host;\n\
|
| 71 |
+
proxy_set_header X-Real-IP $remote_addr;\n\
|
| 72 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
| 73 |
+
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
|
| 74 |
+
proxy_buffering off;\n\
|
| 75 |
+
proxy_read_timeout 300s;\n\
|
| 76 |
}\n\
|
| 77 |
\n\
|
| 78 |
+
# 健康检查端点\n\
|
| 79 |
+
location /health {\n\
|
| 80 |
+
auth_basic off;\n\
|
| 81 |
+
return 200 "OK";\n\
|
| 82 |
+
add_header Content-Type text/plain;\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}\n\
|
| 84 |
+
}\n' > /etc/nginx/conf.d/kkfileview.conf
|
| 85 |
|
| 86 |
# 5. 启动脚本
|
| 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 |
# 生成 htpasswd 文件\n\
|
| 97 |
htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
|
| 98 |
\n\
|
| 99 |
+
# 启动 Xvfb(虚拟显示)\n\
|
| 100 |
echo "Starting Xvfb..."\n\
|
| 101 |
Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
|
| 102 |
export DISPLAY=:99\n\
|
|
|
|
| 126 |
\n\
|
| 127 |
# 等待 KKFileView 启动\n\
|
| 128 |
echo "Waiting for KKFileView to start..."\n\
|
| 129 |
+
for i in {1..60}; do\n\
|
| 130 |
if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
|
| 131 |
echo "✓ KKFileView is ready on port 8012!"\n\
|
| 132 |
break\n\
|
| 133 |
fi\n\
|
| 134 |
+
if [ $i -eq 60 ]; then\n\
|
| 135 |
+
echo "ERROR: KKFileView failed to start within 120 seconds"\n\
|
| 136 |
exit 1\n\
|
| 137 |
fi\n\
|
| 138 |
+
echo "Waiting... ($i/60)"\n\
|
| 139 |
sleep 2\n\
|
| 140 |
done\n\
|
| 141 |
\n\
|
|
|
|
| 153 |
|
| 154 |
# 8. 启动命令
|
| 155 |
ENTRYPOINT []
|
| 156 |
+
CMD ["/start.sh"]
|