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/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-container-windows",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "DSH sidebar container panel for Docker Desktop on Windows/macOS, colima, OrbStack and Apple container",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./client": "./lib/client.js",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"lib/client.js",
|
|
16
|
+
"src/**/*.js",
|
|
17
|
+
"src/**/*.jsx",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"README.md",
|
|
20
|
+
"README.zh-CN.md",
|
|
21
|
+
"docs/*.png"
|
|
22
|
+
],
|
|
23
|
+
"dsh": {
|
|
24
|
+
"client": {
|
|
25
|
+
"platform": "web",
|
|
26
|
+
"inject": [
|
|
27
|
+
"@deepseek-ai/dsh-client-connection",
|
|
28
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
29
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
30
|
+
"@deepseek-ai/dsh-client-locale"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"bundle": {
|
|
34
|
+
"patch": "./cordis.patch.yml"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "node scripts/build-client.mjs",
|
|
39
|
+
"install-profile": "node scripts/install-profile.mjs",
|
|
40
|
+
"test": "node --test test/*.test.mjs",
|
|
41
|
+
"prepack": "npm run build && npm test"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"esbuild": "0.25.0",
|
|
45
|
+
"@deepseek-ai/dsh-tools": "^0.2.1-rc.5"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"keywords": [
|
|
49
|
+
"dsh",
|
|
50
|
+
"dsh-plugin",
|
|
51
|
+
"deepseek-harness",
|
|
52
|
+
"docker",
|
|
53
|
+
"docker-desktop",
|
|
54
|
+
"apple-container",
|
|
55
|
+
"macos",
|
|
56
|
+
"windows",
|
|
57
|
+
"containers"
|
|
58
|
+
],
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=22"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "git+https://github.com/my-dream0414/dsh-plugin-container-windows.git"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/my-dream0414/dsh-plugin-container-windows#readme",
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/my-dream0414/dsh-plugin-container-windows/issues"
|
|
72
|
+
},
|
|
73
|
+
"author": "Zaynervewreck"
|
|
74
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Typed wrapper around the host `/docker` Connection RPC channel. */
|
|
2
|
+
|
|
3
|
+
export const DOCKER_CHANNEL = '/docker'
|
|
4
|
+
|
|
5
|
+
export class DockerApiError extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} code
|
|
8
|
+
* @param {string} message
|
|
9
|
+
* @param {Record<string, any>} [details]
|
|
10
|
+
* @param {unknown} [cause]
|
|
11
|
+
*/
|
|
12
|
+
constructor(code, message, details = {}, cause = undefined) {
|
|
13
|
+
super(message)
|
|
14
|
+
this.name = 'DockerApiError'
|
|
15
|
+
this.code = code
|
|
16
|
+
this.details = details
|
|
17
|
+
this.cause = cause
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @param {unknown} error */
|
|
22
|
+
export function isAbortError(error) {
|
|
23
|
+
return (
|
|
24
|
+
(error instanceof DOMException && error.name === 'AbortError') ||
|
|
25
|
+
error?.name === 'AbortError' ||
|
|
26
|
+
error?.code === 'docker/cancelled'
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @param {unknown} value */
|
|
31
|
+
function isResult(value) {
|
|
32
|
+
return typeof value === 'object' && value !== null && typeof value.ok === 'boolean'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @param {any} connection */
|
|
36
|
+
export function createApi(connection) {
|
|
37
|
+
return {
|
|
38
|
+
connection,
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} method
|
|
41
|
+
* @param {Record<string, any>} payload
|
|
42
|
+
* @param {AbortSignal} [signal]
|
|
43
|
+
*/
|
|
44
|
+
async call(method, payload = {}, signal = undefined) {
|
|
45
|
+
let result
|
|
46
|
+
try {
|
|
47
|
+
result = await connection.rpc.call(DOCKER_CHANNEL, method, payload, signal)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (isAbortError(error)) throw new DockerApiError('docker/cancelled', '请求已取消', {}, error)
|
|
50
|
+
throw new DockerApiError('docker/transport', transportMessage(error), {}, error)
|
|
51
|
+
}
|
|
52
|
+
if (!isResult(result)) throw new DockerApiError('docker/protocol', 'Docker 服务返回了无效响应')
|
|
53
|
+
if (result.ok !== true) {
|
|
54
|
+
const error = result.error ?? {}
|
|
55
|
+
throw new DockerApiError(
|
|
56
|
+
typeof error.code === 'string' ? error.code : 'docker/internal',
|
|
57
|
+
typeof error.message === 'string' ? error.message : 'Docker 服务调用失败',
|
|
58
|
+
error.details ?? {},
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
return result.value
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {unknown} error */
|
|
67
|
+
function transportMessage(error) {
|
|
68
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
69
|
+
if (/HTTP 404|not found/iu.test(message)) return 'Docker 服务未加载(/docker 通道不可用),请刷新页面或重启 DSH'
|
|
70
|
+
if (/HTTP 500/iu.test(message)) return 'Docker 服务内部错误,请查看 DSH 日志'
|
|
71
|
+
if (/HTTP 401|HTTP 403/iu.test(message)) return '本机 Docker 服务通道被拒绝;请重启 DSH 后重试'
|
|
72
|
+
return `Docker 服务连接失败:${message}`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Module-level query cache used by the tabs. Values only, never promises. */
|
|
76
|
+
const queryCache = new Map()
|
|
77
|
+
|
|
78
|
+
/** @param {string} key */
|
|
79
|
+
export function cacheGet(key) {
|
|
80
|
+
const hit = queryCache.get(key)
|
|
81
|
+
if (hit === undefined) return undefined
|
|
82
|
+
if (Date.now() - hit.at > hit.ttl) {
|
|
83
|
+
queryCache.delete(key)
|
|
84
|
+
return undefined
|
|
85
|
+
}
|
|
86
|
+
return hit.value
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @param {string} key @param {unknown} value @param {number} [ttl] */
|
|
90
|
+
export function cacheSet(key, value, ttl = 2000) {
|
|
91
|
+
queryCache.set(key, { at: Date.now(), value, ttl })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @param {string} [prefix] */
|
|
95
|
+
export function cacheClear(prefix = '') {
|
|
96
|
+
if (prefix === '') queryCache.clear()
|
|
97
|
+
else for (const key of [...queryCache.keys()]) if (key.startsWith(prefix)) queryCache.delete(key)
|
|
98
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/** Interactive PTY attach viewer: raw output plus keyboard/paste input. */
|
|
2
|
+
import { useEffect, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { Button, CopyButton, Modal, Spinner } from './components.jsx'
|
|
5
|
+
|
|
6
|
+
/** Keep common terminal output readable without pulling xterm into this modal. */
|
|
7
|
+
function cleanTerminal(text) {
|
|
8
|
+
return text
|
|
9
|
+
.replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)/gu, '')
|
|
10
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/gu, '')
|
|
11
|
+
.replace(/\x1b[@-_]/gu, '')
|
|
12
|
+
.replace(/\r/gu, '')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function statusLabel(t, status) {
|
|
16
|
+
if (status === 'running') return t('attachRunning')
|
|
17
|
+
if (status === 'exited') return t('attachExited')
|
|
18
|
+
if (status === 'failed') return t('attachFailed')
|
|
19
|
+
if (status === 'closed') return t('attachClosed')
|
|
20
|
+
return t('attachStarting')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function keyBytes(event) {
|
|
24
|
+
if (event.metaKey) return null
|
|
25
|
+
if (event.ctrlKey && event.key.length === 1) {
|
|
26
|
+
const code = event.key.toUpperCase().charCodeAt(0)
|
|
27
|
+
if (code >= 64 && code <= 95) return String.fromCharCode(code - 64)
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
if (event.altKey) return null
|
|
31
|
+
if (event.key === 'Enter') return '\r'
|
|
32
|
+
if (event.key === 'Backspace') return '\x7f'
|
|
33
|
+
if (event.key === 'Tab') return '\t'
|
|
34
|
+
if (event.key === 'Escape') return '\x1b'
|
|
35
|
+
if (event.key === 'ArrowUp') return '\x1b[A'
|
|
36
|
+
if (event.key === 'ArrowDown') return '\x1b[B'
|
|
37
|
+
if (event.key === 'ArrowRight') return '\x1b[C'
|
|
38
|
+
if (event.key === 'ArrowLeft') return '\x1b[D'
|
|
39
|
+
if (event.key === 'Home') return '\x1b[H'
|
|
40
|
+
if (event.key === 'End') return '\x1b[F'
|
|
41
|
+
if (event.key === 'Delete') return '\x1b[3~'
|
|
42
|
+
if (event.key === 'PageUp') return '\x1b[5~'
|
|
43
|
+
if (event.key === 'PageDown') return '\x1b[6~'
|
|
44
|
+
if (event.key.length === 1) return event.key
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default function AttachDialog({ open, t, mode = 'attach', session, output, loading, error, onInput, onClose }) {
|
|
49
|
+
const screenRef = useRef(null)
|
|
50
|
+
const preRef = useRef(null)
|
|
51
|
+
const [stick, setStick] = useState(true)
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!open) return undefined
|
|
55
|
+
setStick(true)
|
|
56
|
+
const timer = setTimeout(() => screenRef.current?.focus(), 60)
|
|
57
|
+
return () => clearTimeout(timer)
|
|
58
|
+
}, [open])
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!stick) return
|
|
62
|
+
const element = preRef.current
|
|
63
|
+
if (element !== null) element.scrollTop = element.scrollHeight
|
|
64
|
+
}, [output, stick])
|
|
65
|
+
|
|
66
|
+
const running = session?.status === 'running'
|
|
67
|
+
const title = (session?.mode ?? mode) === 'exec' ? t('execTitle') : t('attachTitle')
|
|
68
|
+
const shown = cleanTerminal(output)
|
|
69
|
+
return (
|
|
70
|
+
<Modal
|
|
71
|
+
open={open}
|
|
72
|
+
title={`${title} · ${session?.containerName ?? ''}`}
|
|
73
|
+
subtitle={session?.command ?? undefined}
|
|
74
|
+
wide
|
|
75
|
+
onClose={onClose}
|
|
76
|
+
closeLabel={t('close')}
|
|
77
|
+
footer={
|
|
78
|
+
<>
|
|
79
|
+
<span className="dsh-docker-muted">{t('attachInputHint')}</span>
|
|
80
|
+
<span style={{ flex: 1 }} />
|
|
81
|
+
{session?.exitCode !== null && session?.exitCode !== undefined && <span className="dsh-docker-muted">{t('exitCode')}: {session.exitCode}</span>}
|
|
82
|
+
<CopyButton text={shown} label={t('copy')} copiedLabel={t('copied')} />
|
|
83
|
+
<Button size="sm" onClick={onClose}>{t((session?.mode ?? mode) === 'exec' ? 'execClose' : 'attachClose')}</Button>
|
|
84
|
+
</>
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
<div className="dsh-docker-attach-status">
|
|
88
|
+
<span className="dsh-docker-status" data-state={running ? 'running' : session?.status === 'failed' ? 'error' : 'stopped'}>
|
|
89
|
+
<span className="dsh-docker-dot" />
|
|
90
|
+
{statusLabel(t, session?.status)}
|
|
91
|
+
</span>
|
|
92
|
+
<span className="dsh-docker-muted">{session?.cols ?? 120} × {session?.rows ?? 30}</span>
|
|
93
|
+
</div>
|
|
94
|
+
<div
|
|
95
|
+
ref={screenRef}
|
|
96
|
+
className="dsh-docker-attach-screen"
|
|
97
|
+
tabIndex={0}
|
|
98
|
+
role="textbox"
|
|
99
|
+
aria-label={title}
|
|
100
|
+
onKeyDown={(event) => {
|
|
101
|
+
if (!running || loading) return
|
|
102
|
+
const data = keyBytes(event)
|
|
103
|
+
if (data === null) return
|
|
104
|
+
event.preventDefault()
|
|
105
|
+
onInput(data)
|
|
106
|
+
}}
|
|
107
|
+
onPaste={(event) => {
|
|
108
|
+
if (!running || loading) return
|
|
109
|
+
event.preventDefault()
|
|
110
|
+
const text = event.clipboardData.getData('text')
|
|
111
|
+
if (text !== '') onInput(text)
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{loading ? (
|
|
115
|
+
<div className="dsh-docker-attach-loading"><Spinner size={16} /> {t('attachStarting')}</div>
|
|
116
|
+
) : error !== null ? (
|
|
117
|
+
<pre className="dsh-docker-attach-pre dsh-docker-attach-error">{error.message ?? String(error)}</pre>
|
|
118
|
+
) : shown === '' ? (
|
|
119
|
+
<pre className="dsh-docker-attach-pre dsh-docker-no-output">{t('attachHint')}</pre>
|
|
120
|
+
) : (
|
|
121
|
+
<pre
|
|
122
|
+
ref={preRef}
|
|
123
|
+
className="dsh-docker-attach-pre"
|
|
124
|
+
onScroll={() => {
|
|
125
|
+
const element = preRef.current
|
|
126
|
+
if (element === null) return
|
|
127
|
+
setStick(element.scrollHeight - element.scrollTop - element.clientHeight < 28)
|
|
128
|
+
}}
|
|
129
|
+
>{shown}</pre>
|
|
130
|
+
)}
|
|
131
|
+
</div>
|
|
132
|
+
</Modal>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/** Build an image from a project directory, validating the directory as the user types. */
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { Button, Modal, fill } from './components.jsx'
|
|
5
|
+
import { PLATFORMS } from './platforms.js'
|
|
6
|
+
|
|
7
|
+
const IMAGE_REF = /^[A-Za-z0-9][A-Za-z0-9_.:/@-]*$/u
|
|
8
|
+
|
|
9
|
+
export default function BuildImageDialog({ open, t, api, provider, defaultDir = '', pickDirectory, onClose, onSubmit }) {
|
|
10
|
+
const [dir, setDir] = useState('')
|
|
11
|
+
const [info, setInfo] = useState(null)
|
|
12
|
+
const [file, setFile] = useState('')
|
|
13
|
+
const [tag, setTag] = useState('')
|
|
14
|
+
const [tagEdited, setTagEdited] = useState(false)
|
|
15
|
+
const [platform, setPlatform] = useState('')
|
|
16
|
+
const [noCache, setNoCache] = useState(false)
|
|
17
|
+
const [buildArgs, setBuildArgs] = useState('')
|
|
18
|
+
const [error, setError] = useState(null)
|
|
19
|
+
const [busy, setBusy] = useState(false)
|
|
20
|
+
const requestId = useRef(0)
|
|
21
|
+
const canPick = typeof pickDirectory === 'function' && (pickDirectory.available?.() ?? true)
|
|
22
|
+
|
|
23
|
+
const choose = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const picked = await pickDirectory()
|
|
26
|
+
if (typeof picked === 'string' && picked !== '') {
|
|
27
|
+
setDir(picked)
|
|
28
|
+
setError(null)
|
|
29
|
+
}
|
|
30
|
+
} catch (pickError) {
|
|
31
|
+
setError(pickError instanceof Error && pickError.message !== 'unsupported' ? pickError.message : t('imgBuildDirPickFailed'))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!open) return
|
|
37
|
+
setDir(defaultDir)
|
|
38
|
+
setInfo(null)
|
|
39
|
+
setFile('')
|
|
40
|
+
setTag('')
|
|
41
|
+
setTagEdited(false)
|
|
42
|
+
setPlatform('')
|
|
43
|
+
setNoCache(false)
|
|
44
|
+
setBuildArgs('')
|
|
45
|
+
setError(null)
|
|
46
|
+
setBusy(false)
|
|
47
|
+
}, [open, defaultDir])
|
|
48
|
+
|
|
49
|
+
// Validate the directory shortly after the user stops typing.
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!open) return undefined
|
|
52
|
+
const path = dir.trim()
|
|
53
|
+
if (path === '') {
|
|
54
|
+
setInfo(null)
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
const id = ++requestId.current
|
|
58
|
+
const timer = setTimeout(async () => {
|
|
59
|
+
try {
|
|
60
|
+
const value = await api.call('buildContext', { path })
|
|
61
|
+
if (id !== requestId.current) return
|
|
62
|
+
setInfo(value)
|
|
63
|
+
setFile((current) => (value.dockerfiles.includes(current) ? current : (value.dockerfiles[0] ?? '')))
|
|
64
|
+
// Follow the folder until the user types their own tag.
|
|
65
|
+
if (value.suggestedTag !== '' && !tagEdited) setTag(value.suggestedTag)
|
|
66
|
+
} catch {
|
|
67
|
+
if (id === requestId.current) setInfo(null)
|
|
68
|
+
}
|
|
69
|
+
}, 300)
|
|
70
|
+
return () => clearTimeout(timer)
|
|
71
|
+
}, [api, dir, open, tagEdited])
|
|
72
|
+
|
|
73
|
+
const args = useMemo(() => buildArgs.split(/\n/u).map((line) => line.trim()).filter(Boolean), [buildArgs])
|
|
74
|
+
const tagValid = IMAGE_REF.test(tag.trim())
|
|
75
|
+
const trimmedDir = dir.trim()
|
|
76
|
+
const dirChecked = info !== null && info.path === trimmedDir
|
|
77
|
+
const dirOk = dirChecked && info.isDirectory && info.dockerfiles.length > 0
|
|
78
|
+
|
|
79
|
+
let dirLine = null
|
|
80
|
+
if (trimmedDir !== '' && !dirChecked) dirLine = { tone: 'hint', text: t('imgBuildDirChecking') }
|
|
81
|
+
else if (dirChecked && !info.exists) dirLine = { tone: 'err', text: t('imgBuildDirMissing') }
|
|
82
|
+
else if (dirChecked && !info.isDirectory) dirLine = { tone: 'err', text: t('imgBuildDirNotDir') }
|
|
83
|
+
else if (dirChecked && info.dockerfiles.length === 0) dirLine = { tone: 'err', text: t('imgBuildDirNoFile') }
|
|
84
|
+
else if (dirChecked) dirLine = { tone: 'ok', text: fill(t('imgBuildDirOk'), { count: info.dockerfiles.length }) }
|
|
85
|
+
|
|
86
|
+
const command = useMemo(() => {
|
|
87
|
+
const cli = provider === 'apple-container' ? 'container' : 'docker'
|
|
88
|
+
const parts = [cli, 'build', '-t', tag.trim() || '<name:tag>']
|
|
89
|
+
if (file !== '' && file !== 'Dockerfile') parts.push('-f', file)
|
|
90
|
+
if (platform !== '') parts.push('--platform', platform)
|
|
91
|
+
if (noCache) parts.push('--no-cache')
|
|
92
|
+
for (const arg of args) parts.push('--build-arg', arg)
|
|
93
|
+
parts.push('.')
|
|
94
|
+
return `cd ${trimmedDir || '<dir>'}\n${parts.join(' ')}`
|
|
95
|
+
}, [args, file, noCache, platform, provider, tag, trimmedDir])
|
|
96
|
+
|
|
97
|
+
const submit = async (event) => {
|
|
98
|
+
event?.preventDefault()
|
|
99
|
+
if (!dirOk) {
|
|
100
|
+
setError(dirLine?.tone === 'err' ? dirLine.text : t('imgBuildDirPlaceholder'))
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
if (!tagValid) {
|
|
104
|
+
setError(t('imgBuildTagRequired'))
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
setBusy(true)
|
|
108
|
+
setError(null)
|
|
109
|
+
try {
|
|
110
|
+
await onSubmit({
|
|
111
|
+
kind: 'image',
|
|
112
|
+
action: 'build',
|
|
113
|
+
tag: tag.trim(),
|
|
114
|
+
name: tag.trim(),
|
|
115
|
+
contextDir: trimmedDir,
|
|
116
|
+
file: file === '' ? undefined : file,
|
|
117
|
+
platform: platform === '' ? undefined : platform,
|
|
118
|
+
noCache,
|
|
119
|
+
buildArgs: args,
|
|
120
|
+
})
|
|
121
|
+
onClose()
|
|
122
|
+
} catch (submitError) {
|
|
123
|
+
setError(submitError instanceof Error ? submitError.message : String(submitError))
|
|
124
|
+
setBusy(false)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Modal
|
|
130
|
+
open={open}
|
|
131
|
+
title={t('imgBuildTitle')}
|
|
132
|
+
subtitle={provider === 'apple-container' ? t('providerApple') : t('providerDocker')}
|
|
133
|
+
onClose={onClose}
|
|
134
|
+
closeLabel={t('close')}
|
|
135
|
+
footer={
|
|
136
|
+
<>
|
|
137
|
+
<Button size="sm" variant="ghost" onClick={onClose} disabled={busy}>{t('modalCancel')}</Button>
|
|
138
|
+
<Button size="sm" variant="primary" onClick={submit} disabled={busy || !dirOk || !tagValid}>
|
|
139
|
+
{busy ? t('imgBuilding') : t('imgBuildStart')}
|
|
140
|
+
</Button>
|
|
141
|
+
</>
|
|
142
|
+
}
|
|
143
|
+
>
|
|
144
|
+
<form className="dsh-docker-run-form" onSubmit={submit}>
|
|
145
|
+
{/* A div, not a label: clicking the caption should not open the folder picker. */}
|
|
146
|
+
<div className="dsh-docker-field">
|
|
147
|
+
<span>{t('imgBuildDir')}</span>
|
|
148
|
+
<div className="dsh-docker-image-picker">
|
|
149
|
+
<input
|
|
150
|
+
className="dsh-docker-input dsh-docker-mono"
|
|
151
|
+
style={{ flex: 1, minWidth: 0 }}
|
|
152
|
+
value={dir}
|
|
153
|
+
onChange={(event) => setDir(event.target.value)}
|
|
154
|
+
onClick={canPick ? choose : undefined}
|
|
155
|
+
readOnly={canPick}
|
|
156
|
+
placeholder={canPick ? t('imgBuildDirChoose') : t('imgBuildDirPlaceholder')}
|
|
157
|
+
spellCheck="false"
|
|
158
|
+
autoFocus={!canPick}
|
|
159
|
+
/>
|
|
160
|
+
{canPick && <Button size="sm" onClick={choose}>{dir.trim() === '' ? t('imgBuildDirChoose') : t('imgBuildDirChange')}</Button>}
|
|
161
|
+
</div>
|
|
162
|
+
{dirLine === null || dirLine.tone === 'hint'
|
|
163
|
+
? <span className="dsh-docker-hint">{dirLine?.text ?? t('imgBuildDirHint')}</span>
|
|
164
|
+
: <span className={dirLine.tone === 'ok' ? 'dsh-docker-line-ok' : 'dsh-docker-line-err'}>{dirLine.text}</span>}
|
|
165
|
+
</div>
|
|
166
|
+
{dirOk && info.dockerfiles.length > 1 && (
|
|
167
|
+
<label className="dsh-docker-field">
|
|
168
|
+
<span>{t('imgBuildFile')}</span>
|
|
169
|
+
<select className="dsh-docker-select" value={file} onChange={(event) => setFile(event.target.value)}>
|
|
170
|
+
{info.dockerfiles.map((name) => <option key={name} value={name}>{name}</option>)}
|
|
171
|
+
</select>
|
|
172
|
+
</label>
|
|
173
|
+
)}
|
|
174
|
+
<label className="dsh-docker-field">
|
|
175
|
+
<span>{t('imgBuildTag')}</span>
|
|
176
|
+
<input
|
|
177
|
+
className="dsh-docker-input dsh-docker-mono"
|
|
178
|
+
value={tag}
|
|
179
|
+
onChange={(event) => {
|
|
180
|
+
setTag(event.target.value)
|
|
181
|
+
setTagEdited(true)
|
|
182
|
+
}}
|
|
183
|
+
placeholder={t('imgBuildTagPlaceholder')}
|
|
184
|
+
spellCheck="false"
|
|
185
|
+
/>
|
|
186
|
+
<span className="dsh-docker-hint">{t('imgBuildTagHint')}</span>
|
|
187
|
+
</label>
|
|
188
|
+
<details className="dsh-docker-advanced">
|
|
189
|
+
<summary>{t('imgBuildAdvanced')}</summary>
|
|
190
|
+
<div className="dsh-docker-advanced-body">
|
|
191
|
+
<label className="dsh-docker-field">
|
|
192
|
+
<span>{t('imgBuildPlatform')}</span>
|
|
193
|
+
<select className="dsh-docker-select" value={platform} onChange={(event) => setPlatform(event.target.value)}>
|
|
194
|
+
<option value="">{t('imgBuildPlatformAuto')}</option>
|
|
195
|
+
{PLATFORMS.map((name) => <option key={name} value={name}>{name}</option>)}
|
|
196
|
+
</select>
|
|
197
|
+
</label>
|
|
198
|
+
<label className="dsh-docker-check">
|
|
199
|
+
<input type="checkbox" checked={noCache} onChange={(event) => setNoCache(event.target.checked)} />
|
|
200
|
+
<span>{t('imgBuildNoCache')}</span>
|
|
201
|
+
</label>
|
|
202
|
+
<label className="dsh-docker-field">
|
|
203
|
+
<span>{t('imgBuildArgs')}</span>
|
|
204
|
+
<textarea
|
|
205
|
+
className="dsh-docker-input dsh-docker-textarea"
|
|
206
|
+
value={buildArgs}
|
|
207
|
+
onChange={(event) => setBuildArgs(event.target.value)}
|
|
208
|
+
placeholder={t('imgBuildArgsPlaceholder')}
|
|
209
|
+
spellCheck="false"
|
|
210
|
+
rows={3}
|
|
211
|
+
/>
|
|
212
|
+
</label>
|
|
213
|
+
</div>
|
|
214
|
+
</details>
|
|
215
|
+
<label className="dsh-docker-field">
|
|
216
|
+
<span>{t('imgCommandPreview')}</span>
|
|
217
|
+
<pre className="dsh-docker-preview">{command}</pre>
|
|
218
|
+
</label>
|
|
219
|
+
<div className="dsh-docker-hint">{t('imgBuildHint')}</div>
|
|
220
|
+
{error !== null && <div className="dsh-docker-form-error">{error}</div>}
|
|
221
|
+
</form>
|
|
222
|
+
</Modal>
|
|
223
|
+
)
|
|
224
|
+
}
|