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
260 changes: 196 additions & 64 deletions cli/golem-cli/src/app/context.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/golem-cli/src/app/manifest_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ app: demo
assert_eq!(steps.len(), 1);
assert_eq!(steps[0].path, source);
assert!(steps[0].new.contains("manifestVersion: 1.6.0"));
assert!(steps[0].new.contains("/1.6.0-dev.2/golem.schema.json"));
assert!(steps[0].new.contains("/1.6.0-dev.3/golem.schema.json"));
assert!(!steps[0].new.contains("/1.5.0/golem.schema.json"));
}

Expand Down
10 changes: 7 additions & 3 deletions cli/golem-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,9 @@ pub mod account {
}

pub mod server {
use crate::config::{
DEFAULT_LOCAL_CUSTOM_REQUEST_PORT, DEFAULT_LOCAL_MCP_PORT, DEFAULT_LOCAL_ROUTER_PORT,
};
use clap::{Args, Subcommand};
use std::path::PathBuf;

Expand Down Expand Up @@ -2356,14 +2359,15 @@ pub mod server {
}

pub fn router_port(&self) -> u16 {
self.router_port.unwrap_or(9881)
self.router_port.unwrap_or(DEFAULT_LOCAL_ROUTER_PORT)
}

pub fn custom_request_port(&self) -> u16 {
self.custom_request_port.unwrap_or(9006)
self.custom_request_port
.unwrap_or(DEFAULT_LOCAL_CUSTOM_REQUEST_PORT)
}
pub fn mcp_port(&self) -> u16 {
self.mcp_port.unwrap_or(9007)
self.mcp_port.unwrap_or(DEFAULT_LOCAL_MCP_PORT)
}
}

Expand Down
19 changes: 14 additions & 5 deletions cli/golem-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ use std::time::Duration;
use url::Url;
use uuid::Uuid;

pub const CLOUD_URL: &str = "https://release.api.golem.cloud";
const BUILTIN_LOCAL_URL: &str = "http://localhost:9881";
pub const DEFAULT_LOCAL_ROUTER_PORT: u16 = 9881;
pub const DEFAULT_LOCAL_CUSTOM_REQUEST_PORT: u16 = 9006;
pub const DEFAULT_LOCAL_MCP_PORT: u16 = 9007;

pub const DEFAULT_LOCAL_URL: &str = "http://localhost:9881";
pub const DEFAULT_CLOUD_URL: &str = "https://release.api.golem.cloud";

pub const CLOUD_HTTP_API_DOMAIN: &str = "apps.golem.cloud";
pub const CLOUD_MCP_DOMAIN: &str = "mcps.golem.cloud";

const BUILTIN_LOCAL_URL_ENV: &str = "GOLEM_BUILTIN_LOCAL_URL";
const PROFILE_NAME_LOCAL: &str = "local";
const PROFILE_NAME_CLOUD: &str = "cloud";
Expand All @@ -58,7 +66,7 @@ fn builtin_local_url_state() -> &'static BuiltinLocalUrlState {
}

BuiltinLocalUrlState {
url: Url::parse(BUILTIN_LOCAL_URL).expect("Failed to parse BUILTIN_LOCAL_URL"),
url: Url::parse(DEFAULT_LOCAL_URL).expect("Failed to parse DEFAULT_LOCAL_URL"),
uses_default: true,
}
})
Expand Down Expand Up @@ -331,7 +339,7 @@ pub struct ClientConfig {

impl From<&Profile> for ClientConfig {
fn from(profile: &Profile) -> Self {
let default_cloud_url = Url::parse(CLOUD_URL).unwrap();
let default_cloud_url = Url::parse(DEFAULT_CLOUD_URL).unwrap();
let registry_url = profile.custom_url.clone().unwrap_or(default_cloud_url);
let worker_url = profile
.custom_worker_url
Expand Down Expand Up @@ -373,7 +381,8 @@ impl From<&Server> for ClientConfig {
allow_insecure: false,
},
BuiltinServer::Cloud => {
let cloud_url = Url::parse(CLOUD_URL).expect("Failed to parse CLOUD_URL");
let cloud_url =
Url::parse(DEFAULT_CLOUD_URL).expect("Failed to parse DEFAULT_CLOUD_URL");
BaseConfig {
registry_url: cloud_url.clone(),
worker_url: cloud_url.clone(),
Expand Down
83 changes: 46 additions & 37 deletions cli/golem-cli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use crate::config::{
use crate::config::{ClientConfig, ProfileName, builtin_local_url};
use crate::error::{ContextInitHintError, HintError, NonSuccessfulExit};
use crate::log::{LogColorize, LogOutput, Output, log_action, set_log_output};
use crate::model::app::{ApplicationConfig, ComponentPresetSelector};
use crate::model::app::{
ApplicationNameAndEnvironments, ApplicationSourceMode, ComponentPresetName, WithSource,
ApplicationConfig, ApplicationPreload, ApplicationSourceMode, ComponentPresetName,
ComponentPresetSelector, ResolvedLocalServer, WithSource,
};
use crate::model::app_raw::{
BuiltinServer, CustomServerAuth, DeploymentOptions, Environment, Marker, Server,
Expand Down Expand Up @@ -68,6 +68,7 @@ pub struct Context {
environment_reference: Option<EnvironmentReference>,
manifest_environment: Option<SelectedManifestEnvironment>,
manifest_environment_deployment_options: Option<DeploymentOptions>,
manifest_local_server: Option<ResolvedLocalServer>,
app_context_config: Option<ApplicationContextConfig>,
http_batch_size: u64,
http_parallelism: usize,
Expand Down Expand Up @@ -146,17 +147,19 @@ impl Context {
}

let app_source_mode = preloaded_app.source_mode;
let application_name_and_environments = preloaded_app.application_name_and_environments;
let manifest_local_server = preloaded_app.resolved_local_server;
let application_preload = preloaded_app.application_preload;

let manifest_environment: Option<SelectedManifestEnvironment> = match &environment_reference
{
Some(environment_reference) => {
match environment_reference {
EnvironmentReference::Environment { environment_name } => {
match &application_name_and_environments {
Some(ApplicationNameAndEnvironments {
match &application_preload {
Some(ApplicationPreload {
application_name,
environments,
..
}) => match environments.get(environment_name) {
Some(environment) => Some(SelectedManifestEnvironment {
application_name: application_name.value.clone(),
Expand Down Expand Up @@ -188,10 +191,11 @@ impl Context {
EnvironmentReference::AccountApplicationEnvironment { .. } => None,
}
}
None => match &application_name_and_environments {
Some(ApplicationNameAndEnvironments {
None => match &application_preload {
Some(ApplicationPreload {
application_name,
environments,
..
}) => environments
.iter()
.find(|(_, env)| env.default == Some(Marker))
Expand Down Expand Up @@ -283,34 +287,31 @@ impl Context {
let file_download_client =
new_raw_reqwest_client(&client_config.file_download_http_client_config)?;

let app_context_config = manifest_environment
.as_ref()
.zip(application_name_and_environments)
.map(
|(selected_environment, application_name_and_environments)| {
ApplicationContextConfig::new(
&global_flags,
application_name_and_environments,
ComponentPresetSelector {
environment: selected_environment.environment_name.clone(),
presets: {
if global_flags.preset.is_empty() {
selected_environment
.environment
.component_presets
.clone()
.into_vec()
.into_iter()
.map(ComponentPresetName)
.collect::<Vec<_>>()
} else {
global_flags.preset.clone()
}
},
let app_context_config = manifest_environment.as_ref().zip(application_preload).map(
|(selected_environment, application_preload)| {
ApplicationContextConfig::new(
&global_flags,
application_preload,
ComponentPresetSelector {
environment: selected_environment.environment_name.clone(),
presets: {
if global_flags.preset.is_empty() {
selected_environment
.environment
.component_presets
.clone()
.into_vec()
.into_iter()
.map(ComponentPresetName)
.collect::<Vec<_>>()
} else {
global_flags.preset.clone()
}
},
)
},
);
},
)
},
);

Ok(Self {
config_dir: global_flags.config_dir(),
Expand All @@ -325,6 +326,7 @@ impl Context {
environment_reference,
manifest_environment,
manifest_environment_deployment_options,
manifest_local_server,
yes,
dev_mode: global_flags.dev_mode,
show_secrets: global_flags.show_secrets,
Expand Down Expand Up @@ -413,6 +415,10 @@ impl Context {
self.manifest_environment_deployment_options.as_ref()
}

pub fn manifest_local_server(&self) -> Option<&ResolvedLocalServer> {
self.manifest_local_server.as_ref()
}

pub fn caches(&self) -> &Caches {
&self.caches
}
Expand Down Expand Up @@ -675,6 +681,7 @@ struct ApplicationContextConfig {
disable_app_manifest_discovery: bool,
application_name: WithSource<ApplicationName>,
environments: BTreeMap<EnvironmentName, Environment>,
local_server: Option<WithSource<crate::model::app_raw::LocalServer>>,
component_presets: ComponentPresetSelector,
wasm_rpc_client_build_offline: bool,
dev_mode: bool,
Expand All @@ -684,14 +691,15 @@ struct ApplicationContextConfig {
impl ApplicationContextConfig {
pub fn new(
global_flags: &GolemCliGlobalFlags,
application_name_and_environments: ApplicationNameAndEnvironments,
application_preload: ApplicationPreload,
component_presets: ComponentPresetSelector,
) -> Self {
Self {
app_manifest_path: global_flags.app_manifest_path.clone(),
disable_app_manifest_discovery: global_flags.disable_app_manifest_discovery,
application_name: application_name_and_environments.application_name,
environments: application_name_and_environments.environments,
application_name: application_preload.application_name,
environments: application_preload.environments,
local_server: application_preload.local_server,
component_presets,
wasm_rpc_client_build_offline: global_flags.wasm_rpc_offline,
dev_mode: global_flags.dev_mode,
Expand Down Expand Up @@ -781,6 +789,7 @@ impl ApplicationContextState {
app_config,
config.application_name.clone(),
config.environments.clone(),
config.local_server.clone(),
config.component_presets.clone(),
file_download_client.clone(),
)
Expand Down
Loading
Loading