File size: 2,311 Bytes
d2e0457
e4cf850
919170c
bbf8af3
919170c
 
 
 
 
 
bbf8af3
 
919170c
 
2fc6c9d
e4cf850
2fc6c9d
919170c
2fc6c9d
 
 
 
 
 
bbf8af3
7f342f8
 
 
2fc6c9d
 
 
 
 
 
 
 
 
 
 
7f342f8
 
 
 
2fc6c9d
7f342f8
2fc6c9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f342f8
e4cf850
 
 
919170c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
FROM yimik/kkfileview:latest

USER root

RUN 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=7860
ENV 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.sh

EXPOSE 7860

CMD ["/start.sh"]