Skip to content

Commit 5dee58c

Browse files
committed
Unify dstack agent address getter
1 parent 797c5d2 commit 5dee58c

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dstack-types/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,12 @@ impl KeyProviderInfo {
133133
}
134134

135135
pub mod shared_filenames;
136+
137+
/// Get the address of the dstack agent
138+
pub fn dstack_agent_address() -> String {
139+
// Check env DSTACK_AGENT_ADDRESS
140+
if let Ok(address) = std::env::var("DSTACK_AGENT_ADDRESS") {
141+
return address;
142+
}
143+
"unix:/var/run/dstack.sock".into()
144+
}

gateway/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ra-tls.workspace = true
4040
dstack-guest-agent-rpc.workspace = true
4141
http-client = { workspace = true, features = ["prpc"] }
4242
sha2.workspace = true
43+
dstack-types.workspace = true
4344

4445
[target.'cfg(unix)'.dependencies]
4546
nix = { workspace = true, features = ["resource"] }

gateway/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, bail, Context, Result};
1+
use anyhow::{anyhow, Context, Result};
22
use clap::Parser;
33
use config::{Config, TlsConfig};
44
use dstack_guest_agent_rpc::{dstack_guest_client::DstackGuestClient, GetTlsKeyArgs};
@@ -49,11 +49,8 @@ fn set_max_ulimit() -> Result<()> {
4949
}
5050

5151
fn dstack_agent() -> Result<DstackGuestClient<PrpcClient>> {
52-
let uds_path = "/var/run/dstack.sock";
53-
if !std::fs::exists(uds_path).unwrap_or_default() {
54-
bail!("dstack socket({uds_path}) not found");
55-
}
56-
let http_client = PrpcClient::new_unix(uds_path.to_string(), "/prpc".to_string());
52+
let address = dstack_types::dstack_agent_address();
53+
let http_client = PrpcClient::new(address);
5754
Ok(DstackGuestClient::new(http_client))
5855
}
5956

http-client/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ pub async fn http_request(
3333
) -> Result<(u16, Vec<u8>)> {
3434
debug!("Sending HTTP request to {base}, path={path}");
3535
let mut response = if base.starts_with("unix:") {
36+
let path = if path.starts_with("/") {
37+
path.to_string()
38+
} else {
39+
format!("/{path}")
40+
};
3641
let client: Client<UnixConnector, Full<Bytes>> = Client::unix();
37-
let unix_uri: hyper::Uri = Uri::new(base.strip_prefix("unix:").unwrap(), path).into();
42+
let unix_uri: hyper::Uri = Uri::new(base.strip_prefix("unix:").unwrap(), &path).into();
3843
let req = Request::builder()
3944
.method(method)
4045
.uri(unix_uri)

kms/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ x509-parser = { workspace = true, features = ["verify"] }
3737
ring.workspace = true
3838
safe-write.workspace = true
3939
serde_json.workspace = true
40+
dstack-types.workspace = true
4041

4142
[features]
4243
default = []

kms/src/onboard_service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ pub(crate) async fn bootstrap_keys(cfg: &KmsConfig) -> Result<()> {
241241
}
242242

243243
fn dstack_client() -> DstackGuestClient<PrpcClient> {
244-
let http_client = PrpcClient::new_unix("/var/run/dstack.sock".into(), "/prpc".into());
244+
let address = dstack_types::dstack_agent_address();
245+
let http_client = PrpcClient::new(address);
245246
DstackGuestClient::new(http_client)
246247
}
247248

0 commit comments

Comments
 (0)