Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use candid::{CandidType, Principal};
use clap::Args;
use futures::{StreamExt, future::try_join_all, stream::FuturesOrdered};
use ic_agent::Agent;
use icp::network::{Managed, ManagedMode};
use icp::parsers::CyclesAmount;
use icp::{
context::{CanisterSelection, Context, EnvironmentSelection},
Expand Down Expand Up @@ -385,24 +384,16 @@ async fn print_canister_urls(
let env = ctx.get_environment(environment_selection).await?;

// Get the network URL
let http_gateway_url = match &env.network.configuration {
let (http_gateway_url, has_friendly) = match &env.network.configuration {
NetworkConfiguration::Managed { managed: _ } => {
let access = ctx.network.access(&env.network).await?;
access.http_gateway_url.clone()
(access.http_gateway_url.clone(), access.use_friendly_domains)
}
NetworkConfiguration::Connected { connected } => {
(connected.http_gateway_url.clone(), false)
}
NetworkConfiguration::Connected { connected } => connected.http_gateway_url.clone(),
};

// Friendly domains are available for managed networks where we write custom-domains.txt
let has_friendly = matches!(
&env.network.configuration,
NetworkConfiguration::Managed {
managed: Managed {
mode: ManagedMode::Launcher(config)
}
} if config.version.is_none()
);

let _ = ctx.term.write_line("\n\nDeployed canisters:");

for name in canister_names {
Expand Down
11 changes: 11 additions & 0 deletions crates/icp/src/context/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ async fn test_get_agent_for_env_uses_environment_network() {
root_key: local_root_key.clone(),
api_url: Url::parse("http://localhost:8000").unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
)
.with_network(
Expand All @@ -359,6 +360,7 @@ async fn test_get_agent_for_env_uses_environment_network() {
root_key: staging_root_key.clone(),
api_url: Url::parse("http://staging:9000").unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
),
),
Expand Down Expand Up @@ -432,6 +434,7 @@ async fn test_get_agent_for_network_success() {
root_key: root_key.clone(),
api_url: Url::parse("http://localhost:8000").unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
)),
..Context::mocked()
Expand Down Expand Up @@ -645,6 +648,7 @@ async fn test_get_agent_defaults_inside_project_with_default_local() {
root_key: local_root_key.clone(),
api_url: Url::parse(DEFAULT_LOCAL_NETWORK_URL).unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
)),
..Context::mocked()
Expand Down Expand Up @@ -717,6 +721,7 @@ async fn test_get_agent_defaults_with_overridden_local_network() {
root_key: custom_root_key.clone(),
api_url: Url::parse("http://localhost:9000").unwrap(), // Custom port
http_gateway_url: None,
use_friendly_domains: false,
},
)),
..Context::mocked()
Expand Down Expand Up @@ -816,6 +821,7 @@ async fn test_get_agent_defaults_with_overridden_local_environment() {
root_key: local_root_key.clone(),
api_url: Url::parse(DEFAULT_LOCAL_NETWORK_URL).unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
)
.with_network(
Expand All @@ -824,6 +830,7 @@ async fn test_get_agent_defaults_with_overridden_local_environment() {
root_key: custom_root_key.clone(),
api_url: Url::parse("http://localhost:7000").unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
),
),
Expand Down Expand Up @@ -858,6 +865,7 @@ async fn test_get_agent_explicit_network_inside_project() {
root_key: local_root_key.clone(),
api_url: Url::parse(DEFAULT_LOCAL_NETWORK_URL).unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
)
.with_network(
Expand All @@ -866,6 +874,7 @@ async fn test_get_agent_explicit_network_inside_project() {
root_key: staging_root_key.clone(),
api_url: Url::parse("http://localhost:8001").unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
),
),
Expand Down Expand Up @@ -901,6 +910,7 @@ async fn test_get_agent_explicit_environment_inside_project() {
root_key: local_root_key.clone(),
api_url: Url::parse(DEFAULT_LOCAL_NETWORK_URL).unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
)
.with_network(
Expand All @@ -909,6 +919,7 @@ async fn test_get_agent_explicit_environment_inside_project() {
root_key: staging_root_key.clone(),
api_url: Url::parse("http://localhost:8001").unwrap(),
http_gateway_url: None,
use_friendly_domains: false,
},
),
),
Expand Down
6 changes: 5 additions & 1 deletion crates/icp/src/network/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ pub struct NetworkAccess {

/// Routing configuration
pub api_url: Url,

pub http_gateway_url: Option<Url>,

/// If true, use friendly canister names with the gateway url
pub use_friendly_domains: bool,
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -81,6 +83,7 @@ pub async fn get_managed_network_access(
root_key: desc.root_key,
api_url: http_gateway_url.clone(),
http_gateway_url: Some(http_gateway_url),
use_friendly_domains: desc.use_friendly_domains,
})
}

Expand All @@ -93,5 +96,6 @@ pub async fn get_connected_network_access(
root_key,
api_url: connected.api_url.clone(),
http_gateway_url: connected.http_gateway_url.clone(),
use_friendly_domains: false,
})
}
3 changes: 3 additions & 0 deletions crates/icp/src/network/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub struct NetworkDescriptorModel {
/// Used to write `custom-domains.txt` for friendly domain routing.
#[serde(default)]
pub status_dir: Option<PathBuf>,
/// Whether the network supports friendly domain routing (e.g., `foo.local.localhost`).
#[serde(default)]
pub use_friendly_domains: bool,
}

/// Identifies the process or container running a managed network.
Expand Down
8 changes: 7 additions & 1 deletion crates/icp/src/network/managed/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use tokio::select;
use wslpath2::Conversion;

use crate::network::{
ManagedImageConfig, config::ChildLocator, managed::launcher::NetworkInstance,
ManagedImageConfig,
config::ChildLocator,
managed::launcher::{CUSTOM_DOMAINS_FEATURE, NetworkInstance},
};
use crate::prelude::*;

Expand Down Expand Up @@ -499,6 +501,10 @@ pub async fn spawn_docker_launcher(
root_key: hex::decode(&launcher_status.root_key).context(ParseRootKeySnafu {
key: &launcher_status.root_key,
})?,
use_friendly_domains: launcher_status
.supported_features
.iter()
.any(|f| f == CUSTOM_DOMAINS_FEATURE),
},
locator,
gateway_port_was_fixed,
Expand Down
9 changes: 9 additions & 0 deletions crates/icp/src/network/managed/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct NetworkInstance {
pub root_key: Vec<u8>,
pub pocketic_config_port: Option<u16>,
pub pocketic_instance_id: Option<usize>,
pub use_friendly_domains: bool,
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -141,6 +142,10 @@ pub async fn spawn_network_launcher(
})?,
pocketic_config_port: launcher_status.config_port,
pocketic_instance_id: launcher_status.instance_id,
use_friendly_domains: launcher_status
.supported_features
.iter()
.any(|f| f == CUSTOM_DOMAINS_FEATURE),
},
ChildLocator::Pid { pid, start_time },
))
Expand Down Expand Up @@ -357,8 +362,12 @@ pub struct LauncherStatus {
pub gateway_port: u16,
pub root_key: String,
pub default_effective_canister_id: Option<Principal>,
#[serde(default)]
pub supported_features: Vec<String>,
}

pub const CUSTOM_DOMAINS_FEATURE: &str = "custom-domains";

struct WatchRecv(Sender<notify::Result<notify::Event>>);

impl EventHandler for WatchRecv {
Expand Down
1 change: 1 addition & 0 deletions crates/icp/src/network/managed/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ async fn run_network_launcher(
candid_ui_canister_id,
proxy_canister_id,
status_dir: Some(status_dir_path.clone()),
use_friendly_domains: instance.use_friendly_domains,
};

// Save descriptor to project root and all fixed port directories
Expand Down