dragg2 commited on
Commit
4d8577b
·
verified ·
1 Parent(s): 444c787

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +174 -64
Dockerfile CHANGED
@@ -2,107 +2,217 @@ FROM ymlisoft/kkfileview
2
 
3
  USER root
4
 
5
- # 1. 安装所有必要依赖
6
- # ffmpeg: 用于视频转码
7
- # fonts-*: 解决 CAD
8
- # libfreetype6, fontconfig: 字体支持库
9
  RUN apt-get update && apt-get install -y \
10
  nginx \
11
  apache2-utils \
12
  xvfb \
13
- net-tools \
14
- curl \
15
- ffmpeg \
16
- libfreetype6 \
17
- fontconfig \
18
- fonts-wqy-microhei \
19
  fonts-wqy-zenhei \
20
- fonts-arphic-ukai \
21
- fonts-arphic-uming \
22
- xfonts-75dpi \
23
- xfonts-100dpi \
24
- && rm -rf /var/lib/apt/lists/* && \
25
- fc-cache -fv
26
 
27
- ENV SERVER_PORT=8012
28
- ENV KKFILEVIEW_SECURITY_TRUST_HOST=default
29
- ENV AUTH_USERNAME=admin
30
- ENV AUTH_PASSWORD=yourpassword
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # 修复 Aspose 字体问题
33
- ENV JAVA_OPTS="-Dsun.java2d.fontpath=/usr/share/fonts -Djava.awt.headless=true"
 
 
34
 
35
- # Nginx 配置
36
- RUN rm -rf /etc/nginx/sites-enabled/* && \
37
- rm -rf /etc/nginx/conf.d/* && \
38
- printf 'server {\n\
39
- listen 7860 default_server;\n\
40
- server_name _;\n\
41
- auth_basic "Restricted Access";\n\
42
- auth_basic_user_file /etc/nginx/.htpasswd;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  client_max_body_size 500M;\n\
44
- location / {\n\
45
- proxy_pass http://127.0.0.1:8012;\n\
46
- proxy_set_header Host $http_host;\n\
47
- proxy_set_header X-Real-IP $remote_addr;\n\
48
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
49
- proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
50
- proxy_buffering off;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }\n\
52
- }\n' > /etc/nginx/conf.d/kkfileview.conf
53
 
54
- # 启动脚本
55
  RUN printf '#!/bin/bash\n\
56
  set -e\n\
57
  \n\
58
- echo "=== Starting Secure kkFileView ==="\n\
59
  \n\
60
- STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
61
- KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\
62
  \n\
63
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
64
  \n\
 
65
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
66
  export DISPLAY=:99\n\
67
  sleep 2\n\
68
  \n\
69
- echo "Starting kkFileView on port 8012..."\n\
70
- # 关键:确保 JAVA_OPTS 被传递\n\
71
- # 如果脚本不支持 JAVA_OPTS 变量,我们尝试通过 export 注入\n\
72
- export JAVA_OPTS="$JAVA_OPTS"\n\
 
73
  \n\
 
 
74
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
75
- bash "$STARTUP_SCRIPT" 2>&1 | tee /var/log/kkfileview.log &\n\
76
  else\n\
77
- "$STARTUP_SCRIPT" --server.port=8012 2>&1 | tee /var/log/kkfileview.log &\n\
78
  fi\n\
79
  \n\
80
- echo "Waiting for log file..."\n\
81
- LOG_FILE="$KK_ROOT_DIR/log/kkFileView.log"\n\
82
  for i in {1..30}; do\n\
83
- if [ -f "$LOG_FILE" ]; then\n\
84
- echo "✓ Found log file: $LOG_FILE"\n\
85
- tail -f "$LOG_FILE" &\n\
86
  break\n\
87
  fi\n\
88
- sleep 1\n\
89
- done\n\
90
- \n\
91
- echo "Waiting for backend..."\n\
92
- for i in {1..60}; do\n\
93
- if netstat -tuln | grep ":8012 " > /dev/null; then\n\
94
- echo "✓ Port 8012 is ready!"\n\
95
- break\n\
96
  fi\n\
97
- echo "Waiting... ($i/60)"\n\
98
  sleep 2\n\
99
  done\n\
100
  \n\
101
- echo "Starting Nginx on 7860..."\n\
102
  nginx -g "daemon off;"\n' > /start.sh && \
103
  chmod +x /start.sh
104
 
 
 
 
 
 
105
  EXPOSE 7860
106
 
 
107
  ENTRYPOINT []
108
- CMD ["/start.sh"]
 
2
 
3
  USER root
4
 
5
+ # 1. 安装必要依赖
 
 
 
6
  RUN apt-get update && apt-get install -y \
7
  nginx \
8
  apache2-utils \
9
  xvfb \
 
 
 
 
 
 
10
  fonts-wqy-zenhei \
11
+ curl \
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. 创建非 root 用户
51
+ RUN useradd -m -u 1000 -s /bin/bash kkuser && \
52
+ mkdir -p /var/log/kkfileview /opt/kkFileView/file && \
53
+ chown -R kkuser:kkuser /var/log/kkfileview /opt/kkFileView
54
 
55
+ # 4. Nginx 配置
56
+ RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
57
+ printf 'user nginx;\n\
58
+ worker_processes 2;\n\
59
+ worker_cpu_affinity 01 10;\n\
60
+ worker_priority -5;\n\
61
+ worker_rlimit_nofile 65535;\n\
62
+ \n\
63
+ error_log /var/log/nginx/error.log warn;\n\
64
+ pid /var/run/nginx.pid;\n\
65
+ \n\
66
+ events {\n\
67
+ worker_connections 4096;\n\
68
+ multi_accept on;\n\
69
+ use epoll;\n\
70
+ accept_mutex off;\n\
71
+ }\n\
72
+ \n\
73
+ http {\n\
74
+ include /etc/nginx/mime.types;\n\
75
+ default_type application/octet-stream;\n\
76
+ \n\
77
+ log_format main '"'"'$remote_addr - $remote_user [$time_local] "$request" '"'"'\n\
78
+ '"'"'$status $body_bytes_sent "$http_referer" '"'"'\n\
79
+ '"'"'"$http_user_agent" rt=$request_time uct="$upstream_connect_time"'"'"';\n\
80
+ \n\
81
+ access_log /var/log/nginx/access.log main;\n\
82
+ \n\
83
+ sendfile on;\n\
84
+ tcp_nopush on;\n\
85
+ tcp_nodelay on;\n\
86
+ keepalive_timeout 65;\n\
87
+ keepalive_requests 1000;\n\
88
+ \n\
89
  client_max_body_size 500M;\n\
90
+ client_body_buffer_size 1M;\n\
91
+ client_body_timeout 300s;\n\
92
+ client_header_timeout 60s;\n\
93
+ \n\
94
+ proxy_buffering on;\n\
95
+ proxy_buffer_size 16k;\n\
96
+ proxy_buffers 8 16k;\n\
97
+ proxy_busy_buffers_size 32k;\n\
98
+ proxy_max_temp_file_size 2048m;\n\
99
+ proxy_temp_file_write_size 32k;\n\
100
+ \n\
101
+ proxy_connect_timeout 60s;\n\
102
+ proxy_send_timeout 300s;\n\
103
+ proxy_read_timeout 300s;\n\
104
+ \n\
105
+ gzip on;\n\
106
+ gzip_vary on;\n\
107
+ gzip_min_length 1024;\n\
108
+ gzip_comp_level 6;\n\
109
+ gzip_types text/plain text/css text/xml text/javascript application/json application/javascript;\n\
110
+ \n\
111
+ upstream kkfileview {\n\
112
+ server 127.0.0.1:8012;\n\
113
+ keepalive 32;\n\
114
+ keepalive_requests 1000;\n\
115
+ keepalive_timeout 60s;\n\
116
+ }\n\
117
+ \n\
118
+ server {\n\
119
+ listen 7860 default_server;\n\
120
+ server_name _;\n\
121
+ \n\
122
+ auth_basic "Restricted Access";\n\
123
+ auth_basic_user_file /etc/nginx/.htpasswd;\n\
124
+ \n\
125
+ add_header X-Content-Type-Options "nosniff" always;\n\
126
+ add_header X-Frame-Options "SAMEORIGIN" always;\n\
127
+ add_header X-XSS-Protection "1; mode=block" always;\n\
128
+ \n\
129
+ location / {\n\
130
+ proxy_pass http://kkfileview;\n\
131
+ proxy_http_version 1.1;\n\
132
+ proxy_set_header Connection "";\n\
133
+ proxy_set_header Host $http_host;\n\
134
+ proxy_set_header X-Real-IP $remote_addr;\n\
135
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
136
+ proxy_set_header X-Forwarded-Proto $scheme;\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
+ \n\
144
+ location /health {\n\
145
+ auth_basic off;\n\
146
+ access_log off;\n\
147
+ return 200 "OK";\n\
148
+ add_header Content-Type text/plain;\n\
149
+ }\n\
150
+ \n\
151
+ location /nginx_status {\n\
152
+ auth_basic off;\n\
153
+ stub_status on;\n\
154
+ access_log off;\n\
155
+ allow 127.0.0.1;\n\
156
+ deny all;\n\
157
+ }\n\
158
  }\n\
159
+ }\n' > /etc/nginx/nginx.conf
160
 
161
+ # 5. 启动脚本
162
  RUN printf '#!/bin/bash\n\
163
  set -e\n\
164
  \n\
165
+ echo "=== Starting KKFileView Optimized for HuggingFace Spaces ==="\n\
166
  \n\
167
+ : "${AUTH_USERNAME:?AUTH_USERNAME is required}"\n\
168
+ : "${AUTH_PASSWORD:?AUTH_PASSWORD is required}"\n\
169
  \n\
170
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
171
  \n\
172
+ echo "Starting Xvfb..."\n\
173
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
174
  export DISPLAY=:99\n\
175
  sleep 2\n\
176
  \n\
177
+ STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
178
+ if [ -z "$STARTUP_SCRIPT" ]; then\n\
179
+ echo "ERROR: KKFileView startup script not found!"\n\
180
+ exit 1\n\
181
+ fi\n\
182
  \n\
183
+ echo "Starting KKFileView on port 8012..."\n\
184
+ echo "JVM Configuration: $JAVA_OPTS"\n\
185
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
186
+ bash "$STARTUP_SCRIPT" 2>&1 | tee /var/log/kkfileview/app.log &\n\
187
  else\n\
188
+ "$STARTUP_SCRIPT" --server.port=8012 2>&1 | tee /var/log/kkfileview/app.log &\n\
189
  fi\n\
190
  \n\
191
+ echo "Waiting for KKFileView to start..."\n\
 
192
  for i in {1..30}; do\n\
193
+ if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
194
+ echo "✓ KKFileView is ready!"\n\
 
195
  break\n\
196
  fi\n\
197
+ if [ $i -eq 30 ]; then\n\
198
+ echo "ERROR: KKFileView failed to start within 60 seconds"\n\
199
+ cat /var/log/kkfileview/app.log\n\
200
+ exit 1\n\
 
 
 
 
201
  fi\n\
 
202
  sleep 2\n\
203
  done\n\
204
  \n\
205
+ echo "Starting Nginx on port 7860..."\n\
206
  nginx -g "daemon off;"\n' > /start.sh && \
207
  chmod +x /start.sh
208
 
209
+ # 6. 健康检查
210
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
211
+ CMD curl -f http://localhost:7860/health || exit 1
212
+
213
+ # 7. 暴露端口
214
  EXPOSE 7860
215
 
216
+ # 8. 启动命令
217
  ENTRYPOINT []
218
+ CMD ["/start.sh"]