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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -11
Dockerfile CHANGED
@@ -52,13 +52,13 @@ 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/* && \
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 /var/log/nginx/error.log warn;\n\
62
  pid /var/run/nginx.pid;\n\
63
  \n\
64
  events {\n\
@@ -76,7 +76,7 @@ http {\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 /var/log/nginx/access.log main;\n\
80
  \n\
81
  sendfile on;\n\
82
  tcp_nopush on;\n\
@@ -128,15 +128,19 @@ http {\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 $http_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 $scheme;\n\
 
 
135
  \n\
136
  proxy_buffering on;\n\
137
  proxy_buffer_size 16k;\n\
138
  proxy_buffers 8 16k;\n\
139
  proxy_read_timeout 300s;\n\
 
 
140
  }\n\
141
  \n\
142
  location /health {\n\
@@ -161,46 +165,62 @@ RUN printf '#!/bin/bash\n\
161
  set -e\n\
162
  \n\
163
  echo "=== Starting KKFileView Optimized for HuggingFace Spaces ==="\n\
 
 
164
  \n\
165
  : "${AUTH_USERNAME:?AUTH_USERNAME is required}"\n\
166
  : "${AUTH_PASSWORD:?AUTH_PASSWORD is required}"\n\
167
  \n\
 
168
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
169
  \n\
170
  echo "Starting Xvfb..."\n\
171
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
172
  export DISPLAY=:99\n\
173
  sleep 2\n\
 
174
  \n\
175
  STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
176
  if [ -z "$STARTUP_SCRIPT" ]; then\n\
177
  echo "ERROR: KKFileView startup script not found!"\n\
178
  exit 1\n\
179
  fi\n\
 
180
  \n\
181
  echo "Starting KKFileView on port 8012..."\n\
182
- echo "JVM Configuration: $JAVA_OPTS"\n\
 
 
183
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
184
- bash "$STARTUP_SCRIPT" 2>&1 | tee /var/log/kkfileview/app.log &\n\
185
  else\n\
186
- "$STARTUP_SCRIPT" --server.port=8012 2>&1 | tee /var/log/kkfileview/app.log &\n\
187
  fi\n\
 
 
188
  \n\
189
- echo "Waiting for KKFileView to start..."\n\
190
  for i in {1..30}; do\n\
191
  if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
192
- echo "✓ KKFileView is ready!"\n\
193
  break\n\
194
  fi\n\
195
  if [ $i -eq 30 ]; then\n\
196
  echo "ERROR: KKFileView failed to start within 60 seconds"\n\
197
- cat /var/log/kkfileview/app.log\n\
 
 
 
 
 
198
  exit 1\n\
199
  fi\n\
 
200
  sleep 2\n\
201
  done\n\
202
  \n\
203
  echo "Starting Nginx on port 7860..."\n\
 
204
  nginx -g "daemon off;"\n' > /start.sh && \
205
  chmod +x /start.sh
206
 
 
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\
 
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\
 
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\
 
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