@stardustlc/dsh-docker 0.5.6 → 0.5.8
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/CHANGELOG.md +12 -0
- package/README.en.md +35 -24
- package/README.md +33 -23
- package/docs/REFERENCE.en.md +61 -0
- package/docs/REFERENCE.zh.md +61 -0
- package/docs/USAGE.en.md +14 -0
- package/docs/USAGE.md +14 -0
- package/docs/assets/intro/workflow-en-dark.svg +1 -0
- package/docs/assets/intro/workflow-en-light.svg +1 -0
- package/docs/assets/intro/workflow-en-mobile-dark.svg +1 -0
- package/docs/assets/intro/workflow-en-mobile-light.svg +1 -0
- package/docs/assets/intro/workflow-zh-dark.svg +1 -0
- package/docs/assets/intro/workflow-zh-light.svg +1 -0
- package/docs/assets/intro/workflow-zh-mobile-dark.svg +1 -0
- package/docs/assets/intro/workflow-zh-mobile-light.svg +1 -0
- package/lib/tools.d.ts +8 -0
- package/lib/tools.js +60 -5
- package/lib/update-client.js +1 -1
- package/package.json +3 -3
package/lib/tools.js
CHANGED
|
@@ -44,13 +44,40 @@ function executionSignal(exec) {
|
|
|
44
44
|
const signal = exec.signal;
|
|
45
45
|
return signal instanceof AbortSignal ? signal : undefined;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* 把 docker 的原始 stderr 映射成一行可执行的「下一步」。
|
|
49
|
+
*
|
|
50
|
+
* 原来非零退出只提示「请确认 docker 可用(docker version)」,守护进程没起、
|
|
51
|
+
* 权限不足、容器名写错、端口冲突看起来都一样,用户只能反复试。原始输出保留,
|
|
52
|
+
* 这里只追加一条最可能的原因与动作。
|
|
53
|
+
*/
|
|
54
|
+
export function dockerErrorHint(text) {
|
|
55
|
+
if (/Cannot connect to the Docker daemon|Is the docker daemon running|docker\.sock: connect|open .*docker\.sock/i.test(text))
|
|
56
|
+
return '守护进程不可达:请启动 Docker Desktop / dockerd(Windows 需 WSL2 或 Hyper-V 后端),再运行 docker_health 复查。';
|
|
57
|
+
if (/permission denied/i.test(text))
|
|
58
|
+
return '权限不足:Linux/macOS 把用户加入 docker 组并重新登录,Windows 以管理员身份启动 Docker Desktop 后重试。';
|
|
59
|
+
if (/command not found|not recognized as the name|ENOENT|no such file or directory/i.test(text))
|
|
60
|
+
return '找不到 docker 命令:请安装 Docker CLI,或在插件配置里用 dockerPath 指定完整可执行文件路径。';
|
|
61
|
+
if (/[Nn]o such container/i.test(text))
|
|
62
|
+
return '容器不存在:用 docker_ps all=true 查真实容器名或 ID(注意大小写),再重试。';
|
|
63
|
+
if (/[Nn]o such image/i.test(text))
|
|
64
|
+
return '镜像不存在:用 docker_images 查看本地镜像,或先 docker pull 该镜像。';
|
|
65
|
+
if (/context deadline exceeded|i\/o timeout|timed out|timeout/i.test(text))
|
|
66
|
+
return '命令超时:确认目标机器与容器状态,必要时调大插件配置里的 timeoutMs 后重试。';
|
|
67
|
+
if (/port is already allocated|address already in use/i.test(text))
|
|
68
|
+
return '端口已被占用:先用 docker_ps 找到占用端口的容器并停止,或改用其它端口。';
|
|
69
|
+
if (/Conflict\. The container name/i.test(text))
|
|
70
|
+
return '容器名冲突:已有同名容器,请改名,或用 docker_ps 找到现有容器先停掉/删除。';
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
47
73
|
async function runChecked(runner, argv, timeoutMs, label, signal) {
|
|
48
74
|
signal?.throwIfAborted();
|
|
49
75
|
const result = await runner.run(argv, { timeoutMs, ...(signal === undefined ? {} : { signal }) });
|
|
50
76
|
signal?.throwIfAborted();
|
|
51
77
|
if (result.exitCode !== 0) {
|
|
52
78
|
const tail = result.stderr.trim().split(/\r?\n/).slice(-6).join(' | ');
|
|
53
|
-
|
|
79
|
+
const next = dockerErrorHint(result.stderr) ?? '请确认 docker 可用(docker version)。';
|
|
80
|
+
throw new Error(label + '失败(退出码 ' + String(result.exitCode ?? 'null') + '):' + (tail || '无错误输出') + '。' + next);
|
|
54
81
|
}
|
|
55
82
|
return result;
|
|
56
83
|
}
|
|
@@ -105,10 +132,17 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
|
|
|
105
132
|
render: (_args, value) => {
|
|
106
133
|
const rec = asRecord(value);
|
|
107
134
|
const containers = Array.isArray(rec.containers) ? rec.containers : [];
|
|
135
|
+
if (containers.length === 0) {
|
|
136
|
+
const onlyRunning = rec.all !== true;
|
|
137
|
+
return [{ type: 'text', text: onlyRunning
|
|
138
|
+
? '没有正在运行的容器。下一步:用 docker_ps all=true 查看已停止的容器;确认 Docker 已启动的话也可以运行 docker_health。'
|
|
139
|
+
: '没有任何容器(含已停止)。下一步:用 docker_images 确认镜像是否已拉到本地,或用 docker_health 检查守护进程。' }];
|
|
140
|
+
}
|
|
108
141
|
const lines = ['共 ' + containers.length + ' 个容器:'];
|
|
109
142
|
for (const item of containers) {
|
|
110
143
|
const c = asRecord(item);
|
|
111
|
-
|
|
144
|
+
const detail = typeof c.status === 'string' && c.status !== '' ? c.status : c.state;
|
|
145
|
+
lines.push('- ' + c.name + '(' + c.image + ',' + detail + ')');
|
|
112
146
|
}
|
|
113
147
|
return [{ type: 'text', text: lines.join('\n') }];
|
|
114
148
|
},
|
|
@@ -134,7 +168,11 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
|
|
|
134
168
|
schema: logsSchema,
|
|
135
169
|
render: (_args, value) => {
|
|
136
170
|
const rec = asRecord(value);
|
|
137
|
-
|
|
171
|
+
const text = typeof rec.text === 'string' ? rec.text : '';
|
|
172
|
+
if (text.trim() === '') {
|
|
173
|
+
return [{ type: 'text', text: '容器 ' + rec.container + ' 最近 ' + String(rec.tail ?? '') + ' 行日志为空:进程可能还没输出、日志驱动不是 json-file,或该时间段内没有写入。下一步:用 docker_inspect 看状态与启动时间,或调大 tail 再取一次。' }];
|
|
174
|
+
}
|
|
175
|
+
return [{ type: 'text', text: '容器 ' + rec.container + ' 最近日志:\n' + text }];
|
|
138
176
|
},
|
|
139
177
|
},
|
|
140
178
|
async execute(rawArgs, exec) {
|
|
@@ -187,7 +225,10 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
|
|
|
187
225
|
render: (_args, value) => {
|
|
188
226
|
const rec = asRecord(value);
|
|
189
227
|
const info = asRecord(rec.info);
|
|
190
|
-
|
|
228
|
+
const ports = Array.isArray(info.ports) && info.ports.length > 0 ? info.ports.join(', ') : '无端口映射';
|
|
229
|
+
const started = typeof info.startedAt === 'string' && info.startedAt !== '' ? ',启动于 ' + info.startedAt : '';
|
|
230
|
+
const state = typeof info.state === 'string' && info.state !== '' ? info.state : (info.running === true ? 'running' : 'exited');
|
|
231
|
+
return [{ type: 'text', text: '容器 ' + info.name + '(' + info.image + '):' + state + started + ',端口:' + ports + '。下一步:docker_logs 看日志,docker_exec 进容器排查。' }];
|
|
191
232
|
},
|
|
192
233
|
},
|
|
193
234
|
async execute(rawArgs, exec) {
|
|
@@ -237,7 +278,8 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
|
|
|
237
278
|
schema: manageSchema,
|
|
238
279
|
render: (_args, value) => {
|
|
239
280
|
const rec = asRecord(value);
|
|
240
|
-
|
|
281
|
+
const output = typeof rec.output === 'string' && rec.output.trim() !== '' ? '\n' + rec.output : '';
|
|
282
|
+
return [{ type: 'text', text: '容器 ' + rec.container + ' 已执行 ' + rec.action + '。下一步:用 docker_ps 确认当前状态。' + output }];
|
|
241
283
|
},
|
|
242
284
|
},
|
|
243
285
|
async execute(rawArgs, exec) {
|
|
@@ -261,9 +303,21 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
|
|
|
261
303
|
const rec = asRecord(value);
|
|
262
304
|
const checks = Array.isArray(rec.checks) ? rec.checks : [];
|
|
263
305
|
const lines = ['dsh-docker 自检' + (rec.ok === true ? ':正常。' : ':发现问题。')];
|
|
306
|
+
const failed = [];
|
|
264
307
|
for (const item of checks) {
|
|
265
308
|
const c = asRecord(item);
|
|
266
309
|
lines.push('- ' + c.name + ':' + (c.ok === true ? '✅ ' : '❌ ') + String(c.detail ?? ''));
|
|
310
|
+
if (c.ok !== true)
|
|
311
|
+
failed.push(String(c.name));
|
|
312
|
+
}
|
|
313
|
+
if (failed.length > 0) {
|
|
314
|
+
lines.push('', '下一步:');
|
|
315
|
+
if (failed.includes('docker daemon'))
|
|
316
|
+
lines.push(' · 启动 Docker Desktop / dockerd 后重新运行 docker_health;命令找不到时在插件配置里用 dockerPath 指定完整路径。');
|
|
317
|
+
if (failed.some(name => name.includes('审批门')))
|
|
318
|
+
lines.push(' · 审批门不可用时,把会话审批策略切到可询问(ask),或由用户明确设置 execApproval / manageApproval = false(之后不再询问,慎用)。');
|
|
319
|
+
if (!failed.some(name => name.includes('审批门')) && !failed.includes('docker daemon'))
|
|
320
|
+
lines.push(' · 按上面 ❌ 项的说明处理后重新运行 docker_health 复查。');
|
|
267
321
|
}
|
|
268
322
|
return [{ type: 'text', text: lines.join('\n') }];
|
|
269
323
|
},
|
|
@@ -285,6 +339,7 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
|
|
|
285
339
|
checks.push({ name: 'exec 审批门', ...dockerApprovalCheck(cfg.execApproval, policy, 'execApproval') });
|
|
286
340
|
checks.push({ name: 'manage 审批门', ...dockerApprovalCheck(cfg.manageApproval, policy, 'manageApproval') });
|
|
287
341
|
checks.push({ name: '超时配置', ok: true, detail: 'timeoutMs=' + cfg.timeoutMs + ', graceMs=' + cfg.graceMs });
|
|
342
|
+
checks.push({ name: 'docker 命令', ok: true, detail: cfg.dockerPath + '(可用 dockerPath 配置覆盖)' });
|
|
288
343
|
return { ok: ok && checks.every(check => check.ok === true), plugin: 'dsh-docker', approvalPolicy: policy, checks };
|
|
289
344
|
},
|
|
290
345
|
timeoutMs: 20000,
|
package/lib/update-client.js
CHANGED
|
@@ -437,7 +437,7 @@ function __stardustUpdatesClient(ctx, React, require, shared) {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
/* STARDUSTLC_UPDATE_CLIENT_BODY_START */
|
|
440
|
-
window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"@stardustlc/dsh-docker",factory:require=>({apply(){}})},{"name":"@stardustlc/dsh-docker","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.5.
|
|
440
|
+
window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"@stardustlc/dsh-docker",factory:require=>({apply(){}})},{"name":"@stardustlc/dsh-docker","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.5.8","label":"Docker","labelEn":"Docker","suiteComponent":true}));
|
|
441
441
|
|
|
442
442
|
/* STARDUSTLC_UPDATE_CLIENT_BODY_END */
|
|
443
443
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stardustlc/dsh-docker",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "DSH Docker 工具:容器与镜像管理、日志、状态检查及操作确认;清楚报告权限原因。欢迎提交 issues 和 PR。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsc -p tsconfig.json && node scripts/build-updates.mjs",
|
|
28
28
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
29
|
-
"test": "
|
|
30
|
-
"prepublishOnly": "
|
|
29
|
+
"test": "npm run build && node --test \"test/*.test.mjs\"",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
31
|
},
|
|
32
32
|
"dsh": {
|
|
33
33
|
"bundle": {
|