dragg2 commited on
Commit
e085d41
·
verified ·
1 Parent(s): fe41ce4

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +69 -61
Dockerfile CHANGED
@@ -7,105 +7,112 @@ RUN apt-get update && apt-get install -y \
7
  nginx \
8
  apache2-utils \
9
  xvfb \
10
- fonts-wqy-zenhei \
11
  curl \
 
 
 
12
  && rm -rf /var/lib/apt/lists/* \
13
  && fc-cache -fv
14
 
15
- # 2. JVM 配置
16
- ENV SERVER_PORT=8012 \
17
- JAVA_OPTS="-Xms2g -Xmx2g -Djava.awt.headless=true"
 
 
18
 
19
- # 3. 创建必要目录
20
- RUN mkdir -p /var/log/kkfileview
21
 
22
  # 4. Nginx 配置
23
- RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* /etc/nginx/nginx.conf && \
24
- printf 'worker_processes auto;\n\
25
- error_log /dev/stderr warn;\n\
26
- pid /var/run/nginx.pid;\n\
27
- \n\
28
- events {\n\
29
- worker_connections 1024;\n\
30
- }\n\
31
- \n\
32
- http {\n\
33
- include /etc/nginx/mime.types;\n\
34
- default_type application/octet-stream;\n\
35
  \n\
36
- access_log /dev/stdout;\n\
 
 
37
  \n\
38
- sendfile on;\n\
39
- keepalive_timeout 65;\n\
40
  \n\
41
- client_max_body_size 200M;\n\
42
- \n\
43
- upstream kkfileview {\n\
44
- server 127.0.0.1:8012;\n\
 
 
 
 
 
45
  }\n\
46
  \n\
47
- server {\n\
48
- listen 7860;\n\
49
- \n\
50
- auth_basic "Restricted Access";\n\
51
- auth_basic_user_file /etc/nginx/.htpasswd;\n\
52
- \n\
53
- location / {\n\
54
- proxy_pass http://kkfileview;\n\
55
- proxy_set_header Host $host;\n\
56
- proxy_set_header X-Real-IP $remote_addr;\n\
57
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
58
- proxy_read_timeout 300s;\n\
59
- }\n\
60
- \n\
61
- location /health {\n\
62
- auth_basic off;\n\
63
- return 200 "OK";\n\
64
- add_header Content-Type text/plain;\n\
65
- }\n\
66
  }\n\
67
- }\n' > /etc/nginx/nginx.conf
68
 
69
  # 5. 启动脚本
70
  RUN printf '#!/bin/bash\n\
71
  set -e\n\
72
  \n\
73
- echo "=== Starting KKFileView (Simplified) ==="\n\
74
  \n\
75
- : "${AUTH_USERNAME:?AUTH_USERNAME required}"\n\
76
- : "${AUTH_PASSWORD:?AUTH_PASSWORD required}"\n\
 
77
  \n\
 
78
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
79
  \n\
 
80
  echo "Starting Xvfb..."\n\
81
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
82
  export DISPLAY=:99\n\
83
  sleep 2\n\
84
  \n\
85
- STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
86
- if [ -z "$STARTUP_SCRIPT" ]; then\n\
87
- echo "ERROR: KKFileView startup script not found!"\n\
88
- exit 1\n\
89
- fi\n\
90
- \n\
91
  echo "Starting KKFileView on port 8012..."\n\
 
 
92
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
93
- bash "$STARTUP_SCRIPT" 2>&1 &\n\
94
  else\n\
95
- "$STARTUP_SCRIPT" --server.port=8012 2>&1 &\n\
96
  fi\n\
97
  \n\
98
- echo "Waiting for KKFileView..."\n\
 
 
99
  for i in {1..30}; do\n\
 
 
 
 
 
 
 
 
 
 
 
100
  if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
101
- echo "✓ KKFileView ready!"\n\
102
  break\n\
103
  fi\n\
104
- [ $i -eq 30 ] && echo "ERROR: Timeout" && exit 1\n\
 
 
 
 
105
  sleep 2\n\
106
  done\n\
107
  \n\
108
- echo "Starting Nginx..."\n\
 
109
  nginx -g "daemon off;"\n' > /start.sh && \
110
  chmod +x /start.sh
111
 
@@ -116,5 +123,6 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
116
  # 7. 暴露端口
117
  EXPOSE 7860
118
 
119
- # 8. 启动
 
120
  CMD ["/start.sh"]
 
7
  nginx \
8
  apache2-utils \
9
  xvfb \
 
10
  curl \
11
+ libfreetype6 \
12
+ fontconfig \
13
+ fonts-wqy-zenhei \
14
  && rm -rf /var/lib/apt/lists/* \
15
  && fc-cache -fv
16
 
17
+ # 2. 环境变量配置
18
+ ENV SERVER_PORT=8012
19
+ ENV KKFILEVIEW_SECURITY_TRUST_HOST=default
20
+ ENV AUTH_USERNAME=admin
21
+ ENV AUTH_PASSWORD=yourpassword
22
 
23
+ # 3. JVM 配置
24
+ ENV JAVA_OPTS="-Dsun.java2d.fontpath=/usr/share/fonts -Djava.awt.headless=true"
25
 
26
  # 4. Nginx 配置
27
+ RUN rm -rf /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
28
+ printf 'server {\n\
29
+ listen 7860 default_server;\n\
30
+ server_name _;\n\
 
 
 
 
 
 
 
 
31
  \n\
32
+ # Basic Auth\n\
33
+ auth_basic "Restricted Access";\n\
34
+ auth_basic_user_file /etc/nginx/.htpasswd;\n\
35
  \n\
36
+ # 文件上传限制\n\
37
+ client_max_body_size 500M;\n\
38
  \n\
39
+ # 反向代理到 KKFileView\n\
40
+ location / {\n\
41
+ proxy_pass http://127.0.0.1:8012;\n\
42
+ proxy_set_header Host $http_host;\n\
43
+ proxy_set_header X-Real-IP $remote_addr;\n\
44
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
45
+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\
46
+ proxy_buffering off;\n\
47
+ proxy_read_timeout 300s;\n\
48
  }\n\
49
  \n\
50
+ # 健康检查端点)\n\
51
+ location /health {\n\
52
+ auth_basic off;\n\
53
+ return 200 "OK";\n\
54
+ add_header Content-Type text/plain;\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }\n\
56
+ }\n' > /etc/nginx/conf.d/kkfileview.conf
57
 
58
  # 5. 启动脚本
59
  RUN printf '#!/bin/bash\n\
60
  set -e\n\
61
  \n\
62
+ echo "=== Starting KKFileView for HuggingFace Spaces ==="\n\
63
  \n\
64
+ # 查找 KKFileView 启动脚本\n\
65
+ STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\
66
+ KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\
67
  \n\
68
+ # 生成 htpasswd 文件\n\
69
  htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\
70
  \n\
71
+ # 启动 Xvfb(虚拟显示)\n\
72
  echo "Starting Xvfb..."\n\
73
  Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\
74
  export DISPLAY=:99\n\
75
  sleep 2\n\
76
  \n\
77
+ # 启动 KKFileView\n\
 
 
 
 
 
78
  echo "Starting KKFileView on port 8012..."\n\
79
+ export JAVA_OPTS="$JAVA_OPTS"\n\
80
+ \n\
81
  if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\
82
+ bash "$STARTUP_SCRIPT" 2>&1 | tee /var/log/kkfileview.log &\n\
83
  else\n\
84
+ "$STARTUP_SCRIPT" --server.port=8012 2>&1 | tee /var/log/kkfileview.log &\n\
85
  fi\n\
86
  \n\
87
+ # 等待日志文件生成\n\
88
+ echo "Waiting for log file..."\n\
89
+ LOG_FILE="$KK_ROOT_DIR/log/kkFileView.log"\n\
90
  for i in {1..30}; do\n\
91
+ if [ -f "$LOG_FILE" ]; then\n\
92
+ echo "✓ Found log file: $LOG_FILE"\n\
93
+ tail -f "$LOG_FILE" &\n\
94
+ break\n\
95
+ fi\n\
96
+ sleep 1\n\
97
+ done\n\
98
+ \n\
99
+ # 等待 KKFileView 启动(使用 curl 替代 netstat)\n\
100
+ echo "Waiting for KKFileView to start..."\n\
101
+ for i in {1..60}; do\n\
102
  if curl -s http://127.0.0.1:8012 >/dev/null 2>&1; then\n\
103
+ echo "✓ KKFileView is ready on port 8012!"\n\
104
  break\n\
105
  fi\n\
106
+ if [ $i -eq 60 ]; then\n\
107
+ echo "ERROR: KKFileView failed to start within 120 seconds"\n\
108
+ exit 1\n\
109
+ fi\n\
110
+ echo "Waiting... ($i/60)"\n\
111
  sleep 2\n\
112
  done\n\
113
  \n\
114
+ # 启动 Nginx\n\
115
+ echo "Starting Nginx on port 7860..."\n\
116
  nginx -g "daemon off;"\n' > /start.sh && \
117
  chmod +x /start.sh
118
 
 
123
  # 7. 暴露端口
124
  EXPOSE 7860
125
 
126
+ # 8. 启动命令
127
+ ENTRYPOINT []
128
  CMD ["/start.sh"]