Skip to content

Commit

Permalink
Dev Container heartbeats (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: jeanp413 <[email protected]>
  • Loading branch information
filiptronicek and jeanp413 authored Oct 29, 2024
1 parent 9ee2404 commit 9a22590
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/commands/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class ConnectInCurrentWindowCommand implements Command {

private async initializeLocalSSH(workspaceId: string) {
try {
await this.remoteService.updateRemoteSSHConfig();
await this.remoteService.updateRemoteConfig();
await Promise.all([
this.remoteService.setupSSHProxy(),
this.remoteService.startLocalSSHServiceServer()
Expand Down
31 changes: 25 additions & 6 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ export function getGitpodRemoteWindowConnectionInfo(context: vscode.ExtensionCon
const remoteUri = vscode.workspace.workspaceFile?.scheme !== 'untitled'
? vscode.workspace.workspaceFile || vscode.workspace.workspaceFolders?.[0].uri
: vscode.workspace.workspaceFolders?.[0].uri;
if (vscode.env.remoteName === 'dev-container' && context.extension.extensionKind === vscode.ExtensionKind.UI && remoteUri) {
const authorities = remoteUri.authority.split('@');
const sshAuthority = authorities.find((str) => str.includes('ssh-remote'));
const containerAuthority = authorities.find((str) => str.includes('dev-container'));
if (!sshAuthority || !containerAuthority) {
return undefined;
}
const [, sshEncoded] = sshAuthority.split('+');
if (!sshEncoded) {
return undefined;
}

const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);

const connectionInfo = context.globalState.get<SSHConnectionParams>(`${SSH_DEST_KEY}${sshDest.toRemoteSSHString()}`);
if (connectionInfo) {
return { connectionInfo, remoteUri, sshDestStr: sshDest.toRemoteSSHString() };
}
}
if (vscode.env.remoteName === 'ssh-remote' && context.extension.extensionKind === vscode.ExtensionKind.UI && remoteUri) {
const [, sshDestStr] = remoteUri.authority.split('+');
const connectionInfo = context.globalState.get<SSHConnectionParams>(`${SSH_DEST_KEY}${sshDestStr}`);
Expand Down Expand Up @@ -97,14 +116,14 @@ export function isGitpodFlexRemoteWindow() {
return /gitpod\.(local|remote)$/.test(sshDest.hostname);
}
if (vscode.env.remoteName === 'ssh-remote') {
const [, sshEncoded] = remoteUri.authority.split('+');
if (!sshEncoded) {
return;
}
const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);
const [, sshEncoded] = remoteUri.authority.split('+');
if (!sshEncoded) {
return;
}
const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);

return /gitpod\.(local|remote)$/.test(sshDest.hostname);
}
}
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/remoteConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class RemoteConnector extends Disposable {
try {
this.telemetryService.sendUserFlowStatus('connecting', localSSHFlow);
// If needed, revert local-app changes first
await this.remoteService.updateRemoteSSHConfig();
await this.remoteService.updateRemoteConfig();

this.remoteService.flow = sshFlow;
await Promise.all([
Expand Down Expand Up @@ -344,7 +344,7 @@ export class RemoteConnector extends Disposable {
}
}

await this.remoteService.updateRemoteSSHConfig();
await this.remoteService.updateRemoteConfig();

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

Expand Down
53 changes: 38 additions & 15 deletions src/services/remoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface IRemoteService {
getWorkspaceSSHDestination(wsData: WorkspaceData): Promise<{ destination: SSHDestination; password?: string }>;
showSSHPasswordModal(wsData: WorkspaceData, password: string): Promise<void>;

updateRemoteSSHConfig(): Promise<void>;
updateRemoteConfig(): Promise<void>;
initializeRemoteExtensions(): Promise<void>;
}

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

async updateRemoteSSHConfig() {
const remoteSSHconfig = vscode.workspace.getConfiguration('remote.SSH');
const defaultExtConfigInfo = remoteSSHconfig.inspect<string[]>('defaultExtensions');
const defaultExtensions = defaultExtConfigInfo?.globalValue ?? [];
if (!defaultExtensions.includes('gitpod.gitpod-remote-ssh')) {
defaultExtensions.unshift('gitpod.gitpod-remote-ssh');
await remoteSSHconfig.update('defaultExtensions', defaultExtensions, vscode.ConfigurationTarget.Global);
}

const currentConfigFile = remoteSSHconfig.get<string>('configFile');
if (currentConfigFile?.includes('gitpod_ssh_config')) {
await remoteSSHconfig.update('configFile', undefined, vscode.ConfigurationTarget.Global);
}
async updateRemoteConfig() {
const remoteSSHconfig = vscode.workspace.getConfiguration('remote.SSH');
const defaultSSHExtConfigInfo =
remoteSSHconfig.inspect<string[]>('defaultExtensions');
const defaultSSHExtensions = defaultSSHExtConfigInfo?.globalValue ?? [];
if (!defaultSSHExtensions.includes('gitpod.gitpod-remote-ssh')) {
defaultSSHExtensions.unshift('gitpod.gitpod-remote-ssh');
await remoteSSHconfig.update(
'defaultExtensions',
defaultSSHExtensions,
vscode.ConfigurationTarget.Global,
);
}

const remoteDevContainerConfig =
vscode.workspace.getConfiguration('dev.containers');
const defaultDevContainerExtConfigInfo = remoteDevContainerConfig.inspect<string[]>('defaultExtensions');
const defaultDevContainerExtensions = defaultDevContainerExtConfigInfo?.globalValue ?? [];
if (!defaultDevContainerExtensions.includes('gitpod.gitpod-remote-ssh')) {
defaultDevContainerExtensions.unshift('gitpod.gitpod-remote-ssh');
await remoteDevContainerConfig.update(
'defaultExtensions',
defaultDevContainerExtensions,
vscode.ConfigurationTarget.Global,
);
}

const currentConfigFile = remoteSSHconfig.get<string>('configFile');
if (currentConfigFile?.includes('gitpod_ssh_config')) {
await remoteSSHconfig.update(
'configFile',
undefined,
vscode.ConfigurationTarget.Global,
);
}
}

async initializeRemoteExtensions() {
Expand Down Expand Up @@ -379,9 +401,10 @@ export class RemoteService extends Disposable implements IRemoteService {
throw e;
}
this.telemetryService.sendUserFlowStatus('synced', flowData);
} catch {
} catch (error) {
const msg = `Error while installing local extensions on remote.`;
this.logService.error(msg);
this.logService.trace(error);

const status = 'failed';
const seeLogs = 'See Logs';
Expand Down

0 comments on commit 9a22590

Please sign in to comment.