@lazycatcloud/lzc-cli 1.2.31 → 1.2.33
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.
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "child_process"
|
|
2
2
|
import fs from "node:fs"
|
|
3
3
|
import shellApi from "../shellapi.js"
|
|
4
|
-
import
|
|
5
|
-
import { isDebugMode, resolveDomain, sleep } from "../utils.js"
|
|
4
|
+
import { isDebugMode, resolveDomain, sleep, sshCmd } from "../utils.js"
|
|
6
5
|
import logger from "loglevel"
|
|
7
6
|
|
|
8
7
|
export class DebugBridge {
|
|
@@ -10,13 +9,17 @@ export class DebugBridge {
|
|
|
10
9
|
this.uid = shellApi.uid
|
|
11
10
|
this.boxname = shellApi.boxname
|
|
12
11
|
this.domain = `dev.${this.boxname}.heiyu.space`
|
|
13
|
-
this.sshCmd =
|
|
12
|
+
this.sshCmd = sshCmd(
|
|
13
|
+
`${isDebugMode() ? "-vv" : ""}`,
|
|
14
|
+
"-p 22222",
|
|
15
|
+
`box@${this.domain}`
|
|
16
|
+
)
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
async common(cmd, args) {
|
|
17
20
|
const resolvedIp = await resolveDomain(this.domain)
|
|
18
|
-
const
|
|
19
|
-
const ssh = spawnSync(
|
|
21
|
+
const resolvedCmd = cmd.replace(this.domain, resolvedIp)
|
|
22
|
+
const ssh = spawnSync(resolvedCmd, args, {
|
|
20
23
|
shell: true,
|
|
21
24
|
encoding: "utf-8",
|
|
22
25
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -25,7 +28,7 @@ export class DebugBridge {
|
|
|
25
28
|
ssh.status == 0
|
|
26
29
|
? resolve(ssh.stdout)
|
|
27
30
|
: reject(
|
|
28
|
-
`执行命令 ${
|
|
31
|
+
`执行命令 ${resolvedCmd} ${args.join(" ")} 出错\n${ssh.stderr ?? ""}`
|
|
29
32
|
)
|
|
30
33
|
})
|
|
31
34
|
}
|
|
@@ -39,7 +42,7 @@ export class DebugBridge {
|
|
|
39
42
|
const stream = fs.createReadStream(lpkPath)
|
|
40
43
|
const resolvedIp = await resolveDomain(this.domain)
|
|
41
44
|
const ssh = spawn(
|
|
42
|
-
|
|
45
|
+
sshCmd("-p 22222", `box@${resolvedIp}`),
|
|
43
46
|
[`install --uid ${this.uid} --pkgId ${pkgId}`],
|
|
44
47
|
{
|
|
45
48
|
shell: true,
|
|
@@ -61,7 +64,9 @@ export class DebugBridge {
|
|
|
61
64
|
|
|
62
65
|
async sshCopyId() {
|
|
63
66
|
const resolvedIp = await resolveDomain(this.domain)
|
|
64
|
-
return this.common(`ssh-copy-id`, [
|
|
67
|
+
return this.common(`ssh-copy-id`, [
|
|
68
|
+
`-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -f -p 22222 box@${resolvedIp}`
|
|
69
|
+
])
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
async status(appId) {
|
|
@@ -85,7 +90,6 @@ export class DebugBridge {
|
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
async devshell(appId, isUserApp, onconnect = null) {
|
|
88
|
-
const resolvedIp = await resolveDomain(this.domain)
|
|
89
93
|
let waiting = true
|
|
90
94
|
while (waiting) {
|
|
91
95
|
if (await this.isDevshell(appId)) {
|
|
@@ -96,8 +100,10 @@ export class DebugBridge {
|
|
|
96
100
|
await sleep(100)
|
|
97
101
|
}
|
|
98
102
|
|
|
103
|
+
const resolvedIp = await resolveDomain(this.domain)
|
|
104
|
+
|
|
99
105
|
const stream = spawn(
|
|
100
|
-
|
|
106
|
+
sshCmd("-p 22222", `box@${resolvedIp}`),
|
|
101
107
|
[
|
|
102
108
|
"-t",
|
|
103
109
|
"devshell",
|
|
@@ -117,7 +123,9 @@ export class DebugBridge {
|
|
|
117
123
|
})
|
|
118
124
|
// spawn 事件只是进程启动成功的事件,并不是ssh成功连接上的事件。所以这里使
|
|
119
125
|
// 用前面的一个 isDevshell 判断是否已经启动这个容器,再使用 spawn
|
|
120
|
-
stream.on("spawn",
|
|
126
|
+
stream.on("spawn", () => {
|
|
127
|
+
onconnect && onconnect()
|
|
128
|
+
})
|
|
121
129
|
})
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -125,8 +133,9 @@ export class DebugBridge {
|
|
|
125
133
|
const tag = `debug.bridge/${label}`
|
|
126
134
|
const resolvedIp = await resolveDomain(this.domain)
|
|
127
135
|
const stream = fs.createReadStream(contextTar)
|
|
136
|
+
|
|
128
137
|
const ssh = spawn(
|
|
129
|
-
|
|
138
|
+
sshCmd("-p 22222", `box@${resolvedIp}`),
|
|
130
139
|
[`build --tag ${tag}`],
|
|
131
140
|
{
|
|
132
141
|
shell: true,
|
package/lib/app/lpk_devshell.js
CHANGED
|
@@ -18,8 +18,7 @@ import {
|
|
|
18
18
|
isUserApp,
|
|
19
19
|
createTemplateFileCommon,
|
|
20
20
|
isDebugMode,
|
|
21
|
-
resolveDomain
|
|
22
|
-
sleep
|
|
21
|
+
resolveDomain
|
|
23
22
|
} from "../utils.js"
|
|
24
23
|
import os from "node:os"
|
|
25
24
|
import commandExists from "command-exists"
|
|
@@ -412,8 +411,8 @@ class DevShell {
|
|
|
412
411
|
const resolvedIp = await resolveDomain(`dev.${shellApi.boxname}.heiyu.space`);
|
|
413
412
|
let rsh = [
|
|
414
413
|
"ssh",
|
|
415
|
-
"-
|
|
416
|
-
`box
|
|
414
|
+
"-o",
|
|
415
|
+
`"ProxyCommand ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -q -W %h:%p -p 22222 box@${resolvedIp}"`,
|
|
417
416
|
"-p",
|
|
418
417
|
`22222`,
|
|
419
418
|
"-o",
|
package/lib/utils.js
CHANGED
|
@@ -464,3 +464,14 @@ export async function resolveDomain(domain) {
|
|
|
464
464
|
throw new Error(`无法解析域名 ${domain}: ${error.message}`)
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
+
|
|
468
|
+
export function sshCmd(...args) {
|
|
469
|
+
const baseCommand = "ssh"
|
|
470
|
+
const defaultOptions = [
|
|
471
|
+
"-o StrictHostKeyChecking=no",
|
|
472
|
+
"-o UserKnownHostsFile=/dev/null",
|
|
473
|
+
"-q"
|
|
474
|
+
]
|
|
475
|
+
const options = [...defaultOptions, ...args].join(" ")
|
|
476
|
+
return `${baseCommand} ${options}`
|
|
477
|
+
}
|
package/package.json
CHANGED