diff --git a/liborchestra/src/lib/hosts/mod.rs b/liborchestra/src/lib/hosts/mod.rs index 79e225f65331c77420e12cf0d91bb16a1c073fda..fa19973d43e7649d6ec106dcd1f73e364eb26b38 100644 --- a/liborchestra/src/lib/hosts/mod.rs +++ b/liborchestra/src/lib/hosts/mod.rs @@ -338,7 +338,7 @@ struct Host { impl Host { // Builds a host from a configuration. #[instrument(name="Host::from_conf")] - fn from_conf(conf: HostConf) -> Result { + fn from_conf(conf: HostConf, context: FrontendContext) -> Result { trace!("Loading from conf"); // We retrieve the ssh profile from the configuration let profile = ssh::config::get_profile( @@ -351,7 +351,7 @@ impl Host { trace!(?conn, "Connection to frontend acquired"); // We generate the host - let mut context = FrontendContext(TerminalContext::default()); + let mut context = context; context.0.envs.insert(EnvironmentKey("RUNAWAY_PATH".into()), EnvironmentValue(conf.directory.to_str().unwrap().into())); Ok(Host { @@ -542,8 +542,8 @@ pub struct HostHandle { impl HostHandle { /// This function spawns the thread that will handle all the repository operations using the /// CampaignResource, and returns a handle to it. - pub fn spawn(host_conf: HostConf) -> Result { - let host = Host::from_conf(host_conf.clone())?; + pub fn spawn(host_conf: HostConf, context: TerminalContext) -> Result { + let host = Host::from_conf(host_conf.clone(), FrontendContext(context))?; let conn = host.conn.clone(); let (sender, receiver) = mpsc::unbounded(); let handle = thread::Builder::new().name("host".into()) @@ -990,8 +990,10 @@ mod test { execution: vec!["$RUNAWAY_COMMAND".to_owned()], directory: path::PathBuf::from("/projets/flowers/alex/executions"), }; + - let res_handle = HostHandle::spawn(conf).unwrap(); + let context = TerminalContext::default(); + let res_handle = HostHandle::spawn(conf, context).unwrap(); // We test environment of first connection let conn1 = { @@ -1080,7 +1082,10 @@ mod test { directory: path::PathBuf::from("/projets/flowers/alex/executions"), }; - let res_handle = HostHandle::spawn(conf).unwrap(); + + let context = TerminalContext::default(); + + let res_handle = HostHandle::spawn(conf, context).unwrap(); async fn test(res: HostHandle) { let conn = res.async_acquire().await.unwrap(); diff --git a/runaway-cli/src/misc.rs b/runaway-cli/src/misc.rs index bc2c29503de444f1c21d2b4ec9413709c38be657..0b76f8fb04f649d80183f84024604ae5c96c30f9 100644 --- a/runaway-cli/src/misc.rs +++ b/runaway-cli/src/misc.rs @@ -18,7 +18,7 @@ use clap; use crate::exit::Exit; use crate::logger::EchoSubscriber; use liborchestra::primitives::{read_globs_from_file, list_local_folder, Glob}; -use liborchestra::commons::{EnvironmentStore, EnvironmentKey, EnvironmentValue}; +use liborchestra::commons::{EnvironmentStore, EnvironmentKey, EnvironmentValue, TerminalContext}; use liborchestra::scheduler::SchedulerHandle; use itertools::Itertools; use tracing::{self, info, error}; @@ -96,10 +96,12 @@ macro_rules! try_return_err { /// Allows to load host from a host path configuration -pub fn get_host(host_name: &str) -> Result{ +pub fn get_host(host_name: &str, envs: EnvironmentStore) -> Result{ let host_path = get_host_path(host_name); + let mut context = TerminalContext::default(); + context.envs = envs; let config = to_exit!(HostConf::from_file(&host_path), Exit::LoadHostConfiguration)?; - to_exit!(HostHandle::spawn(config), Exit::SpawnHost) + to_exit!(HostHandle::spawn(config, context), Exit::SpawnHost) } /// Allows to generate globs from send and fetch ignore file. diff --git a/runaway-cli/src/subcommands/batch.rs b/runaway-cli/src/subcommands/batch.rs index e3ad28c0316b4313624ddd4b8b3680a6f4f9bff8..cc008fad864f9f671591df1f528517478f325f2b 100644 --- a/runaway-cli/src/subcommands/batch.rs +++ b/runaway-cli/src/subcommands/batch.rs @@ -58,7 +58,7 @@ pub fn batch(matches: clap::ArgMatches<'static>) -> Result{ // We load the host info!("Loading host"); - let host = misc::get_host(matches.value_of("REMOTE").unwrap())?; + let host = misc::get_host(matches.value_of("REMOTE").unwrap(), store.clone())?; push_env(&mut store, "RUNAWAY_REMOTE", host.get_name()); debug!("Host {} loaded", host); diff --git a/runaway-cli/src/subcommands/exec.rs b/runaway-cli/src/subcommands/exec.rs index 5484a53dacb1105330d646974a91e13222460c53..68d34b2c7f6b85ae3829b557022fa46ab3ae88b5 100644 --- a/runaway-cli/src/subcommands/exec.rs +++ b/runaway-cli/src/subcommands/exec.rs @@ -38,9 +38,18 @@ pub fn exec(matches: clap::ArgMatches) -> Result{ // We create the store that will keep env vars let mut store = EnvironmentStore::new(); + // We read the envs to the store. + if !matches.is_present("no-env-read"){ + let envs = misc::read_local_runaway_envs(); + debug!("Local environment variables captured: {}", envs.iter() + .fold(String::new(), |mut acc, (k, v)| {acc.push_str(&format!("\n{:?}={:?}", k, v)); acc})); + envs.into_iter() + .for_each(|(k, v)| {push_env(&mut store, k.0, v.0);}); + } + // We load the host info!("Loading host"); - let host = misc::get_host(matches.value_of("REMOTE").unwrap())?; + let host = misc::get_host(matches.value_of("REMOTE").unwrap(), store.clone())?; push_env(&mut store, "RUNAWAY_REMOTE", host.get_name()); debug!("Host {:?} loaded", host); diff --git a/runaway-cli/src/subcommands/sched.rs b/runaway-cli/src/subcommands/sched.rs index 55dbdfd13115a349b64b48114da697148f5c95dd..5443f24a419f5bb66a1aa079546a1d78ccee99e7 100644 --- a/runaway-cli/src/subcommands/sched.rs +++ b/runaway-cli/src/subcommands/sched.rs @@ -58,7 +58,7 @@ pub fn sched(matches: clap::ArgMatches<'static>) -> Result{ // We load the host info!("Loading host"); - let host = misc::get_host(matches.value_of("REMOTE").unwrap())?; + let host = misc::get_host(matches.value_of("REMOTE").unwrap(), store.clone())?; push_env(&mut store, "RUNAWAY_REMOTE", host.get_name()); debug!("Host {} loaded", host);