Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101114 unmodified lines1161171181191206 unmodified linesnginx \apache2-utils \xvfb \fonts-wqy-zenhei \curl \&& rm -rf /var/lib/apt/lists/* \&& fc-cache -fv# 2. JVM 配置ENV SERVER_PORT=8012 \JAVA_OPTS="-Xms2g -Xmx2g -Djava.awt.headless=true"# 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 auto;\n\error_log /dev/stderr warn;\n\pid /var/run/nginx.pid;\n\\n\events {\n\worker_connections 1024;\n\}\n\\n\http {\n\include /etc/nginx/mime.types;\n\default_type application/octet-stream;\n\\n\access_log /dev/stdout;\n\\n\sendfile on;\n\keepalive_timeout 65;\n\\n\client_max_body_size 200M;\n\\n\upstream kkfileview {\n\server 127.0.0.1:8012;\n\}\n\\n\server {\n\listen 7860;\n\\n\auth_basic "Restricted Access";\n\auth_basic_user_file /etc/nginx/.htpasswd;\n\\n\location / {\n\proxy_pass http://kkfileview;\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_read_timeout 300s;\n\}\n\\n\location /health {\n\auth_basic off;\n\return 200 "OK";\n\add_header Content-Type text/plain;\n\}\n\}\n\}\n' > /etc/nginx/nginx.conf# 5. 启动脚本RUN printf '#!/bin/bash\n\set -e\n\\n\echo "=== Starting KKFileView (Simplified) ==="\n\\n\: "${AUTH_USERNAME:?AUTH_USERNAME required}"\n\: "${AUTH_PASSWORD:?AUTH_PASSWORD required}"\n\\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\\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\\n\echo "Starting KKFileView on port 8012..."\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\\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 ready!"\n\break\n\fi\n\[ $i -eq 30 ] && echo "ERROR: Timeout" && exit 1\n\sleep 2\n\done\n\\n\echo "Starting Nginx..."\n\nginx -g "daemon off;"\n' > /start.sh && \chmod +x /start.sh4 unmodified lines# 7. 暴露端口EXPOSE 7860# 8. 启动CMD ["/start.sh"]6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171184 unmodified lines1231241251261271286 unmodified linesnginx \apache2-utils \xvfb \curl \libfreetype6 \fontconfig \fonts-wqy-zenhei \&& rm -rf /var/lib/apt/lists/* \&& fc-cache -fv# 2. 环境变量配置ENV SERVER_PORT=8012ENV KKFILEVIEW_SECURITY_TRUST_HOST=defaultENV AUTH_USERNAME=adminENV AUTH_PASSWORD=yourpassword# 3. JVM 配置ENV JAVA_OPTS="-Dsun.java2d.fontpath=/usr/share/fonts -Djava.awt.headless=true"# 4. Nginx 配置RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \printf 'server {\n\listen 7860 default_server;\n\server_name _;\n\\n\# Basic Auth\n\auth_basic "Restricted Access";\n\auth_basic_user_file /etc/nginx/.htpasswd;\n\\n\# 文件上传限制\n\client_max_body_size 500M;\n\\n\# 反向代理到 KKFileView\n\location / {\n\proxy_pass http://127.0.0.1:8012;\n\proxy_set_header Host $http_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_buffering off;\n\proxy_read_timeout 300s;\n\}\n\\n\# 健康检查端点)\n\location /health {\n\auth_basic off;\n\return 200 "OK";\n\add_header Content-Type text/plain;\n\}\n\}\n' > /etc/nginx/conf.d/kkfileview.conf# 5. 启动脚本RUN printf '#!/bin/bash\n\set -e\n\\n\echo "=== Starting KKFileView for HuggingFace Spaces ==="\n\\n\# 查找 KKFileView 启动脚本\n\STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\\n\# 生成 htpasswd 文件\n\htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\\n\# 启动 Xvfb(虚拟显示)\n\echo "Starting Xvfb..."\n\Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\export DISPLAY=:99\n\sleep 2\n\\n\# 启动 KKFileView\n\echo "Starting KKFileView on port 8012..."\n\export JAVA_OPTS="$JAVA_OPTS"\n\\n\if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\bash "$STARTUP_SCRIPT" 2>&1 | tee /var/log/kkfileview.log &\n\else\n\"$STARTUP_SCRIPT" --server.port=8012 2>&1 | tee /var/log/kkfileview.log &\n\fi\n\\n\# 等待日志文件生成\n\echo "Waiting for log file..."\n\LOG_FILE="$KK_ROOT_DIR/log/kkFileView.log"\n\for i in {1..30}; do\n\if [ -f "$LOG_FILE" ]; then\n\echo "✓ Found log file: $LOG_FILE"\n\tail -f "$LOG_FILE" &\n\break\n\fi\n\sleep 1\n\done\n\\n\# 等待 KKFileView 启动(使用 curl 替代 netstat)\n\echo "Waiting for KKFileView to start..."\n\for i in {1..60}; 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\break\n\fi\n\if [ $i -eq 60 ]; then\n\echo "ERROR: KKFileView failed to start within 120 seconds"\n\exit 1\n\fi\n\echo "Waiting... ($i/60)"\n\sleep 2\n\done\n\\n\# 启动 Nginx\n\echo "Starting Nginx on port 7860..."\n\nginx -g "daemon off;"\n' > /start.sh && \chmod +x /start.sh4 unmodified lines# 7. 暴露端口EXPOSE 7860# 8. 启动命令ENTRYPOINT []CMD ["/start.sh"]
Dockerfile+69-61