diff --git a/golem/src/command.rs b/golem/src/command.rs index e695ed957..cfb06cdfb 100644 --- a/golem/src/command.rs +++ b/golem/src/command.rs @@ -24,6 +24,10 @@ use std::path::PathBuf; pub enum SingleExecutableCommand { #[clap(name = "start", about = "Start a golem server for local development")] Start { + /// Address to serve the main API on + #[clap(long, default_value = "0.0.0.0")] + router_addr: String, + /// Port to serve the main API on #[clap(long, default_value_t = 9881)] router_port: u16, @@ -46,6 +50,7 @@ impl CliCommand for SingleExecutableCommand { async fn run(self, _ctx: Ctx) -> Result { match self { SingleExecutableCommand::Start { + router_addr: router_host, router_port, custom_request_port, data_dir, @@ -63,6 +68,7 @@ impl CliCommand for SingleExecutableCommand { }; match launch_golem_services(&LaunchArgs { + router_host, router_port, custom_request_port, data_dir, diff --git a/golem/src/launch.rs b/golem/src/launch.rs index 2483d1e26..472b3c8ac 100644 --- a/golem/src/launch.rs +++ b/golem/src/launch.rs @@ -49,6 +49,7 @@ use tracing::Instrument; use crate::proxy; pub struct LaunchArgs { + pub router_host: String, pub router_port: u16, pub custom_request_port: u16, pub data_dir: PathBuf, @@ -110,6 +111,7 @@ pub async fn launch_golem_services(args: &LaunchArgs) -> Result<(), anyhow::Erro // Don't drop the channel, it will cause the proxy to fail let _proxy_command_channel = proxy::start_proxy( + &args.router_host, args.router_port, healthcheck_port, &all_run_details, @@ -188,14 +190,14 @@ fn worker_executor_config( blob_storage: blob_storage_config(args), component_service: golem_worker_executor_base::services::golem_config::ComponentServiceConfig::Grpc( ComponentServiceGrpcConfig { - host: "127.0.0.1".to_string(), + host: args.router_host.clone(), port: component_service_run_details.grpc_port, ..ComponentServiceGrpcConfig::default() } ), compiled_component_service: CompiledComponentServiceConfig::Disabled(golem_worker_executor_base::services::golem_config::CompiledComponentServiceDisabledConfig { }), shard_manager_service: ShardManagerServiceConfig::Grpc(ShardManagerServiceGrpcConfig { - host: "127.0.0.1".to_string(), + host: args.router_host.clone(), port: shard_manager_run_details.grpc_port, ..ShardManagerServiceGrpcConfig::default() }), @@ -236,12 +238,12 @@ fn worker_service_config( ), blob_storage: blob_storage_config(args), component_service: golem_worker_service_base::app_config::ComponentServiceConfig { - host: "127.0.0.1".to_string(), + host: args.router_host.clone(), port: component_service_run_details.grpc_port, ..golem_worker_service_base::app_config::ComponentServiceConfig::default() }, routing_table: RoutingTableConfig { - host: "127.0.0.1".to_string(), + host: args.router_host.clone(), port: shard_manager_run_details.grpc_port, ..RoutingTableConfig::default() }, diff --git a/golem/src/proxy.rs b/golem/src/proxy.rs index 92b0ac26e..5e1348d8c 100644 --- a/golem/src/proxy.rs +++ b/golem/src/proxy.rs @@ -22,12 +22,14 @@ use sozu_command_lib::{ RequestHttpFrontend, RulePosition, SocketAddress, WorkerRequest, }, }; +use std::net::Ipv4Addr; use tokio::task::JoinSet; use tracing::info; use crate::AllRunDetails; pub fn start_proxy( + listener_addr: &str, listener_port: u16, healthcheck_port: u16, all_run_details: &AllRunDetails, @@ -35,9 +37,18 @@ pub fn start_proxy( ) -> Result, anyhow::Error> { info!("Starting proxy"); - let listener_address = SocketAddress::new_v4(127, 0, 0, 1, listener_port); - - let http_listener = ListenerBuilder::new_http(listener_address).to_http(None)?; + let ipv4_addr: Ipv4Addr = listener_addr.parse().context(format!( + "Failed at parsing the listener host address {}", + listener_addr + ))?; + let listener_socket_addr = SocketAddress::new_v4( + ipv4_addr.octets()[0], + ipv4_addr.octets()[1], + ipv4_addr.octets()[2], + ipv4_addr.octets()[3], + listener_port, + ); + let http_listener = ListenerBuilder::new_http(listener_socket_addr).to_http(None)?; let (mut command_channel, proxy_channel) = Channel::generate(1000, 10000).with_context(|| "should create a channel")?; @@ -86,7 +97,13 @@ pub fn start_proxy( content: RequestType::AddBackend(AddBackend { cluster_id: name.to_string(), backend_id: name.to_string(), - address: SocketAddress::new_v4(127, 0, 0, 1, port), + address: SocketAddress::new_v4( + ipv4_addr.octets()[0], + ipv4_addr.octets()[1], + ipv4_addr.octets()[2], + ipv4_addr.octets()[3], + port, + ), ..Default::default() }) .into(), @@ -110,7 +127,7 @@ pub fn start_proxy( id: format!("add-golem-frontend-${route_counter}"), content: RequestType::AddHttpFrontend(RequestHttpFrontend { cluster_id: Some(cluster_id.to_string()), - address: SocketAddress::new_v4(127, 0, 0, 1, listener_port), + address: listener_socket_addr, hostname: "*".to_string(), path, position: RulePosition::Post.into(),