From da531a361aed5aa1138b4101515579b44353d29a Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Thu, 22 Aug 2024 11:53:39 +0800 Subject: [PATCH] feat: install vscode-server and devstar in remote container when first connecting --- src/remote-container.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/remote-container.ts b/src/remote-container.ts index 075a3e6..bcaafa6 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -16,6 +16,11 @@ export default class RemoteContainer { // first connect to the remote host using password const ssh = new NodeSSH(); + vscode.window.withProgress({ + location: vscode.ProgressLocation.Notification, + title: "正在容器中安装vscode-server及devstar插件", + cancellable: false + }, async (progress) => { try { await ssh.connect({ host: host, @@ -23,10 +28,32 @@ export default class RemoteContainer { password: password, port: port }); + progress.report({ message: "连接成功,开始安装" }); + + // install vscode-server and devstar extension + const vscodeCommitId = await utils.getVsCodeCommitId(); + const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz` + const installVscodeServerScript = ` + mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\ + if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then + ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar + else + wget ${vscodeServerUrl} -O vscode-server-linux-x64.tar.gz && \\ + mv vscode-server-linux-x64.tar.gz ~/.vscode-server/bin/${vscodeCommitId} && \\ + cd ~/.vscode-server/bin/${vscodeCommitId} && \\ + tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1 && \\ + rm vscode-server-linux-x64.tar.gz && \\ + ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar + fi + `; + await ssh.execCommand(installVscodeServerScript); + console.log("vscode-server and extension installed"); + vscode.window.showInformationMessage('安装完成!'); // add the public key to the remote authorized_keys await ssh.execCommand(`mkdir -p ~/.ssh && echo '${publicKey}' >> ~/.ssh/authorized_keys`); console.log('Public key added to remote authorized_keys'); + await ssh.dispose(); // only connect successfully then save the host info @@ -44,7 +71,7 @@ export default class RemoteContainer { console.error('Error adding public key: ', error); await ssh.dispose(); reject("failed"); - } + }}); }); }