ssh remoting: Add setting to download binary on host (#19606)

This adds the following optional setting:

```json
{
  "remote_server": {
    "download_on_host": false
  }
}
```
Right now, it's **off by default** because I haven't tested it enough.

Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-10-23 16:06:16 +02:00 committed by GitHub
parent c292bdd2ca
commit bce1b7a10a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 207 additions and 41 deletions

View file

@ -14,6 +14,7 @@ use gpui::{AppContext, Model};
use language::CursorShape;
use markdown::{Markdown, MarkdownStyle};
use release_channel::{AppVersion, ReleaseChannel};
use remote::ssh_session::ServerBinary;
use remote::{SshConnectionOptions, SshPlatform, SshRemoteClient};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@ -25,9 +26,15 @@ use ui::{
};
use workspace::{AppState, ModalView, Workspace};
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct RemoteServerSettings {
pub download_on_host: Option<bool>,
}
#[derive(Deserialize)]
pub struct SshSettings {
pub ssh_connections: Option<Vec<SshConnection>>,
pub remote_server: Option<RemoteServerSettings>,
}
impl SshSettings {
@ -107,6 +114,7 @@ pub struct SshProject {
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct RemoteSettingsContent {
pub ssh_connections: Option<Vec<SshConnection>>,
pub remote_server: Option<RemoteServerSettings>,
}
impl Settings for SshSettings {
@ -435,7 +443,7 @@ impl remote::SshClientDelegate for SshClientDelegate {
&self,
platform: SshPlatform,
cx: &mut AsyncAppContext,
) -> oneshot::Receiver<Result<(PathBuf, SemanticVersion)>> {
) -> oneshot::Receiver<Result<(ServerBinary, SemanticVersion)>> {
let (tx, rx) = oneshot::channel();
let this = self.clone();
cx.spawn(|mut cx| async move {
@ -476,10 +484,18 @@ impl SshClientDelegate {
&self,
platform: SshPlatform,
cx: &mut AsyncAppContext,
) -> Result<(PathBuf, SemanticVersion)> {
let (version, release_channel) = cx.update(|cx| {
let global = AppVersion::global(cx);
(global, ReleaseChannel::global(cx))
) -> Result<(ServerBinary, SemanticVersion)> {
let (version, release_channel, download_binary_on_host) = cx.update(|cx| {
let version = AppVersion::global(cx);
let channel = ReleaseChannel::global(cx);
let ssh_settings = SshSettings::get_global(cx);
let download_binary_on_host = ssh_settings
.remote_server
.as_ref()
.and_then(|server| server.download_on_host)
.unwrap_or(false);
(version, channel, download_binary_on_host)
})?;
// In dev mode, build the remote server binary from source
@ -487,29 +503,55 @@ impl SshClientDelegate {
if release_channel == ReleaseChannel::Dev {
let result = self.build_local(cx, platform, version).await?;
// Fall through to a remote binary if we're not able to compile a local binary
if let Some(result) = result {
return Ok(result);
if let Some((path, version)) = result {
return Ok((ServerBinary::LocalBinary(path), version));
}
}
self.update_status(Some("checking for latest version of remote server"), cx);
let binary_path = AutoUpdater::get_latest_remote_server_release(
platform.os,
platform.arch,
release_channel,
cx,
)
.await
.map_err(|e| {
anyhow!(
"failed to download remote server binary (os: {}, arch: {}): {}",
if download_binary_on_host {
let (request_url, request_body) = AutoUpdater::get_latest_remote_server_release_url(
platform.os,
platform.arch,
e
release_channel,
cx,
)
})?;
.await
.map_err(|e| {
anyhow!(
"failed to get remote server binary download url (os: {}, arch: {}): {}",
platform.os,
platform.arch,
e
)
})?;
Ok((binary_path, version))
Ok((
ServerBinary::ReleaseUrl {
url: request_url,
body: request_body,
},
version,
))
} else {
self.update_status(Some("checking for latest version of remote server"), cx);
let binary_path = AutoUpdater::get_latest_remote_server_release(
platform.os,
platform.arch,
release_channel,
cx,
)
.await
.map_err(|e| {
anyhow!(
"failed to download remote server binary (os: {}, arch: {}): {}",
platform.os,
platform.arch,
e
)
})?;
Ok((ServerBinary::LocalBinary(binary_path), version))
}
}
#[cfg(debug_assertions)]
@ -517,8 +559,8 @@ impl SshClientDelegate {
&self,
cx: &mut AsyncAppContext,
platform: SshPlatform,
version: SemanticVersion,
) -> Result<Option<(PathBuf, SemanticVersion)>> {
version: gpui::SemanticVersion,
) -> Result<Option<(PathBuf, gpui::SemanticVersion)>> {
use smol::process::{Command, Stdio};
async fn run_cmd(command: &mut Command) -> Result<()> {