dsh-plugin-container-windows 0.0.0-stage → 0.5.1
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/LICENSE +21 -0
- package/README.md +109 -2
- package/README.zh-CN.md +110 -0
- package/cordis.patch.yml +3 -0
- package/docs/ai-chat.png +0 -0
- package/docs/ai-new-session.png +0 -0
- package/docs/apple-container.png +0 -0
- package/docs/attach.png +0 -0
- package/docs/docker-console.png +0 -0
- package/docs/docker-overview.png +0 -0
- package/docs/docker-volumes.png +0 -0
- package/docs/image-architecture.png +0 -0
- package/docs/package-install.png +0 -0
- package/docs/provider-switch.png +0 -0
- package/docs/run-container.png +0 -0
- package/index.js +141 -0
- package/lib/client.js +4092 -0
- package/package.json +72 -4
- package/src/client/api.js +98 -0
- package/src/client/attach.jsx +134 -0
- package/src/client/build-image.jsx +224 -0
- package/src/client/components.jsx +325 -0
- package/src/client/hooks.js +161 -0
- package/src/client/i18n.js +602 -0
- package/src/client/icons.jsx +239 -0
- package/src/client/index.jsx +90 -0
- package/src/client/page.jsx +854 -0
- package/src/client/platforms.js +2 -0
- package/src/client/push-image.jsx +113 -0
- package/src/client/run-container.jsx +187 -0
- package/src/client/runs.js +182 -0
- package/src/client/store.js +91 -0
- package/src/client/styles.js +383 -0
- package/src/client/tabs/compose.jsx +94 -0
- package/src/client/tabs/console.jsx +211 -0
- package/src/client/tabs/containers.jsx +148 -0
- package/src/client/tabs/images.jsx +154 -0
- package/src/client/tabs/networks.jsx +91 -0
- package/src/client/tabs/overview.jsx +266 -0
- package/src/client/tabs/volumes.jsx +76 -0
- package/src/host/apple-cli.js +319 -0
- package/src/host/apple.js +495 -0
- package/src/host/attach.js +246 -0
- package/src/host/commands.js +241 -0
- package/src/host/docker-cli.js +468 -0
- package/src/host/images.js +143 -0
- package/src/host/jobs.js +245 -0
- package/src/host/parsers.js +484 -0
- package/src/host/runtime.js +379 -0
- package/src/host/service.js +892 -0
- package/src/host/tools.js +198 -0
- package/src/host/util.js +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-plugin-container contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# DSH Container
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A DSH sidebar panel for managing containers on Windows and macOS: Docker (Docker Desktop / colima / OrbStack / remote contexts), plus Apple `container` on macOS.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Two providers, Docker and Apple container, with runtime status and context switching
|
|
12
|
+
- Containers, images, volumes, networks, Compose, and commands
|
|
13
|
+
- Start / stop / restart / delete containers; pull / push / build / inspect / delete images
|
|
14
|
+
- **Pull** with an optional architecture (`linux/amd64` / `linux/arm64`); a pasted `docker pull nginx` works too
|
|
15
|
+
- **Build** an image from a project folder chosen with a folder picker: the form checks the folder, finds Dockerfiles, suggests a tag, and previews the command
|
|
16
|
+
- **Push** an image: pick a target such as `username/app:tag` or `ghcr.io/username/app:tag`; it is tagged first when the name differs, with login hints and a clear message when the registry rejects the push
|
|
17
|
+
- Logs, inspect, and live follow
|
|
18
|
+
- **Attach**: `docker attach` for Docker; `container exec` for Apple
|
|
19
|
+
- **Exec**: open a shell inside a container (`docker exec -it <id> /bin/sh`)
|
|
20
|
+
- Image architecture column (arm64/amd64)
|
|
21
|
+
- Read-only AI tools: `container_status`, `container_list`, `container_inspect`, `container_logs`
|
|
22
|
+
- AI diagnosis opens a separate session and leaves the current conversation untouched
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
- Windows 10/11 or macOS
|
|
27
|
+
- DSH 0.2.x
|
|
28
|
+
- Docker CLI, or [Apple container](https://github.com/apple/container)
|
|
29
|
+
- Configure any network proxy for your own environment
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
GitHub: https://github.com/my-dream0414/dsh-plugin-container-windows
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
dsh plugin --profile desktop add dsh-plugin-container-windows
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Restart DSH. The installer writes `dsh.profile.bundles` for you, so **you do not need to edit `cordis.patch.yml` by hand**.
|
|
40
|
+
|
|
41
|
+
Local development build:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
node scripts/install-profile.mjs --home "$HOME/.dsh" --profile desktop
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Do not enable source-path mode and npm-package mode at the same time.
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
1. Open **Containers** in the left sidebar
|
|
52
|
+
2. Switch between Docker and Apple container at the top
|
|
53
|
+
3. Container row actions:
|
|
54
|
+
- Start / stop / restart / delete
|
|
55
|
+
- Logs / Follow / Inspect
|
|
56
|
+
- Attach: take over the container's main process
|
|
57
|
+
- Exec: open a new shell inside the container
|
|
58
|
+
- Ask AI / Diagnose: starts a separate DSH session that calls the read-only container tools
|
|
59
|
+
4. The Images tab shows architecture and can start a container directly from an image
|
|
60
|
+
|
|
61
|
+
## Security
|
|
62
|
+
|
|
63
|
+
- All Docker/Apple commands run with the current user's permissions
|
|
64
|
+
- No shell string concatenation; commands are split into argv and spawned directly
|
|
65
|
+
- Dangerous actions such as delete, stop, and prune require confirmation
|
|
66
|
+
- AI tools are read-only; there are no start/stop/rm/prune tools
|
|
67
|
+
- Logs and inspect output are marked as untrusted data and are never executed as instructions
|
|
68
|
+
|
|
69
|
+
## Release
|
|
70
|
+
|
|
71
|
+
Releases are published by GitHub Actions. The npm token is stored in the repository secrets:
|
|
72
|
+
|
|
73
|
+
1. GitHub repository → Settings → Secrets and variables → Actions
|
|
74
|
+
2. Create `NPM_TOKEN` with an npm Granular Access Token (Bypass 2FA, Read and write)
|
|
75
|
+
3. Bump the version and tag:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm version patch
|
|
79
|
+
git push --follow-tags
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The `Release` workflow checks that the tag matches the `package.json` version, then runs:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm publish --access public --provenance
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install
|
|
92
|
+
npm run build # src/client -> lib/client.js
|
|
93
|
+
npm test # 59 tests
|
|
94
|
+
npm pack # pre-release check
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
> `@deepseek-ai/dsh-tools` is provided by the host app. **Do not** add it to `dependencies` or `peerDependencies`. Otherwise installing the plugin puts an older copy in the profile's `node_modules`, which shadows the host's own version, leaves the `tools` service missing, and DSH fails to start. Keep it in `devDependencies` only.
|
|
98
|
+
|
|
99
|
+
Layout:
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
index.js Host entry
|
|
103
|
+
cordis.patch.yml Bundle install patch
|
|
104
|
+
src/host/service.js Provider routing + Docker
|
|
105
|
+
src/host/images.js Image push/build validation
|
|
106
|
+
src/host/apple.js Apple container
|
|
107
|
+
src/host/attach.js Attach/Exec PTY
|
|
108
|
+
src/host/tools.js Read-only agent tools
|
|
109
|
+
src/client/ Pages, tabs, i18n, styles
|
|
110
|
+
```
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# DSH 容器
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
DSH 左栏容器面板:管理 Windows / macOS 上的 Docker(Docker Desktop / colima / OrbStack / remote context);macOS 还支持 Apple `container`。
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- Docker / Apple container 双 provider,运行时状态、上下文切换
|
|
12
|
+
- 容器、镜像、卷、网络、Compose、命令
|
|
13
|
+
- 容器启动/停止/重启/删除,镜像 pull/push/build/inspect/delete
|
|
14
|
+
- **拉取镜像**:可选指定架构(`linux/amd64` / `linux/arm64`),也可以直接粘贴 `docker pull nginx` 整条命令
|
|
15
|
+
- **构建镜像**:用文件夹选择器选择项目目录,表单会实时检查目录、识别 Dockerfile、推荐镜像名,并预览将执行的命令
|
|
16
|
+
- **推送镜像**:选择目标名,如 `用户名/app:tag` 或 `ghcr.io/用户名/app:tag`;名字不同时会先打标签,带登录提示,被仓库拒绝时给出明确说明
|
|
17
|
+
- 查看日志、inspect、实时 follow
|
|
18
|
+
- **Attach**:Docker `docker attach`;Apple `container exec`
|
|
19
|
+
- **Exec**:进入容器内部 shell(`docker exec -it <id> /bin/sh`)
|
|
20
|
+
- 镜像架构列(arm64/amd64)
|
|
21
|
+
- 只读 AI 工具:`container_status`、`container_list`、`container_inspect`、`container_logs`
|
|
22
|
+
- AI 诊断会新建独立会话,不污染当前对话
|
|
23
|
+
|
|
24
|
+
## 要求
|
|
25
|
+
|
|
26
|
+
- Windows 10/11 或 macOS
|
|
27
|
+
- DSH 0.2.x
|
|
28
|
+
- Docker CLI;或安装 [Apple container](https://github.com/apple/container)
|
|
29
|
+
- 网络代理按本机环境配置
|
|
30
|
+
|
|
31
|
+
## 安装
|
|
32
|
+
|
|
33
|
+
GitHub: https://github.com/my-dream0414/dsh-plugin-container-windows
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
dsh plugin --profile desktop add dsh-plugin-container-windows
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
重启 DSH。安装器会自动写入 `dsh.profile.bundles`,**不需要手改 `cordis.patch.yml`**。
|
|
40
|
+
|
|
41
|
+
本地开发版:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
node scripts/install-profile.mjs --home "$HOME/.dsh" --profile desktop
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
源码路径模式与 npm 包模式不要同时启用。
|
|
48
|
+
|
|
49
|
+
## 使用
|
|
50
|
+
|
|
51
|
+
1. 左栏打开 **容器**
|
|
52
|
+
2. 顶部切换 Docker / Apple container
|
|
53
|
+
3. 容器行操作:
|
|
54
|
+
- 启动 / 停止 / 重启 / 删除
|
|
55
|
+
- 日志 / Follow / Inspect
|
|
56
|
+
- Attach:接管容器主进程
|
|
57
|
+
- Exec:在容器内开一个新 shell
|
|
58
|
+
- 问 AI / 诊断:新建独立 DSH 会话,调用只读容器工具
|
|
59
|
+
4. 镜像 tab 可查看架构,或直接用镜像启动容器
|
|
60
|
+
|
|
61
|
+
## 安全
|
|
62
|
+
|
|
63
|
+
- 所有 Docker/Apple 命令以当前用户权限执行
|
|
64
|
+
- 无 shell 拼接;命令拆成 argv 直接 spawn
|
|
65
|
+
- 删除、stop、prune 等危险操作需要确认
|
|
66
|
+
- AI 工具只读,不提供 start/stop/rm/prune tool
|
|
67
|
+
- 日志和 inspect 被标记为不可信数据,不能作为指令执行
|
|
68
|
+
|
|
69
|
+
## 发布
|
|
70
|
+
|
|
71
|
+
发布由 GitHub Actions 完成,npm token 放在仓库 Secrets:
|
|
72
|
+
|
|
73
|
+
1. GitHub 仓库 → Settings → Secrets and variables → Actions
|
|
74
|
+
2. 新建 `NPM_TOKEN`,值为 npm Granular Access Token(需要 Bypass 2FA、Read and write)
|
|
75
|
+
3. 更新版本并打 tag:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm version patch
|
|
79
|
+
git push --follow-tags
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`Release` workflow 会校验 tag 与 `package.json` 版本一致,然后执行:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm publish --access public --provenance
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 开发
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install
|
|
92
|
+
npm run build # src/client -> lib/client.js
|
|
93
|
+
npm test # 59 tests
|
|
94
|
+
npm pack # 发布前检查
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
> `@deepseek-ai/dsh-tools` 由宿主应用提供,**不要**加进 `dependencies` / `peerDependencies`。否则安装插件时会在 profile 的 `node_modules` 里装一份旧版,盖住宿主自带的版本,导致 `tools` 服务缺失、DSH 启动失败。它只放在 `devDependencies`。
|
|
98
|
+
|
|
99
|
+
主要结构:
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
index.js Host 入口
|
|
103
|
+
cordis.patch.yml bundle 安装 patch
|
|
104
|
+
src/host/service.js provider 路由 + Docker
|
|
105
|
+
src/host/images.js 镜像 push/build 校验
|
|
106
|
+
src/host/apple.js Apple container
|
|
107
|
+
src/host/attach.js Attach/Exec PTY
|
|
108
|
+
src/host/tools.js 只读 Agent Tools
|
|
109
|
+
src/client/ 页面、tabs、i18n、styles
|
|
110
|
+
```
|
package/cordis.patch.yml
ADDED
package/docs/ai-chat.png
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/docs/attach.png
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host entry for the Docker sidebar plugin.
|
|
3
|
+
*
|
|
4
|
+
* This file is loaded by the DSH Loader from an absolute path, so it imports
|
|
5
|
+
* only local modules and Node built-ins. The browser half is served separately
|
|
6
|
+
* from `lib/client.js` through the package's `dsh.client` declaration.
|
|
7
|
+
*
|
|
8
|
+
* The browser calls the same `/docker/...` envelope used by the Connection
|
|
9
|
+
* generic RPC channel. We mount the route ourselves because Connection's
|
|
10
|
+
* `rpc.handle` helper registers on the service owner's context, which does not
|
|
11
|
+
* inject `webServer`; the direct route below reuses `connection.admit()` for
|
|
12
|
+
* the same Host/Origin fence and browser authentication.
|
|
13
|
+
*/
|
|
14
|
+
import { createDockerService } from './src/host/service.js'
|
|
15
|
+
import { registerContainerTools } from './src/host/tools.js'
|
|
16
|
+
|
|
17
|
+
export const name = 'docker-sidebar'
|
|
18
|
+
export const inject = ['subprocess', 'connection', 'webServer', 'tools', 'systemPrompt']
|
|
19
|
+
|
|
20
|
+
const CHANNEL = '/docker'
|
|
21
|
+
const MAX_BODY_BYTES = 1024 * 1024
|
|
22
|
+
|
|
23
|
+
/** @param {import('node:http').IncomingMessage} req */
|
|
24
|
+
function readBody(req) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const chunks = []
|
|
27
|
+
let size = 0
|
|
28
|
+
req.on('data', (chunk) => {
|
|
29
|
+
size += chunk.byteLength
|
|
30
|
+
if (size > MAX_BODY_BYTES) {
|
|
31
|
+
reject(new Error('request body too large'))
|
|
32
|
+
req.destroy()
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
chunks.push(chunk)
|
|
36
|
+
})
|
|
37
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
|
38
|
+
req.on('error', reject)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {import('node:http').ServerResponse} res @param {number} status @param {unknown} body */
|
|
43
|
+
function send(res, status, body, contentType = 'application/json; charset=utf-8') {
|
|
44
|
+
if (res.writableEnded) return
|
|
45
|
+
const text = typeof body === 'string' ? body : JSON.stringify(body)
|
|
46
|
+
res.writeHead(status, { 'content-type': contentType, 'cache-control': 'no-store' })
|
|
47
|
+
res.end(text)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {import('node:http').IncomingMessage} req
|
|
52
|
+
* @param {import('node:http').ServerResponse} res
|
|
53
|
+
* @param {any} ctx
|
|
54
|
+
* @param {ReturnType<typeof createDockerService>} service
|
|
55
|
+
*/
|
|
56
|
+
async function handleRequest(req, res, ctx, service, peer) {
|
|
57
|
+
let admission
|
|
58
|
+
try {
|
|
59
|
+
// WebServer has already authenticated this route. Reuse its Peer instead of
|
|
60
|
+
// re-running the source policy on the raw request, which can disagree on
|
|
61
|
+
// some Windows host/frontend combinations.
|
|
62
|
+
admission = peer === undefined ? ctx.connection.admit(req) : { peer }
|
|
63
|
+
} catch (error) {
|
|
64
|
+
send(res, 403, `forbidden: ${error instanceof Error ? error.message : String(error)}`, 'text/plain; charset=utf-8')
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if ('rejection' in admission) {
|
|
68
|
+
send(res, admission.rejection, admission.rejection === 401 ? 'unauthorized' : 'forbidden', 'text/plain; charset=utf-8')
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
if (req.method !== 'POST') {
|
|
72
|
+
send(res, 405, 'method not allowed', 'text/plain; charset=utf-8')
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const url = new URL(req.url ?? CHANNEL, 'http://dsh.internal')
|
|
76
|
+
const endpoint = url.pathname.startsWith(`${CHANNEL}/`) ? url.pathname.slice(CHANNEL.length + 1) : ''
|
|
77
|
+
if (endpoint === '' || endpoint.includes('/')) {
|
|
78
|
+
send(res, 404, 'not found', 'text/plain; charset=utf-8')
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let message
|
|
83
|
+
try {
|
|
84
|
+
message = JSON.parse(await readBody(req))
|
|
85
|
+
} catch (error) {
|
|
86
|
+
send(res, 400, `invalid request body: ${error instanceof Error ? error.message : String(error)}`, 'text/plain; charset=utf-8')
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
message === null ||
|
|
91
|
+
typeof message !== 'object' ||
|
|
92
|
+
message.type !== 'client-request' ||
|
|
93
|
+
typeof message.rpcId !== 'string' ||
|
|
94
|
+
typeof message.method !== 'string' ||
|
|
95
|
+
message.method !== endpoint
|
|
96
|
+
) {
|
|
97
|
+
send(res, 400, 'invalid client-request envelope', 'text/plain; charset=utf-8')
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const controller = new AbortController()
|
|
102
|
+
const abort = () => controller.abort()
|
|
103
|
+
res.on('close', abort)
|
|
104
|
+
try {
|
|
105
|
+
const result = await service.handle(message.method, message.payload, controller.signal, admission.peer)
|
|
106
|
+
send(res, 200, { type: 'server-response', rpcId: message.rpcId, result })
|
|
107
|
+
} catch (error) {
|
|
108
|
+
send(res, 500, `handler failure: ${error instanceof Error ? error.message : String(error)}`, 'text/plain; charset=utf-8')
|
|
109
|
+
} finally {
|
|
110
|
+
res.off('close', abort)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
116
|
+
* @param {Record<string, any>} [config]
|
|
117
|
+
*/
|
|
118
|
+
export function apply(ctx, config = {}) {
|
|
119
|
+
const service = createDockerService({
|
|
120
|
+
subprocess: ctx.subprocess,
|
|
121
|
+
logger: ctx.logger,
|
|
122
|
+
config: config ?? {},
|
|
123
|
+
})
|
|
124
|
+
try {
|
|
125
|
+
registerContainerTools(ctx, service)
|
|
126
|
+
service.enableTools()
|
|
127
|
+
} catch (error) {
|
|
128
|
+
ctx.logger?.warn?.('docker: container tool registration failed', error)
|
|
129
|
+
}
|
|
130
|
+
ctx.effect(
|
|
131
|
+
() => ctx.webServer.register({
|
|
132
|
+
kind: 'prefix',
|
|
133
|
+
path: CHANNEL,
|
|
134
|
+
handler: (req, res, peer) => handleRequest(req, res, ctx, service, peer).catch((error) => {
|
|
135
|
+
send(res, 500, `handler failure: ${error instanceof Error ? error.message : String(error)}`, 'text/plain; charset=utf-8')
|
|
136
|
+
}),
|
|
137
|
+
}),
|
|
138
|
+
'docker: rpc route',
|
|
139
|
+
)
|
|
140
|
+
ctx.effect(() => () => service.dispose(), 'docker: jobs')
|
|
141
|
+
}
|