dragg2 commited on
Commit
04e49a6
·
verified ·
1 Parent(s): e085d41

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +99 -32
Dockerfile CHANGED
@@ -20,46 +20,113 @@ ENV KKFILEVIEW_SECURITY_TRUST_HOST=default
20
  ENV AUTH_USERNAME=admin
21
  ENV AUTH_PASSWORD=yourpassword
22
 
23
- # 3. JVM 配置
24
- ENV JAVA_OPTS="-Dsun.java2d.fontpath=/usr/share/fonts -Djava.awt.headless=true"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  # 4. Nginx 配置
27
- RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
28
- printf 'server {\n\
29
- listen 7860 default_server;\n\
30
- server_name _;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  \n\
32
- # Basic Auth\n\
33
- auth_basic "Restricted Access";\n\
34
- auth_basic_user_file /etc/nginx/.htpasswd;\n\
 
 
 
 
35
  \n\
36
- # 文件上传限制\n\
37
  client_max_body_size 500M;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  \n\
39
- # 反向代理到 KKFileView\n\
40
- location / {\n\
41
- proxy_pass http://127.0.0.1:8012;\n\
42
- proxy_set_header Host $http_host;\n\
43
- proxy_set_header X-Real-IP $remote_addr;\n\
44
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
45
- proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
46
- proxy_buffering off;\n\
47
- proxy_read_timeout 300s;\n\
48
  }\n\
49
  \n\
50
- # 健康检查端点)\n\
51
- location /health {\n\
52
- auth_basic off;\n\
53
- return 200 "OK";\n\
54
- add_header Content-Type text/plain;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }\n\
56
- }\n' > /etc/nginx/conf.d/kkfileview.conf
57
 
58
  # 5. 启动脚本
59
  RUN printf '#!/bin/bash\n\
60
  set -e\n\
61
  \n\
62
- echo "=== Starting KKFileView for HuggingFace Spaces ==="\n\
63
  \n\
64
  # 查找 KKFileView 启动脚本\n\
65
  STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
@@ -68,7 +135,7 @@ KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\
68
  # 生成 htpasswd 文件\n\
69
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
70
  \n\
71
- # 启动 Xvfb(虚拟显示)\n\
72
  echo "Starting Xvfb..."\n\
73
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
74
  export DISPLAY=:99\n\
@@ -96,18 +163,18 @@ for i in {1..30}; do\n\
96
  sleep 1\n\
97
  done\n\
98
  \n\
99
- # 等待 KKFileView 启动(使用 curl 替代 netstat)\n\
100
  echo "Waiting for KKFileView to start..."\n\
101
- for i in {1..60}; do\n\
102
  if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
103
  echo "✓ KKFileView is ready on port 8012!"\n\
104
  break\n\
105
  fi\n\
106
- if [ $i -eq 60 ]; then\n\
107
- echo "ERROR: KKFileView failed to start within 120 seconds"\n\
108
  exit 1\n\
109
  fi\n\
110
- echo "Waiting... ($i/60)"\n\
111
  sleep 2\n\
112
  done\n\
113
  \n\
 
20
  ENV AUTH_USERNAME=admin
21
  ENV AUTH_PASSWORD=yourpassword
22
 
23
+ # 3. JVM配置
24
+ # - 堆内存: 4GB
25
+ # - G1GC: 低延迟垃圾回收
26
+ # - 元空间: 256MB
27
+ ENV JAVA_OPTS="-server \
28
+ -Xms4g \
29
+ -Xmx4g \
30
+ -XX:+UseG1GC \
31
+ -XX:MaxGCPauseMillis=200 \
32
+ -XX:MetaspaceSize=256m \
33
+ -XX:MaxMetaspaceSize=512m \
34
+ -Djava.awt.headless=true \
35
+ -Dsun.java2d.fontpath=/usr/share/fonts \
36
+ -Dfile.encoding=UTF-8 \
37
+ -Dserver.tomcat.threads.max=16 \
38
+ -Dserver.tomcat.threads.min-spare=4 \
39
+ -Dserver.tomcat.accept-count=50 \
40
+ -Dserver.tomcat.max-connections=200"
41
 
42
  # 4. Nginx 配置
43
+ RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* /etc/nginx/nginx.conf && \
44
+ printf 'worker_processes 2;\n\
45
+ worker_rlimit_nofile 8192;\n\
46
+ error_log /dev/stderr warn;\n\
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
+ access_log /dev/stdout main;\n\
64
+ \n\
65
+ sendfile on;\n\
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
+ gzip on;\n\
83
+ gzip_vary on;\n\
84
+ gzip_min_length 1024;\n\
85
+ gzip_comp_level 5;\n\
86
+ gzip_types text/plain text/css text/xml text/javascript application/json application/javascript;\n\
87
  \n\
88
+ upstream kkfileview {\n\
89
+ server 127.0.0.1:8012;\n\
90
+ keepalive 16;\n\
91
+ keepalive_requests 100;\n\
92
+ keepalive_timeout 60s;\n\
 
 
 
 
93
  }\n\
94
  \n\
95
+ server {\n\
96
+ listen 7860 default_server;\n\
97
+ server_name _;\n\
98
+ \n\
99
+ auth_basic "Restricted Access";\n\
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/nginx.conf
124
 
125
  # 5. 启动脚本
126
  RUN printf '#!/bin/bash\n\
127
  set -e\n\
128
  \n\
129
+ echo "=== Starting KKFileView (Tuned) for HuggingFace Spaces ==="\n\
130
  \n\
131
  # 查找 KKFileView 启动脚本\n\
132
  STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
 
135
  # 生成 htpasswd 文件\n\
136
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
137
  \n\
138
+ # 启动 Xvfb\n\
139
  echo "Starting Xvfb..."\n\
140
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
141
  export DISPLAY=:99\n\
 
163
  sleep 1\n\
164
  done\n\
165
  \n\
166
+ # 等待 KKFileView 启动\n\
167
  echo "Waiting for KKFileView to start..."\n\
168
+ for i in {1..40}; do\n\
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 40 ]; then\n\
174
+ echo "ERROR: KKFileView failed to start within 80 seconds"\n\
175
  exit 1\n\
176
  fi\n\
177
+ echo "Waiting... ($i/40)"\n\
178
  sleep 2\n\
179
  done\n\
180
  \n\