fix: support ts backend core cli probes
This commit is contained in:
+18
-5
@@ -661,8 +661,9 @@ export function wrapSshRemoteCommand(command: string | null): string {
|
||||
function brokerSource(): string {
|
||||
return String.raw`
|
||||
const open = JSON.parse(process.argv[2] || process.argv[1] || "{}");
|
||||
const token = process.env.PROVIDER_TOKEN || "";
|
||||
const url = "ws://backend-core:8080/ws/ssh?token=" + encodeURIComponent(token);
|
||||
const token = process.env.PROVIDER_TOKEN || process.env.UNIDESK_PROVIDER_TOKEN || "";
|
||||
const baseUrl = process.env.UNIDESK_SSH_BROKER_URL || "ws://backend-core:8080/ws/ssh";
|
||||
const url = baseUrl + "?token=" + encodeURIComponent(token);
|
||||
const ws = new WebSocket(url);
|
||||
let exitCode = 255;
|
||||
let canSend = false;
|
||||
@@ -802,13 +803,25 @@ export async function runSsh(config: UniDeskConfig, providerId: string, args: st
|
||||
cols: size.cols,
|
||||
rows: size.rows,
|
||||
};
|
||||
const payloadJson = JSON.stringify(payload);
|
||||
const encodedBrokerSource = Buffer.from(brokerSource(), "utf8").toString("base64");
|
||||
const script = [
|
||||
"set -euo pipefail",
|
||||
`payload=${shellQuote(payloadJson)}`,
|
||||
"if command -v backend-core >/dev/null 2>&1; then",
|
||||
' exec backend-core --ssh-broker "$payload"',
|
||||
"fi",
|
||||
`export UNIDESK_SSH_BROKER_URL=${shellQuote("ws://127.0.0.1:8080/ws/ssh")}`,
|
||||
`printf %s ${shellQuote(encodedBrokerSource)} | base64 -d >/tmp/unidesk-ssh-broker.js`,
|
||||
"exec bun /tmp/unidesk-ssh-broker.js \"$payload\"",
|
||||
].join("\n");
|
||||
const child = spawn("docker", [
|
||||
"exec",
|
||||
"-i",
|
||||
"unidesk-backend-core",
|
||||
"backend-core",
|
||||
"--ssh-broker",
|
||||
JSON.stringify(payload),
|
||||
"sh",
|
||||
"-lc",
|
||||
script,
|
||||
], {
|
||||
cwd: repoRoot,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
|
||||
Reference in New Issue
Block a user