dotop-gpu-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -2
- package/bin/dotop-gpu.mjs +597 -0
- package/package.json +33 -4
- package/src/api.mjs +214 -0
- package/src/config.mjs +91 -0
- package/src/prompts.mjs +529 -0
- package/src/render.mjs +185 -0
- package/src/rentargs.mjs +232 -0
- package/src/rentflow.mjs +186 -0
- package/src/sshkeys.mjs +69 -0
- package/src/wizard.mjs +1056 -0
package/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dotop-gpu-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
用命令行通过 **GPU 开放接口**租 GPU 服务器。交互式向导,一条命令走完「选公钥 → 选可用区 → 选规格 → 选镜像 → 选计费 → 报价 → 下单 → 等就绪 → 拿到 SSH 命令」。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx dotop-gpu-cli
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g dotop-gpu-cli # 全局装,之后直接用 dotop-gpu
|
|
13
|
+
npx dotop-gpu-cli # 或者不装,用 npx 跑(等价于 dotop-gpu)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
要求 Node.js >= 20。**零运行期依赖**,不下载任何第三方包。
|
|
17
|
+
|
|
18
|
+
## 先准备三样东西
|
|
19
|
+
|
|
20
|
+
1. **服务地址**:GPU 平台的地址,例如 `https://gpu.example.com`。
|
|
21
|
+
2. **API Key**:在平台侧创建的 GPU API Key,形如 `gk_xxxxxxxx_xx_xxxxxxxx`。
|
|
22
|
+
第一次运行时向导会提示粘贴,之后存在本地。
|
|
23
|
+
3. **SSH 公钥**:必须在平台上已经上传过。向导里可以从本机 `~/.ssh/*.pub` 上传、
|
|
24
|
+
手动粘贴一行公钥,或直接选已有的。
|
|
25
|
+
**开放接口不接受密码登录,也不允许新建租约时临时生成密钥**,所以没有公钥就下不了单。
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# 交互式向导(最常用)
|
|
31
|
+
dotop-gpu
|
|
32
|
+
|
|
33
|
+
# 用默认配置快速下单:第一个有货的可用区 / 第一个有货的规格 / 第一个镜像 / 第一把公钥
|
|
34
|
+
dotop-gpu rent --quick
|
|
35
|
+
|
|
36
|
+
# 看自己有哪些租约 / 看某台的详情
|
|
37
|
+
dotop-gpu list
|
|
38
|
+
dotop-gpu show 377
|
|
39
|
+
|
|
40
|
+
# 管理 SSH 公钥
|
|
41
|
+
dotop-gpu keys
|
|
42
|
+
dotop-gpu keys add # 从 ~/.ssh 选一把公钥上传(会先显示指纹让你确认)
|
|
43
|
+
dotop-gpu keys rm 7
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 全部命令
|
|
47
|
+
|
|
48
|
+
| 命令 | 说明 |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `dotop-gpu` | 交互式向导,下单到拿到 SSH 命令 |
|
|
51
|
+
| `dotop-gpu rent` | 同上;也可带参数一次填完,见 `dotop-gpu rent --help` |
|
|
52
|
+
| `dotop-gpu rent --quick` | 用默认配置直接下单 |
|
|
53
|
+
| `dotop-gpu list [--all]` | 我的租约(默认只列未销毁的) |
|
|
54
|
+
| `dotop-gpu show <id>` | 租约详情 + 就绪状态 + SSH 命令 |
|
|
55
|
+
| `dotop-gpu stop <id>` | 关机(保留数据盘,停止计费) |
|
|
56
|
+
| `dotop-gpu start <id>` | 开机 |
|
|
57
|
+
| `dotop-gpu reboot <id>` | 重启 |
|
|
58
|
+
| `dotop-gpu destroy <id>` | 销毁(不可恢复,需要二次确认) |
|
|
59
|
+
| `dotop-gpu keys [add\|rm <id>]` | 列出 / 上传 / 删除 SSH 公钥(向导里也能删) |
|
|
60
|
+
| `dotop-gpu login` | 重新设置 API Key 与服务地址 |
|
|
61
|
+
| `dotop-gpu whoami` | 检查连通性与 Key 是否有效 |
|
|
62
|
+
| `dotop-gpu --version` | 显示版本号(也可用 `-v` 或 `version`) |
|
|
63
|
+
|
|
64
|
+
`rent` 的完整参数(`--zone` / `--plan` / `--image` / `--ssh-key` / `--billing` / `--count` /
|
|
65
|
+
`--dry-run` / `--yes` / `--no-wait` / `--idem` 等)用 `dotop-gpu rent --help` 查看。
|
|
66
|
+
|
|
67
|
+
## 配置
|
|
68
|
+
|
|
69
|
+
优先级:**命令行参数 > 环境变量 > 配置文件**。
|
|
70
|
+
|
|
71
|
+
| 项 | 命令行 | 环境变量 | 默认值 |
|
|
72
|
+
|---|---|---|---|
|
|
73
|
+
| 服务地址 | `--base-url <url>` | `DOTOP_GPU_BASE_URL` | `http://127.0.0.1:8080` |
|
|
74
|
+
| API Key | `--api-key <key>` | `DOTOP_GPU_API_KEY` | 首次运行时输入并保存 |
|
|
75
|
+
|
|
76
|
+
配置文件位于 `~/.config/dotop-gpu/config.json`(Linux/macOS)或
|
|
77
|
+
`%USERPROFILE%\.config\dotop-gpu\config.json`(Windows),写入时权限设为 `600`。
|
|
78
|
+
可以用 `DOTOP_GPU_CONFIG` 指定别的路径。
|
|
79
|
+
|
|
80
|
+
CI 里推荐只用环境变量,不要落盘。
|
|
81
|
+
|
|
82
|
+
Linux / macOS:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
export DOTOP_GPU_BASE_URL=https://gpu.example.com
|
|
86
|
+
export DOTOP_GPU_API_KEY=gk_xxxxxxxx_xx_xxxxxxxx
|
|
87
|
+
dotop-gpu
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Windows PowerShell:
|
|
91
|
+
|
|
92
|
+
```powershell
|
|
93
|
+
$env:DOTOP_GPU_BASE_URL="https://gpu.example.com"
|
|
94
|
+
$env:DOTOP_GPU_API_KEY="gk_xxxxxxxx_xx_xxxxxxxx"
|
|
95
|
+
dotop-gpu
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Windows 命令提示符(cmd):
|
|
99
|
+
|
|
100
|
+
```bat
|
|
101
|
+
set DOTOP_GPU_BASE_URL=https://gpu.example.com
|
|
102
|
+
set DOTOP_GPU_API_KEY=gk_xxxxxxxx_xx_xxxxxxxx
|
|
103
|
+
dotop-gpu
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> PowerShell 的 `$env:X="..."` 只在当前窗口有效,关掉就没了 —— CI 里正是想要这个效果。
|
|
107
|
+
> 想永久生效用 `setx`,但那样 Key 会落进注册表,不建议。
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
> **非交互(管道)运行注意**:确认页不接受回车当确认,必须显式输入序号(`1` 表示确认下单)。
|
|
111
|
+
> 输入提前结束时一律按「取消」处理。要脚本化下单请显式用 `dotop-gpu rent --quick`。
|
|
112
|
+
|
|
113
|
+
### 建机进度
|
|
114
|
+
|
|
115
|
+
下单后每 3 秒查询一次进度,最多等 10 分钟。判定跟平台一致:
|
|
116
|
+
|
|
117
|
+
| 状态 | 含义 | 动作 |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `provisioning` | 正在分配机器 | 继续等 |
|
|
120
|
+
| `running` + `booting` | 机器起来了,系统还在启动 | 继续等 |
|
|
121
|
+
| `running` + `ready` | 可以登录了 | 结束,打印 SSH |
|
|
122
|
+
| `running` + `timeout` | 启动超时 | 判失败 |
|
|
123
|
+
| `failed` / `destroyed` | 建机失败 / 已销毁 | 判失败 |
|
|
124
|
+
|
|
125
|
+
## 关于 SSH 命令
|
|
126
|
+
|
|
127
|
+
`ssh.command` 是**平台下发的完整命令**(包含正确的跳板端口和登录名),
|
|
128
|
+
直接复制执行即可。不要自己拼 `ssh root@<ip>` —— 走公网 IP 和走跳板机的端口、用户名都不同。
|
|
129
|
+
|
|
130
|
+
## 常见错误
|
|
131
|
+
|
|
132
|
+
| 返回 | 意思 | 怎么办 |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| 401 `unauthorized` | Key 无效 / 缺 `Bearer ` 前缀 | `dotop-gpu login` 重设 |
|
|
135
|
+
| 400 `insufficient_balance` | 余额不够覆盖最短计费时长 | 先充值 |
|
|
136
|
+
| 409 `insufficient_stock` | 该型号已被占满 | 换型号,或等别人释放 |
|
|
137
|
+
| 404 `not_found`(下单时) | 所选公钥不存在或不属于当前账号 | `dotop-gpu keys` 重新上传 |
|
|
138
|
+
| 400 `invalid_argument`(billing_mode) | 计费方式拼错 | 用 `on-demand`/`daily`/`weekly`/`monthly`/`yearly` |
|
|
139
|
+
| 409 `conflict`(destroy) | 周期租约还没到期 | 先 `stop`,到期后再 `destroy` |
|
|
140
|
+
|
|
141
|
+
## 数据与隐私
|
|
142
|
+
|
|
143
|
+
- 只保存 API Key 和服务地址,不保存任何租约内容。
|
|
144
|
+
- 上传公钥时只读 `~/.ssh/*.pub`,**不会读私钥,也不会把私钥发到任何地方**。
|
|
145
|
+
- 不做任何埋点、不连第三方服务,所有请求只发往你自己配置的服务地址。
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT
|