Spaces:
Sleeping
Sleeping
docs: Ubuntu desktop --expect Directory listing, /vnc.html
Browse files- docs/PUSH_DEBUG.md +49 -15
docs/PUSH_DEBUG.md
CHANGED
|
@@ -21,7 +21,15 @@ HF 开始构建/部署
|
|
| 21 |
|
| 22 |
---
|
| 23 |
|
| 24 |
-
## 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
### 2.1 推送(触发部署)
|
| 27 |
|
|
@@ -33,19 +41,45 @@ git push origin main
|
|
| 33 |
|
| 34 |
(若 Space 在别的分支,把 `main` 换成该分支。)
|
| 35 |
|
| 36 |
-
### 2.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
```bash
|
| 39 |
-
#
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
|
|
|
| 44 |
```
|
| 45 |
|
| 46 |
-
`--
|
| 47 |
|
| 48 |
-
### 2.
|
| 49 |
|
| 50 |
**方式 A:有 HF_TOKEN 时**(推荐,可看 API 状态)
|
| 51 |
|
|
@@ -53,10 +87,10 @@ HF_TOKEN=你的token python3 scripts/monitor_and_test.py --space-id 你的用户
|
|
| 53 |
# Demo 或默认 Space
|
| 54 |
HF_TOKEN=你的token python3 scripts/monitor_and_test.py --wait-running --test
|
| 55 |
|
| 56 |
-
# Ubuntu 桌面等:
|
| 57 |
HF_TOKEN=你的token python3 scripts/monitor_and_test.py --wait-running --test \
|
| 58 |
--url https://你的用户名-你的Space名.hf.space \
|
| 59 |
-
--expect
|
| 60 |
```
|
| 61 |
|
| 62 |
**方式 B:无 HF_TOKEN 时**(只轮询 URL 直到页面出现期望内容)
|
|
@@ -64,17 +98,17 @@ HF_TOKEN=你的token python3 scripts/monitor_and_test.py --wait-running --test \
|
|
| 64 |
```bash
|
| 65 |
python3 scripts/monitor_and_test.py --wait-url --test \
|
| 66 |
--url https://你的用户名-你的Space名.hf.space \
|
| 67 |
-
--expect
|
| 68 |
```
|
| 69 |
|
| 70 |
-
脚本会先轮询直到 GET 200 且 body 含 `
|
| 71 |
|
| 72 |
-
### 2.
|
| 73 |
|
| 74 |
```bash
|
| 75 |
python3 scripts/monitor_and_test.py --test
|
| 76 |
# 或
|
| 77 |
-
python3 scripts/monitor_and_test.py --url https://xxx.hf.space --test --expect
|
| 78 |
```
|
| 79 |
|
| 80 |
---
|
|
@@ -88,7 +122,7 @@ python3 scripts/monitor_and_test.py --url https://xxx.hf.space --test --expect n
|
|
| 88 |
|
| 89 |
2. **构建完成后**:另一个终端等 RUNNING 并跑测试。
|
| 90 |
```bash
|
| 91 |
-
HF_TOKEN=xxx python3 scripts/monitor_and_test.py --
|
| 92 |
```
|
| 93 |
|
| 94 |
3. 若 **测试失败或一直 503**:用 `--logs run`(以及 `--logs build`)看容器内报错,修代码后:
|
|
|
|
| 21 |
|
| 22 |
---
|
| 23 |
|
| 24 |
+
## 2. 轮询方式(正确做法)
|
| 25 |
+
|
| 26 |
+
用 **HF API** 看远端状态和日志,不要只轮询应用 URL:
|
| 27 |
+
|
| 28 |
+
- **Runtime 状态**:`get_space_runtime`(脚本里 `--wait-running` / `--until-ok` 会轮询)。
|
| 29 |
+
- **构建日志**:`GET .../spaces/<SPACE_ID>/logs/build`(需 `Authorization: Bearer $HF_TOKEN`)。
|
| 30 |
+
- **运行日志**:`GET .../spaces/<SPACE_ID>/logs/run`(同上)。
|
| 31 |
+
|
| 32 |
+
一轮流程:push → 用 API 等 RUNNING(或看 build 失败)→ 跑测试 → 失败则看 run/build 日志尾修代码 → 再 push,循环直到测试全过。
|
| 33 |
|
| 34 |
### 2.1 推送(触发部署)
|
| 35 |
|
|
|
|
| 41 |
|
| 42 |
(若 Space 在别的分支,把 `main` 换成该分支。)
|
| 43 |
|
| 44 |
+
### 2.2 持续看远端状态(不退出)
|
| 45 |
+
|
| 46 |
+
用 curl + Bearer token 周期性拉 run 日志并查应用 URL,适合观察部署过程:
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
# 从 .env 读 HF_TOKEN 时直接运行(脚本会自动加载 .env)
|
| 50 |
+
python3 scripts/monitor_and_test.py --watch
|
| 51 |
+
|
| 52 |
+
# 每 30 秒轮询一次
|
| 53 |
+
python3 scripts/monitor_and_test.py --watch --watch-interval 30
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
会循环打印:当前 stage、GET APP_URL 结果、run 日志尾部。Ctrl+C 结束。
|
| 57 |
+
|
| 58 |
+
### 2.3 用 API 看远端日志(debug 用)
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
# 流式拉取构建日志(推送后看)
|
| 62 |
+
HF_TOKEN=你的token python3 scripts/monitor_and_test.py --logs build
|
| 63 |
+
|
| 64 |
+
# 流式拉取运行日志(看容器输出)
|
| 65 |
+
HF_TOKEN=你的token python3 scripts/monitor_and_test.py --logs run
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
等价 curl(便于脚本里用):
|
| 69 |
|
| 70 |
```bash
|
| 71 |
+
# Get container logs (SSE)
|
| 72 |
+
curl -N -H "Authorization: Bearer $HF_TOKEN" \
|
| 73 |
+
"https://huggingface.co/api/spaces/tao-shen/HuggingRun/logs/run"
|
| 74 |
|
| 75 |
+
# Get build logs (SSE)
|
| 76 |
+
curl -N -H "Authorization: Bearer $HF_TOKEN" \
|
| 77 |
+
"https://huggingface.co/api/spaces/tao-shen/HuggingRun/logs/build"
|
| 78 |
```
|
| 79 |
|
| 80 |
+
`--until-ok` 在 build/run 或测试失败时会自动拉取并打印日志尾部,无需单独跑上面命令。
|
| 81 |
|
| 82 |
+
### 2.4 等 RUNNING / 等 URL 就绪后跑完整测试(一键「远端是否成功」)
|
| 83 |
|
| 84 |
**方式 A:有 HF_TOKEN 时**(推荐,可看 API 状态)
|
| 85 |
|
|
|
|
| 87 |
# Demo 或默认 Space
|
| 88 |
HF_TOKEN=你的token python3 scripts/monitor_and_test.py --wait-running --test
|
| 89 |
|
| 90 |
+
# Ubuntu 桌面等:根路径返回 noVNC 目录列表,用 Directory listing;桌面在 /vnc.html
|
| 91 |
HF_TOKEN=你的token python3 scripts/monitor_and_test.py --wait-running --test \
|
| 92 |
--url https://你的用户名-你的Space名.hf.space \
|
| 93 |
+
--expect "Directory listing"
|
| 94 |
```
|
| 95 |
|
| 96 |
**方式 B:无 HF_TOKEN 时**(只轮询 URL 直到页面出现期望内容)
|
|
|
|
| 98 |
```bash
|
| 99 |
python3 scripts/monitor_and_test.py --wait-url --test \
|
| 100 |
--url https://你的用户名-你的Space名.hf.space \
|
| 101 |
+
--expect "Directory listing" --max-wait 900
|
| 102 |
```
|
| 103 |
|
| 104 |
+
脚本会先轮询直到 GET 200 且 body 含你给的 `--expect`(Ubuntu 桌面根路径返回目录列表,用 `--expect "Directory listing"`;桌面客户端在 `/vnc.html`),再跑:基础 GET、压力请求、多轮持久化检查。**全部通过才 exit 0**,任一失败则 exit 1。
|
| 105 |
|
| 106 |
+
### 2.5 不等待、直接测当前页面(Space 已 RUNNING 时)
|
| 107 |
|
| 108 |
```bash
|
| 109 |
python3 scripts/monitor_and_test.py --test
|
| 110 |
# 或
|
| 111 |
+
python3 scripts/monitor_and_test.py --url https://xxx.hf.space --test --expect "Directory listing"
|
| 112 |
```
|
| 113 |
|
| 114 |
---
|
|
|
|
| 122 |
|
| 123 |
2. **构建完成后**:另一个终端等 RUNNING 并跑测试。
|
| 124 |
```bash
|
| 125 |
+
HF_TOKEN=xxx python3 scripts/monitor_and_test.py --until-ok --url https://tao-shen-huggingrun.hf.space --expect "Directory listing"
|
| 126 |
```
|
| 127 |
|
| 128 |
3. 若 **测试失败或一直 503**:用 `--logs run`(以及 `--logs build`)看容器内报错,修代码后:
|