Skip to content

Commit dd0d160

Browse files
committed
directly start ssh session
1 parent 3699791 commit dd0d160

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"imports": {
1818
"@cfa/gitignore-parser": "jsr:@cfa/gitignore-parser@^0.1.4",
1919
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8",
20-
"@deno/sandbox": "jsr:@deno/sandbox@^0",
20+
"@deno/sandbox": "jsr:@deno/sandbox@^0.2.1",
2121
"@std/cli": "jsr:@std/cli@1.0.22",
2222
"@std/dotenv": "jsr:@std/dotenv@^0.225.5",
2323
"@std/encoding": "jsr:@std/encoding@^1.0.10",

sandbox.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const sandboxKillCommand = new Command()
109109
const res = await (client.sandboxes as any).kill.mutate({
110110
org: orgAndApp.org,
111111
sandboxId,
112-
clusterHostname: [cluster.hostname]
112+
clusterHostname: [cluster.hostname],
113113
});
114114

115115
if (res.success) {
@@ -143,22 +143,42 @@ export const sandboxSshCommand = new Command()
143143
(client.orgs as any).accessTokens.create.mutate({
144144
org: orgAndApp.org,
145145
description: "$$DENO_DEPLOY_CLI_SSH_TOKEN$$",
146-
expiresAt: new Date(Date.now() + 1000 * 60 * 60),
146+
expiresAt: new Date(Date.now() + 1000 * 60 * 60).toISOString(),
147147
}),
148148
]);
149149

150-
await using sandbox = Sandbox.connect({
150+
await using sandbox = await Sandbox.connect({
151151
id: sandboxId,
152-
endpoint: cluster.hostname,
152+
region: cluster.region,
153153
debug: options.debug,
154154
token: token.token,
155155
});
156156

157157
const ssh = await sandbox.exposeSsh();
158158

159-
console.log(
160-
`Started ssh session, you can now connect to ${ssh.username}@${ssh.hostname}.\nUse Ctrl+C to exit.`,
161-
);
159+
const connectInfo = ssh.username + "@" + ssh.hostname;
160+
161+
const which = await new Deno.Command("which", {
162+
args: ["ssh"],
163+
stdout: "null",
164+
stderr: "null",
165+
}).output();
166+
167+
if (which.success) {
168+
// If ssh is available, directly spawn ssh process
169+
const command = new Deno.Command("ssh", {
170+
args: [connectInfo],
171+
stdin: "inherit",
172+
stdout: "inherit",
173+
stderr: "inherit",
174+
});
175+
176+
const _sshProcess = command.spawn();
177+
} else {
178+
console.log(
179+
`Started ssh session, you can now connect to ${connectInfo}.\nUse Ctrl+C to exit.`,
180+
);
181+
}
162182
});
163183

164184
export function formatPassedTime(ms: number, roundToSeconds = false) {

0 commit comments

Comments
 (0)