Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980811 unmodified lineUSER rootRUN apt-get update && apt-get install -y \xvfb \libxrender1 \libxext6 \libxi6 \libgconf-2-4 \fonts-wqy-microhei \fonts-wqy-zenhei \&& rm -rf /var/lib/apt/lists/*# 设置端口和信任主机ENV SERVER_PORT=7860ENV TRUST_HOST=default# 添加执行权限RUN chmod +x /opt/kkFileView-*/bin/*.sh# 查找并修改配置文件RUN find /opt/kkFileView-* -name "application.properties" -type f -exec sed -i 's/trust.host=.*/trust.host=default/g' {} \; || \find /opt/kkFileView-* -name "application.properties" -type f -exec sh -c 'echo "trust.host=default" >> {}' \;# 创建启动脚本RUN printf '#!/bin/bash\n\echo "=== Starting kkFileView on Hugging Face Spaces ==="\n\echo "Port: $SERVER_PORT"\n\echo "Trust Host: $TRUST_HOST"\n\\n\# 查找配置文件并显示\n\CONFIG_FILE=$(find /opt/kkFileView-* -name "application.properties" -type f | head -n 1)\n\if [ -n "$CONFIG_FILE" ]; then\n\echo "Config file: $CONFIG_FILE"\n\echo "Trust host setting:"\n\grep -i "trust.host" "$CONFIG_FILE" || echo "trust.host not found in config"\n\fi\n\\n\echo "Starting Xvfb..."\n\Xvfb :99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset &\n\export DISPLAY=:99\n\sleep 3\n\\n\echo "Starting kkFileView..."\n\KKVIEW_DIR=$(find /opt -maxdepth 1 -type d -name "kkFileView-*" | head -n 1)\n\if [ -z "$KKVIEW_DIR" ]; then\n\echo "Error: kkFileView directory not found"\n\exit 1\n\fi\n\\n\echo "kkFileView directory: $KKVIEW_DIR"\n\cd "$KKVIEW_DIR"\n\\n\# 使用绝对路径启动\n\if [ -f "$KKVIEW_DIR/bin/startup.sh" ]; then\n\echo "Executing: $KKVIEW_DIR/bin/startup.sh"\n\bash "$KKVIEW_DIR/bin/startup.sh"\n\else\n\echo "Error: startup.sh not found at $KKVIEW_DIR/bin/startup.sh"\n\ls -la "$KKVIEW_DIR/bin/"\n\exit 1\n\fi\n\\n\# 等待服务启动\n\sleep 5\n\\n\# 查找并跟踪日志\n\LOG_FILE=$(find "$KKVIEW_DIR" -name "kkFileView.log" -o -name "*.log" | head -n 1)\n\if [ -n "$LOG_FILE" ]; then\n\echo "Following log: $LOG_FILE"\n\tail -f "$LOG_FILE"\n\else\n\echo "Log file not found, keeping container alive..."\n\sleep infinity\n\fi\n' > /start.sh && \chmod +x /start.shEXPOSE 7860CMD ["/start.sh"]1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354551 unmodified lineUSER root# 安装依赖RUN apt-get update && apt-get install -y \xvfb \libxrender1 \libxext6 \&& rm -rf /var/lib/apt/lists/*# 环境变量ENV SERVER_PORT=7860# 添加执行权限RUN chmod -R 755 /opt/kkFileView-*/bin/# 修改配置文件RUN CONFIG_FILE="/opt/kkFileView-4.1.0/config/application.properties" && \if [ -f "$CONFIG_FILE" ]; then \echo "Modifying config file..." && \sed -i '/trust.host/d' "$CONFIG_FILE" && \echo "" >> "$CONFIG_FILE" && \echo "# Trust all hosts for Hugging Face Spaces" >> "$CONFIG_FILE" && \echo "trust.host = default" >> "$CONFIG_FILE" && \echo "" >> "$CONFIG_FILE" && \echo "# Port configuration" >> "$CONFIG_FILE" && \echo "server.port = 7860" >> "$CONFIG_FILE" && \echo "Configuration updated successfully" && \tail -10 "$CONFIG_FILE"; \else \echo "ERROR: Config file not found at $CONFIG_FILE" && \exit 1; \fi# 启动脚本RUN echo '#!/bin/bash' > /start.sh && \echo 'echo "=== kkFileView Configuration ==="' >> /start.sh && \echo 'grep -E "trust.host|server.port" /opt/kkFileView-4.1.0/config/application.properties || echo "Config not found"' >> /start.sh && \echo 'echo ""' >> /start.sh && \echo 'echo "Starting Xvfb..."' >> /start.sh && \echo 'Xvfb :99 -screen 0 1024x768x24 &' >> /start.sh && \echo 'export DISPLAY=:99' >> /start.sh && \echo 'sleep 2' >> /start.sh && \echo 'echo "Starting kkFileView..."' >> /start.sh && \echo 'cd /opt/kkFileView-4.1.0' >> /start.sh && \echo 'bash /opt/kkFileView-4.1.0/bin/startup.sh' >> /start.sh && \echo 'echo ""' >> /start.sh && \echo 'echo "Service started. Access at: http://localhost:7860"' >> /start.sh && \echo 'tail -f /opt/kkFileView-4.1.0/log/*.log' >> /start.sh && \chmod +x /start.shEXPOSE 7860CMD ["/start.sh"]
Dockerfile+38-64