feat(lms): add Docker setup guidance and improve remote workspace handling
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { execFile } from 'node:child_process'
|
||||
|
||||
export type DockerStatus = 'ready' | 'missing' | 'permission' | 'unavailable' | 'error'
|
||||
|
||||
export function classifyDockerError(code: string | number | null | undefined, message: string): DockerStatus {
|
||||
if (code === 'ENOENT') return 'missing'
|
||||
if (/permission denied|access is denied|EACCES/i.test(message)) return 'permission'
|
||||
if (/cannot connect|connection refused|is the docker daemon running/i.test(message)) return 'unavailable'
|
||||
return 'error'
|
||||
}
|
||||
|
||||
export function checkDockerStatus(): Promise<{ status: DockerStatus; platform: string }> {
|
||||
return new Promise((resolve) => {
|
||||
execFile('docker', ['info', '--format', '{{.ServerVersion}}'], {
|
||||
timeout: 5000,
|
||||
maxBuffer: 256 * 1024,
|
||||
env: { ...process.env, LC_ALL: 'C', LANG: 'C' },
|
||||
}, (error, stdout, stderr) => {
|
||||
resolve({
|
||||
status: error
|
||||
? classifyDockerError(error.code, `${error.message}\n${stderr}`)
|
||||
: stdout.trim() ? 'ready' : 'error',
|
||||
platform: process.platform,
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user