dragg2 commited on
Commit
fe41ce4
·
verified ·
1 Parent(s): 9d40f5b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -133
Dockerfile CHANGED
@@ -12,151 +12,57 @@ RUN apt-get update && apt-get install -y \
12
  && rm -rf /var/lib/apt/lists/* \
13
  && fc-cache -fv
14
 
15
- # 2. JVM 优化配置(针对 16GB RAM 环境)
16
  ENV SERVER_PORT=8012 \
17
- KKFILEVIEW_SECURITY_TRUST_HOST=default \
18
- JAVA_OPTS="-server \
19
- -Xms8g \
20
- -Xmx8g \
21
- -XX:+UseG1GC \
22
- -XX:MaxGCPauseMillis=200 \
23
- -XX:G1HeapRegionSize=16m \
24
- -XX:G1NewSizePercent=30 \
25
- -XX:G1MaxNewSizePercent=40 \
26
- -XX:InitiatingHeapOccupancyPercent=45 \
27
- -XX:MetaspaceSize=256m \
28
- -XX:MaxMetaspaceSize=512m \
29
- -Xss1m \
30
- -XX:+UseCompressedOops \
31
- -XX:+UseStringDeduplication \
32
- -XX:+OptimizeStringConcat \
33
- -Djava.awt.headless=true \
34
- -Dsun.java2d.fontpath=/usr/share/fonts \
35
- -Dfile.encoding=UTF-8 \
36
- -Djava.security.egd=file:/dev/./urandom \
37
- -XX:+HeapDumpOnOutOfMemoryError \
38
- -XX:HeapDumpPath=/var/log/kkfileview/ \
39
- -XX:+PrintGCDetails \
40
- -XX:+PrintGCTimeStamps \
41
- -Xloggc:/var/log/kkfileview/gc.log \
42
- -XX:+UseGCLogFileRotation \
43
- -XX:NumberOfGCLogFiles=5 \
44
- -XX:GCLogFileSize=100M \
45
- -Dserver.tomcat.threads.max=16 \
46
- -Dserver.tomcat.threads.min-spare=4 \
47
- -Dserver.tomcat.accept-count=50 \
48
- -Dserver.tomcat.max-connections=200"
49
 
50
- # 3. 创建目录并设置权限
51
- RUN mkdir -p /var/log/kkfileview /opt/kkFileView/file && \
52
- chmod -R 755 /var/log/kkfileview /opt/kkFileView
53
 
54
  # 4. Nginx 配置
55
  RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* /etc/nginx/nginx.conf && \
56
- printf 'worker_processes 2;\n\
57
- worker_cpu_affinity 01 10;\n\
58
- worker_priority -5;\n\
59
- worker_rlimit_nofile 65535;\n\
60
- \n\
61
  error_log /dev/stderr warn;\n\
62
  pid /var/run/nginx.pid;\n\
63
  \n\
64
  events {\n\
65
- worker_connections 4096;\n\
66
- multi_accept on;\n\
67
- use epoll;\n\
68
- accept_mutex off;\n\
69
  }\n\
70
  \n\
71
  http {\n\
72
  include /etc/nginx/mime.types;\n\
73
  default_type application/octet-stream;\n\
74
  \n\
75
- log_format main '"'"'$remote_addr - $remote_user [$time_local] "$request" '"'"'\n\
76
- '"'"'$status $body_bytes_sent "$http_referer" '"'"'\n\
77
- '"'"'"$http_user_agent" rt=$request_time uct="$upstream_connect_time"'"'"';\n\
78
- \n\
79
- access_log /dev/stdout main;\n\
80
  \n\
81
  sendfile on;\n\
82
- tcp_nopush on;\n\
83
- tcp_nodelay on;\n\
84
  keepalive_timeout 65;\n\
85
- keepalive_requests 1000;\n\
86
- \n\
87
- client_max_body_size 500M;\n\
88
- client_body_buffer_size 1M;\n\
89
- client_body_timeout 300s;\n\
90
- client_header_timeout 60s;\n\
91
  \n\
92
- proxy_buffering on;\n\
93
- proxy_buffer_size 16k;\n\
94
- proxy_buffers 8 16k;\n\
95
- proxy_busy_buffers_size 32k;\n\
96
- proxy_max_temp_file_size 2048m;\n\
97
- proxy_temp_file_write_size 32k;\n\
98
- \n\
99
- proxy_connect_timeout 60s;\n\
100
- proxy_send_timeout 300s;\n\
101
- proxy_read_timeout 300s;\n\
102
- \n\
103
- gzip on;\n\
104
- gzip_vary on;\n\
105
- gzip_min_length 1024;\n\
106
- gzip_comp_level 6;\n\
107
- gzip_types text/plain text/css text/xml text/javascript application/json application/javascript;\n\
108
  \n\
109
  upstream kkfileview {\n\
110
  server 127.0.0.1:8012;\n\
111
- keepalive 32;\n\
112
- keepalive_requests 1000;\n\
113
- keepalive_timeout 60s;\n\
114
  }\n\
115
  \n\
116
  server {\n\
117
- listen 7860 default_server;\n\
118
- server_name _;\n\
119
  \n\
120
  auth_basic "Restricted Access";\n\
121
  auth_basic_user_file /etc/nginx/.htpasswd;\n\
122
  \n\
123
- add_header X-Content-Type-Options "nosniff" always;\n\
124
- add_header X-Frame-Options "SAMEORIGIN" always;\n\
125
- add_header X-XSS-Protection "1; mode=block" always;\n\
126
- \n\
127
  location / {\n\
128
  proxy_pass http://kkfileview;\n\
129
- proxy_http_version 1.1;\n\
130
- proxy_set_header Connection "";\n\
131
  proxy_set_header Host $host;\n\
132
  proxy_set_header X-Real-IP $remote_addr;\n\
133
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
134
- proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
135
- proxy_set_header X-Forwarded-Host $host;\n\
136
- proxy_set_header X-Forwarded-Port $server_port;\n\
137
- \n\
138
- proxy_buffering on;\n\
139
- proxy_buffer_size 16k;\n\
140
- proxy_buffers 8 16k;\n\
141
  proxy_read_timeout 300s;\n\
142
- \n\
143
- proxy_redirect off;\n\
144
  }\n\
145
  \n\
146
  location /health {\n\
147
  auth_basic off;\n\
148
- access_log off;\n\
149
  return 200 "OK";\n\
150
  add_header Content-Type text/plain;\n\
151
  }\n\
152
- \n\
153
- location /nginx_status {\n\
154
- auth_basic off;\n\
155
- stub_status on;\n\
156
- access_log off;\n\
157
- allow 127.0.0.1;\n\
158
- deny all;\n\
159
- }\n\
160
  }\n\
161
  }\n' > /etc/nginx/nginx.conf
162
 
@@ -164,63 +70,42 @@ http {\n\
164
  RUN printf '#!/bin/bash\n\
165
  set -e\n\
166
  \n\
167
- echo "=== Starting KKFileView Optimized for HuggingFace Spaces ==="\n\
168
- echo "Date: $(date)"\n\
169
- echo "Environment: HuggingFace Spaces (2 vCPU + 16GB RAM)"\n\
170
  \n\
171
- : "${AUTH_USERNAME:?AUTH_USERNAME is required}"\n\
172
- : "${AUTH_PASSWORD:?AUTH_PASSWORD is required}"\n\
173
  \n\
174
- echo "Creating htpasswd file for user: $AUTH_USERNAME"\n\
175
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
176
  \n\
177
  echo "Starting Xvfb..."\n\
178
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
179
  export DISPLAY=:99\n\
180
  sleep 2\n\
181
- echo "✓ Xvfb started on DISPLAY=:99"\n\
182
  \n\
183
  STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
184
  if [ -z "$STARTUP_SCRIPT" ]; then\n\
185
  echo "ERROR: KKFileView startup script not found!"\n\
186
  exit 1\n\
187
  fi\n\
188
- echo "Found KKFileView startup script: $STARTUP_SCRIPT"\n\
189
  \n\
190
  echo "Starting KKFileView on port 8012..."\n\
191
- echo "JVM Configuration:"\n\
192
- echo "$JAVA_OPTS" | tr " " "\\n" | grep -E "^-" | head -20\n\
193
- \n\
194
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
195
  bash "$STARTUP_SCRIPT" 2>&1 &\n\
196
  else\n\
197
  "$STARTUP_SCRIPT" --server.port=8012 2>&1 &\n\
198
  fi\n\
199
- KKFILEVIEW_PID=$!\n\
200
- echo "KKFileView started with PID: $KKFILEVIEW_PID"\n\
201
  \n\
202
- echo "Waiting for KKFileView to start (max 60 seconds)..."\n\
203
  for i in {1..30}; do\n\
204
  if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
205
- echo "✓ KKFileView is ready on port 8012!"\n\
206
  break\n\
207
  fi\n\
208
- if [ $i -eq 30 ]; then\n\
209
- echo "ERROR: KKFileView failed to start within 60 seconds"\n\
210
- echo "Checking if process is still running..."\n\
211
- if ps -p $KKFILEVIEW_PID > /dev/null; then\n\
212
- echo "Process is running but not responding"\n\
213
- else\n\
214
- echo "Process has died"\n\
215
- fi\n\
216
- exit 1\n\
217
- fi\n\
218
- echo "Waiting... ($i/30)"\n\
219
  sleep 2\n\
220
  done\n\
221
  \n\
222
- echo "Starting Nginx on port 7860..."\n\
223
- echo "Nginx will log to stdout/stderr"\n\
224
  nginx -g "daemon off;"\n' > /start.sh && \
225
  chmod +x /start.sh
226
 
@@ -231,6 +116,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
231
  # 7. 暴露端口
232
  EXPOSE 7860
233
 
234
- # 8. 启动命令
235
- ENTRYPOINT []
236
  CMD ["/start.sh"]
 
12
  && rm -rf /var/lib/apt/lists/* \
13
  && fc-cache -fv
14
 
15
+ # 2. JVM 配置
16
  ENV SERVER_PORT=8012 \
17
+ JAVA_OPTS="-Xms2g -Xmx2g -Djava.awt.headless=true"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ # 3. 创建必要目录
20
+ RUN mkdir -p /var/log/kkfileview
 
21
 
22
  # 4. Nginx 配置
23
  RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* /etc/nginx/nginx.conf && \
24
+ printf 'worker_processes auto;\n\
 
 
 
 
25
  error_log /dev/stderr warn;\n\
26
  pid /var/run/nginx.pid;\n\
27
  \n\
28
  events {\n\
29
+ worker_connections 1024;\n\
 
 
 
30
  }\n\
31
  \n\
32
  http {\n\
33
  include /etc/nginx/mime.types;\n\
34
  default_type application/octet-stream;\n\
35
  \n\
36
+ access_log /dev/stdout;\n\
 
 
 
 
37
  \n\
38
  sendfile on;\n\
 
 
39
  keepalive_timeout 65;\n\
 
 
 
 
 
 
40
  \n\
41
+ client_max_body_size 200M;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  \n\
43
  upstream kkfileview {\n\
44
  server 127.0.0.1:8012;\n\
 
 
 
45
  }\n\
46
  \n\
47
  server {\n\
48
+ listen 7860;\n\
 
49
  \n\
50
  auth_basic "Restricted Access";\n\
51
  auth_basic_user_file /etc/nginx/.htpasswd;\n\
52
  \n\
 
 
 
 
53
  location / {\n\
54
  proxy_pass http://kkfileview;\n\
 
 
55
  proxy_set_header Host $host;\n\
56
  proxy_set_header X-Real-IP $remote_addr;\n\
57
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
 
 
 
 
 
 
 
58
  proxy_read_timeout 300s;\n\
 
 
59
  }\n\
60
  \n\
61
  location /health {\n\
62
  auth_basic off;\n\
 
63
  return 200 "OK";\n\
64
  add_header Content-Type text/plain;\n\
65
  }\n\
 
 
 
 
 
 
 
 
66
  }\n\
67
  }\n' > /etc/nginx/nginx.conf
68
 
 
70
  RUN printf '#!/bin/bash\n\
71
  set -e\n\
72
  \n\
73
+ echo "=== Starting KKFileView (Simplified) ==="\n\
 
 
74
  \n\
75
+ : "${AUTH_USERNAME:?AUTH_USERNAME required}"\n\
76
+ : "${AUTH_PASSWORD:?AUTH_PASSWORD required}"\n\
77
  \n\
 
78
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
79
  \n\
80
  echo "Starting Xvfb..."\n\
81
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
82
  export DISPLAY=:99\n\
83
  sleep 2\n\
 
84
  \n\
85
  STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
86
  if [ -z "$STARTUP_SCRIPT" ]; then\n\
87
  echo "ERROR: KKFileView startup script not found!"\n\
88
  exit 1\n\
89
  fi\n\
 
90
  \n\
91
  echo "Starting KKFileView on port 8012..."\n\
 
 
 
92
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
93
  bash "$STARTUP_SCRIPT" 2>&1 &\n\
94
  else\n\
95
  "$STARTUP_SCRIPT" --server.port=8012 2>&1 &\n\
96
  fi\n\
 
 
97
  \n\
98
+ echo "Waiting for KKFileView..."\n\
99
  for i in {1..30}; do\n\
100
  if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
101
+ echo "✓ KKFileView ready!"\n\
102
  break\n\
103
  fi\n\
104
+ [ $i -eq 30 ] && echo "ERROR: Timeout" && exit 1\n\
 
 
 
 
 
 
 
 
 
 
105
  sleep 2\n\
106
  done\n\
107
  \n\
108
+ echo "Starting Nginx..."\n\
 
109
  nginx -g "daemon off;"\n' > /start.sh && \
110
  chmod +x /start.sh
111
 
 
116
  # 7. 暴露端口
117
  EXPOSE 7860
118
 
119
+ # 8. 启动
 
120
  CMD ["/start.sh"]