Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files11 unmodified lines1213141515161718192021222324252627282930313233343536373839404142434445464748171850515219202122235657585960242526272865666768293031323334357576777879363738828339858687888990409293949596979899100101102103104105106107414243441111121134546471171184849505152123124125126535412913055565713413513613713813914058142143596061621486364651521531541551561571581596667681 unmodified line7071721671681697374171172757677174787980818283181848586878889188909119119219392939495961992009720298991002051011021032082092102112122132142152162172181041051061072222231081091101114 unmodified lines11611711823423511912011 unmodified lines && rm -rf /var/lib/apt/lists/* \ && fc-cache -fv
# 2. JVM 优化配置(针对 16GB RAM 环境)# 2. JVM 配置ENV SERVER_PORT=8012 \ KKFILEVIEW_SECURITY_TRUST_HOST=default \ JAVA_OPTS="-server \-Xms8g \-Xmx8g \-XX:+UseG1GC \-XX:MaxGCPauseMillis=200 \-XX:G1HeapRegionSize=16m \-XX:G1NewSizePercent=30 \-XX:G1MaxNewSizePercent=40 \-XX:InitiatingHeapOccupancyPercent=45 \-XX:MetaspaceSize=256m \-XX:MaxMetaspaceSize=512m \-Xss1m \-XX:+UseCompressedOops \-XX:+UseStringDeduplication \-XX:+OptimizeStringConcat \-Djava.awt.headless=true \-Dsun.java2d.fontpath=/usr/share/fonts \-Dfile.encoding=UTF-8 \-Djava.security.egd=file:/dev/./urandom \-XX:+HeapDumpOnOutOfMemoryError \-XX:HeapDumpPath=/var/log/kkfileview/ \-XX:+PrintGCDetails \-XX:+PrintGCTimeStamps \-Xloggc:/var/log/kkfileview/gc.log \-XX:+UseGCLogFileRotation \-XX:NumberOfGCLogFiles=5 \-XX:GCLogFileSize=100M \-Dserver.tomcat.threads.max=16 \-Dserver.tomcat.threads.min-spare=4 \-Dserver.tomcat.accept-count=50 \-Dserver.tomcat.max-connections=200" JAVA_OPTS="-Xms2g -Xmx2g -Djava.awt.headless=true"
# 3. 创建目录并设置权限RUN mkdir -p /var/log/kkfileview /opt/kkFileView/file && \ chmod -R 755 /var/log/kkfileview /opt/kkFileView# 3. 创建必要目录RUN mkdir -p /var/log/kkfileview
# 4. Nginx 配置RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* /etc/nginx/nginx.conf && \ printf 'worker_processes 2;\n\worker_cpu_affinity 01 10;\n\worker_priority -5;\n\worker_rlimit_nofile 65535;\n\\n\ printf 'worker_processes auto;\n\error_log /dev/stderr warn;\n\pid /var/run/nginx.pid;\n\\n\events {\n\ worker_connections 4096;\n\ multi_accept on;\n\ use epoll;\n\ accept_mutex off;\n\ worker_connections 1024;\n\}\n\\n\http {\n\ include /etc/nginx/mime.types;\n\ default_type application/octet-stream;\n\ \n\ log_format main '"'"'$remote_addr - $remote_user [$time_local] "$request" '"'"'\n\ '"'"'$status $body_bytes_sent "$http_referer" '"'"'\n\ '"'"'"$http_user_agent" rt=$request_time uct="$upstream_connect_time"'"'"';\n\ \n\ access_log /dev/stdout main;\n\ access_log /dev/stdout;\n\ \n\ sendfile on;\n\ tcp_nopush on;\n\ tcp_nodelay on;\n\ keepalive_timeout 65;\n\ keepalive_requests 1000;\n\ \n\ client_max_body_size 500M;\n\ client_body_buffer_size 1M;\n\ client_body_timeout 300s;\n\ client_header_timeout 60s;\n\ \n\ proxy_buffering on;\n\ proxy_buffer_size 16k;\n\ proxy_buffers 8 16k;\n\ proxy_busy_buffers_size 32k;\n\ proxy_max_temp_file_size 2048m;\n\ proxy_temp_file_write_size 32k;\n\ \n\ proxy_connect_timeout 60s;\n\ proxy_send_timeout 300s;\n\ proxy_read_timeout 300s;\n\ \n\ gzip on;\n\ gzip_vary on;\n\ gzip_min_length 1024;\n\ gzip_comp_level 6;\n\ gzip_types text/plain text/css text/xml text/javascript application/json application/javascript;\n\ client_max_body_size 200M;\n\ \n\ upstream kkfileview {\n\ server 127.0.0.1:8012;\n\ keepalive 32;\n\ keepalive_requests 1000;\n\ keepalive_timeout 60s;\n\ }\n\ \n\ server {\n\ listen 7860 default_server;\n\ server_name _;\n\ listen 7860;\n\ \n\ auth_basic "Restricted Access";\n\ auth_basic_user_file /etc/nginx/.htpasswd;\n\ \n\ add_header X-Content-Type-Options "nosniff" always;\n\ add_header X-Frame-Options "SAMEORIGIN" always;\n\ add_header X-XSS-Protection "1; mode=block" always;\n\ \n\ location / {\n\ proxy_pass http://kkfileview;\n\ proxy_http_version 1.1;\n\ proxy_set_header Connection "";\n\ proxy_set_header Host $host;\n\ proxy_set_header X-Real-IP $remote_addr;\n\ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\ proxy_set_header X-Forwarded-Host $host;\n\ proxy_set_header X-Forwarded-Port $server_port;\n\ \n\ proxy_buffering on;\n\ proxy_buffer_size 16k;\n\ proxy_buffers 8 16k;\n\ proxy_read_timeout 300s;\n\ \n\ proxy_redirect off;\n\ }\n\ \n\ location /health {\n\ auth_basic off;\n\ access_log off;\n\ return 200 "OK";\n\ add_header Content-Type text/plain;\n\ }\n\ \n\ location /nginx_status {\n\ auth_basic off;\n\ stub_status on;\n\ access_log off;\n\ allow 127.0.0.1;\n\ deny all;\n\ }\n\ }\n\}\n' > /etc/nginx/nginx.conf
1 unmodified lineRUN printf '#!/bin/bash\n\set -e\n\\n\echo "=== Starting KKFileView Optimized for HuggingFace Spaces ==="\n\echo "Date: $(date)"\n\echo "Environment: HuggingFace Spaces (2 vCPU + 16GB RAM)"\n\echo "=== Starting KKFileView (Simplified) ==="\n\\n\: "${AUTH_USERNAME:?AUTH_USERNAME is required}"\n\: "${AUTH_PASSWORD:?AUTH_PASSWORD is required}"\n\: "${AUTH_USERNAME:?AUTH_USERNAME required}"\n\: "${AUTH_PASSWORD:?AUTH_PASSWORD required}"\n\\n\echo "Creating htpasswd file for user: $AUTH_USERNAME"\n\htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\\n\echo "Starting Xvfb..."\n\Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\export DISPLAY=:99\n\sleep 2\n\echo "✓ Xvfb started on DISPLAY=:99"\n\\n\STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\if [ -z "$STARTUP_SCRIPT" ]; then\n\ echo "ERROR: KKFileView startup script not found!"\n\ exit 1\n\fi\n\echo "Found KKFileView startup script: $STARTUP_SCRIPT"\n\\n\echo "Starting KKFileView on port 8012..."\n\echo "JVM Configuration:"\n\echo "$JAVA_OPTS" | tr " " "\\n" | grep -E "^-" | head -20\n\\n\if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\ bash "$STARTUP_SCRIPT" 2>&1 &\n\else\n\ "$STARTUP_SCRIPT" --server.port=8012 2>&1 &\n\fi\n\KKFILEVIEW_PID=$!\n\echo "KKFileView started with PID: $KKFILEVIEW_PID"\n\\n\echo "Waiting for KKFileView to start (max 60 seconds)..."\n\echo "Waiting for KKFileView..."\n\for i in {1..30}; do\n\ if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\ echo "✓ KKFileView is ready on port 8012!"\n\ echo "✓ KKFileView ready!"\n\ break\n\ fi\n\ if [ $i -eq 30 ]; then\n\ echo "ERROR: KKFileView failed to start within 60 seconds"\n\ echo "Checking if process is still running..."\n\ if ps -p $KKFILEVIEW_PID > /dev/null; then\n\ echo "Process is running but not responding"\n\ else\n\ echo "Process has died"\n\ fi\n\ exit 1\n\ fi\n\ echo "Waiting... ($i/30)"\n\ [ $i -eq 30 ] && echo "ERROR: Timeout" && exit 1\n\ sleep 2\n\done\n\\n\echo "Starting Nginx on port 7860..."\n\echo "Nginx will log to stdout/stderr"\n\echo "Starting Nginx..."\n\nginx -g "daemon off;"\n' > /start.sh && \ chmod +x /start.sh
4 unmodified lines# 7. 暴露端口EXPOSE 7860
# 8. 启动命令ENTRYPOINT []# 8. 启动CMD ["/start.sh"]Dockerfile+17-133