tao-shen commited on
Commit
6ef5ad4
·
1 Parent(s): 5cd111e

fix: noVNC run in foreground with --web; dbus optional; add --wait-url for poll-without-token; doc PUSH_DEBUG

Browse files
docs/PUSH_DEBUG.md CHANGED
@@ -45,7 +45,9 @@ HF_TOKEN=你的token python3 scripts/monitor_and_test.py --space-id 你的用户
45
 
46
  `--space-id` 默认是 `tao-shen/HuggingRun`,可省略。
47
 
48
- ### 2.3 等 RUNNING 后跑完整测试(一键「远端是否成功」)
 
 
49
 
50
  ```bash
51
  # Demo 或默认 Space
@@ -57,7 +59,15 @@ HF_TOKEN=你的token python3 scripts/monitor_and_test.py --wait-running --test \
57
  --expect noVNC
58
  ```
59
 
60
- 脚本会先轮询直到 Space 状态为 RUNNING,再跑:基础 GET、压力请求、多轮持久化检查。**全部通过才 exit 0**,任一失败则 exit 1,便于脚本化「只有远端成功才算数」。
 
 
 
 
 
 
 
 
61
 
62
  ### 2.4 不等待、直接测当前页面(Space 已 RUNNING 时)
63
 
@@ -81,11 +91,11 @@ python3 scripts/monitor_and_test.py --url https://xxx.hf.space --test --expect n
81
  HF_TOKEN=xxx python3 scripts/monitor_and_test.py --wait-running --test --url https://tao-shen-huggingrun.hf.space --expect noVNC
82
  ```
83
 
84
- 3. 若 **测试失败**:用 `--logs run` 看容器内报错,修代码后:
85
  ```bash
86
  git add -A && git commit -m "fix: ..." && git push origin main
87
  ```
88
- 然后重复 1–2,直到测试全部通过。
89
 
90
  ---
91
 
 
45
 
46
  `--space-id` 默认是 `tao-shen/HuggingRun`,可省略。
47
 
48
+ ### 2.3 等 RUNNING / 等 URL 就绪后跑完整测试(一键「远端是否成功」)
49
+
50
+ **方式 A:有 HF_TOKEN 时**(推荐,可看 API 状态)
51
 
52
  ```bash
53
  # Demo 或默认 Space
 
59
  --expect noVNC
60
  ```
61
 
62
+ **方式 B:无 HF_TOKEN 时**(只轮询 URL 直到页面出现期望内容)
63
+
64
+ ```bash
65
+ python3 scripts/monitor_and_test.py --wait-url --test \
66
+ --url https://你的用户名-你的Space名.hf.space \
67
+ --expect noVNC --max-wait 900
68
+ ```
69
+
70
+ 脚本会先轮询直到 GET 200 且 body 含 `noVNC`(或你给的 `--expect`),再跑:基础 GET、压力请求、多轮持久化检查。**全部通过才 exit 0**,任一失败则 exit 1。
71
 
72
  ### 2.4 不等待、直接测当前页面(Space 已 RUNNING 时)
73
 
 
91
  HF_TOKEN=xxx python3 scripts/monitor_and_test.py --wait-running --test --url https://tao-shen-huggingrun.hf.space --expect noVNC
92
  ```
93
 
94
+ 3. 若 **测试失败或一直 503**:用 `--logs run`(以及 `--logs build`)看容器内报错,修代码后:
95
  ```bash
96
  git add -A && git commit -m "fix: ..." && git push origin main
97
  ```
98
+ 然后重复 1–2,直到测试全部通过。**只有远端全部通过才算数。**
99
 
100
  ---
101
 
scripts/monitor_and_test.py CHANGED
@@ -35,7 +35,7 @@ def get_runtime():
35
 
36
 
37
  def wait_running(max_wait_sec=600, poll_interval=15):
38
- """轮询直到 stage == RUNNING 或超时。"""
39
  start = time.time()
40
  while (time.time() - start) < max_wait_sec:
41
  rt, err = get_runtime()
@@ -54,6 +54,22 @@ def wait_running(max_wait_sec=600, poll_interval=15):
54
  return False
55
 
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def http_get(url, timeout=30, retries=3, retry_delay=2):
58
  """GET url; retry on 502/503/timeout/connection errors (generic HF robustness)."""
59
  last_status, last_body, last_err = None, "", None
@@ -154,6 +170,8 @@ def main():
154
  p.add_argument("--max-wait", type=int, default=600)
155
  p.add_argument("--expect", action="append", dest="expect_substrings",
156
  help="Expected substring(s) in response body (basic test). Can repeat. Default: HuggingRun, Run anything")
 
 
157
  args = p.parse_args()
158
  SPACE_ID = args.space_id
159
  APP_URL = args.url.rstrip("/")
@@ -168,6 +186,12 @@ def main():
168
  if not ok:
169
  sys.exit(1)
170
 
 
 
 
 
 
 
171
  if args.test:
172
  print(f"[test] Target: {APP_URL}")
173
  if not test_basic(APP_URL, expect_substrings=expect_substrings):
 
35
 
36
 
37
  def wait_running(max_wait_sec=600, poll_interval=15):
38
+ """轮询直到 stage == RUNNING 或超时。需 HF_TOKEN。"""
39
  start = time.time()
40
  while (time.time() - start) < max_wait_sec:
41
  rt, err = get_runtime()
 
54
  return False
55
 
56
 
57
+ def wait_url(url, expect_substrings=None, max_wait_sec=900, poll_interval=20):
58
+ """轮询 URL 直到 GET 200 且 body 含任一 expect_substrings;无 HF_TOKEN 时用。"""
59
+ if expect_substrings is None:
60
+ expect_substrings = ("HuggingRun", "Run anything", "noVNC")
61
+ start = time.time()
62
+ while (time.time() - start) < max_wait_sec:
63
+ status, body = http_get(url, timeout=30)
64
+ if status == 200 and any(s in body for s in expect_substrings):
65
+ print(f"[monitor] URL ready: {url}")
66
+ return True
67
+ print(f"[monitor] URL not ready: status={status}, waiting {poll_interval}s ...")
68
+ time.sleep(poll_interval)
69
+ print("[monitor] Timeout waiting for URL content")
70
+ return False
71
+
72
+
73
  def http_get(url, timeout=30, retries=3, retry_delay=2):
74
  """GET url; retry on 502/503/timeout/connection errors (generic HF robustness)."""
75
  last_status, last_body, last_err = None, "", None
 
170
  p.add_argument("--max-wait", type=int, default=600)
171
  p.add_argument("--expect", action="append", dest="expect_substrings",
172
  help="Expected substring(s) in response body (basic test). Can repeat. Default: HuggingRun, Run anything")
173
+ p.add_argument("--wait-url", action="store_true",
174
+ help="Poll URL until 200 and body contains one of --expect (no HF_TOKEN needed)")
175
  args = p.parse_args()
176
  SPACE_ID = args.space_id
177
  APP_URL = args.url.rstrip("/")
 
186
  if not ok:
187
  sys.exit(1)
188
 
189
+ if args.wait_url:
190
+ ok = wait_url(APP_URL, expect_substrings=expect_substrings or ("HuggingRun", "Run anything", "noVNC"),
191
+ max_wait_sec=args.max_wait, poll_interval=20)
192
+ if not ok:
193
+ sys.exit(1)
194
+
195
  if args.test:
196
  print(f"[test] Target: {APP_URL}")
197
  if not test_basic(APP_URL, expect_substrings=expect_substrings):
ubuntu-desktop/start-desktop.sh CHANGED
@@ -20,8 +20,8 @@ Xvfb "$DISPLAY" -screen 0 1280x720x24 -ac +extension GLX +render -noreset &
20
  XVFB_PID=$!
21
  sleep 2
22
 
23
- # Start dbus for session (user session only; no system dbus as we run as non-root)
24
- dbus-daemon --session
25
 
26
  # Start XFCE (lightweight)
27
  startxfce4 &
@@ -31,10 +31,5 @@ sleep 3
31
  # x11vnc: share display :99 on port 5901
32
  x11vnc -display "$DISPLAY" -rfbport "$VNC_PORT" -forever -shared -noxdamage -bg
33
 
34
- # noVNC: web on 7860, proxy to VNC
35
- if [ -x /opt/noVNC/utils/novnc_proxy ]; then
36
- /opt/noVNC/utils/novnc_proxy --listen "$NOVNC_PORT" --vnc "localhost:$VNC_PORT"
37
- else
38
- # Fallback: websockify + simple http serve
39
- (cd /opt/noVNC && ./utils/novnc_proxy --listen "$NOVNC_PORT" --vnc "localhost:$VNC_PORT")
40
- fi
 
20
  XVFB_PID=$!
21
  sleep 2
22
 
23
+ # Start dbus for session (optional; avoid exit on failure so noVNC can still serve)
24
+ dbus-daemon --session 2>/dev/null || true
25
 
26
  # Start XFCE (lightweight)
27
  startxfce4 &
 
31
  # x11vnc: share display :99 on port 5901
32
  x11vnc -display "$DISPLAY" -rfbport "$VNC_PORT" -forever -shared -noxdamage -bg
33
 
34
+ # noVNC: must run in foreground so container stays alive; serve web from /opt/noVNC
35
+ exec /bin/bash -c "cd /opt/noVNC && exec ./utils/novnc_proxy --listen $NOVNC_PORT --vnc localhost:$VNC_PORT --web /opt/noVNC"