Skip to content

Commit 9a22590

Browse files
Dev Container heartbeats (#113)
Co-authored-by: jeanp413 <[email protected]>
1 parent 9ee2404 commit 9a22590

File tree

4 files changed

+66
-24
lines changed

4 files changed

+66
-24
lines changed

src/commands/workspaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export class ConnectInCurrentWindowCommand implements Command {
361361

362362
private async initializeLocalSSH(workspaceId: string) {
363363
try {
364-
await this.remoteService.updateRemoteSSHConfig();
364+
await this.remoteService.updateRemoteConfig();
365365
await Promise.all([
366366
this.remoteService.setupSSHProxy(),
367367
this.remoteService.startLocalSSHServiceServer()

src/remote.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ export function getGitpodRemoteWindowConnectionInfo(context: vscode.ExtensionCon
5959
const remoteUri = vscode.workspace.workspaceFile?.scheme !== 'untitled'
6060
? vscode.workspace.workspaceFile || vscode.workspace.workspaceFolders?.[0].uri
6161
: vscode.workspace.workspaceFolders?.[0].uri;
62+
if (vscode.env.remoteName === 'dev-container' && context.extension.extensionKind === vscode.ExtensionKind.UI && remoteUri) {
63+
const authorities = remoteUri.authority.split('@');
64+
const sshAuthority = authorities.find((str) => str.includes('ssh-remote'));
65+
const containerAuthority = authorities.find((str) => str.includes('dev-container'));
66+
if (!sshAuthority || !containerAuthority) {
67+
return undefined;
68+
}
69+
const [, sshEncoded] = sshAuthority.split('+');
70+
if (!sshEncoded) {
71+
return undefined;
72+
}
73+
74+
const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);
75+
76+
const connectionInfo = context.globalState.get<SSHConnectionParams>(`${SSH_DEST_KEY}${sshDest.toRemoteSSHString()}`);
77+
if (connectionInfo) {
78+
return { connectionInfo, remoteUri, sshDestStr: sshDest.toRemoteSSHString() };
79+
}
80+
}
6281
if (vscode.env.remoteName === 'ssh-remote' && context.extension.extensionKind === vscode.ExtensionKind.UI && remoteUri) {
6382
const [, sshDestStr] = remoteUri.authority.split('+');
6483
const connectionInfo = context.globalState.get<SSHConnectionParams>(`${SSH_DEST_KEY}${sshDestStr}`);
@@ -97,14 +116,14 @@ export function isGitpodFlexRemoteWindow() {
97116
return /gitpod\.(local|remote)$/.test(sshDest.hostname);
98117
}
99118
if (vscode.env.remoteName === 'ssh-remote') {
100-
const [, sshEncoded] = remoteUri.authority.split('+');
101-
if (!sshEncoded) {
102-
return;
103-
}
104-
const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);
119+
const [, sshEncoded] = remoteUri.authority.split('+');
120+
if (!sshEncoded) {
121+
return;
122+
}
123+
const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);
105124

106125
return /gitpod\.(local|remote)$/.test(sshDest.hostname);
107-
}
126+
}
108127
return false;
109128
}
110129

src/remoteConnector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class RemoteConnector extends Disposable {
265265
try {
266266
this.telemetryService.sendUserFlowStatus('connecting', localSSHFlow);
267267
// If needed, revert local-app changes first
268-
await this.remoteService.updateRemoteSSHConfig();
268+
await this.remoteService.updateRemoteConfig();
269269

270270
this.remoteService.flow = sshFlow;
271271
await Promise.all([
@@ -344,7 +344,7 @@ export class RemoteConnector extends Disposable {
344344
}
345345
}
346346

347-
await this.remoteService.updateRemoteSSHConfig();
347+
await this.remoteService.updateRemoteConfig();
348348

349349
await this.context.globalState.update(`${SSH_DEST_KEY}${sshDestination!.toRemoteSSHString()}`, { ...params } as SSHConnectionParams);
350350

src/services/remoteService.ts

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface IRemoteService {
4343
getWorkspaceSSHDestination(wsData: WorkspaceData): Promise<{ destination: SSHDestination; password?: string }>;
4444
showSSHPasswordModal(wsData: WorkspaceData, password: string): Promise<void>;
4545

46-
updateRemoteSSHConfig(): Promise<void>;
46+
updateRemoteConfig(): Promise<void>;
4747
initializeRemoteExtensions(): Promise<void>;
4848
}
4949

@@ -329,19 +329,41 @@ export class RemoteService extends Disposable implements IRemoteService {
329329
throw new Error('SSH password modal dialog, Canceled');
330330
}
331331

332-
async updateRemoteSSHConfig() {
333-
const remoteSSHconfig = vscode.workspace.getConfiguration('remote.SSH');
334-
const defaultExtConfigInfo = remoteSSHconfig.inspect<string[]>('defaultExtensions');
335-
const defaultExtensions = defaultExtConfigInfo?.globalValue ?? [];
336-
if (!defaultExtensions.includes('gitpod.gitpod-remote-ssh')) {
337-
defaultExtensions.unshift('gitpod.gitpod-remote-ssh');
338-
await remoteSSHconfig.update('defaultExtensions', defaultExtensions, vscode.ConfigurationTarget.Global);
339-
}
340-
341-
const currentConfigFile = remoteSSHconfig.get<string>('configFile');
342-
if (currentConfigFile?.includes('gitpod_ssh_config')) {
343-
await remoteSSHconfig.update('configFile', undefined, vscode.ConfigurationTarget.Global);
344-
}
332+
async updateRemoteConfig() {
333+
const remoteSSHconfig = vscode.workspace.getConfiguration('remote.SSH');
334+
const defaultSSHExtConfigInfo =
335+
remoteSSHconfig.inspect<string[]>('defaultExtensions');
336+
const defaultSSHExtensions = defaultSSHExtConfigInfo?.globalValue ?? [];
337+
if (!defaultSSHExtensions.includes('gitpod.gitpod-remote-ssh')) {
338+
defaultSSHExtensions.unshift('gitpod.gitpod-remote-ssh');
339+
await remoteSSHconfig.update(
340+
'defaultExtensions',
341+
defaultSSHExtensions,
342+
vscode.ConfigurationTarget.Global,
343+
);
344+
}
345+
346+
const remoteDevContainerConfig =
347+
vscode.workspace.getConfiguration('dev.containers');
348+
const defaultDevContainerExtConfigInfo = remoteDevContainerConfig.inspect<string[]>('defaultExtensions');
349+
const defaultDevContainerExtensions = defaultDevContainerExtConfigInfo?.globalValue ?? [];
350+
if (!defaultDevContainerExtensions.includes('gitpod.gitpod-remote-ssh')) {
351+
defaultDevContainerExtensions.unshift('gitpod.gitpod-remote-ssh');
352+
await remoteDevContainerConfig.update(
353+
'defaultExtensions',
354+
defaultDevContainerExtensions,
355+
vscode.ConfigurationTarget.Global,
356+
);
357+
}
358+
359+
const currentConfigFile = remoteSSHconfig.get<string>('configFile');
360+
if (currentConfigFile?.includes('gitpod_ssh_config')) {
361+
await remoteSSHconfig.update(
362+
'configFile',
363+
undefined,
364+
vscode.ConfigurationTarget.Global,
365+
);
366+
}
345367
}
346368

347369
async initializeRemoteExtensions() {
@@ -379,9 +401,10 @@ export class RemoteService extends Disposable implements IRemoteService {
379401
throw e;
380402
}
381403
this.telemetryService.sendUserFlowStatus('synced', flowData);
382-
} catch {
404+
} catch (error) {
383405
const msg = `Error while installing local extensions on remote.`;
384406
this.logService.error(msg);
407+
this.logService.trace(error);
385408

386409
const status = 'failed';
387410
const seeLogs = 'See Logs';

0 commit comments

Comments
 (0)