From ff347d4204369d40b6b04eedf8e2421bcd7018ab Mon Sep 17 00:00:00 2001 From: notgne2 Date: Mon, 28 Sep 2020 13:55:46 -0700 Subject: Crudely perform pushes before deploys, with little data re-use (untested) --- src/main.rs | 135 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 69 insertions(+), 66 deletions(-) diff --git a/src/main.rs b/src/main.rs index a3c526f..59b79a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -351,81 +351,63 @@ async fn deploy_profile( Ok(()) } -async fn deploy_profile_todo( - top_settings: &GenericSettings, - profile: &Profile, - profile_name: &str, - node: &Node, - node_name: &str, - supports_flakes: bool, - check_sigs: bool, - repo: &str, -) -> Result<(), Box> { - let mut merged_settings = top_settings.clone(); - merged_settings.merge(node.generic_settings.clone()); - merged_settings.merge(profile.generic_settings.clone()); - - let deploy_data = make_deploy_data(profile_name, node_name, &merged_settings).await?; - - push_profile( - profile, - profile_name, - node, - node_name, - supports_flakes, - check_sigs, - repo, - &merged_settings, - &deploy_data, - ) - .await?; - - deploy_profile( - profile, - profile_name, - node, - node_name, - &merged_settings, - &deploy_data, - ) - .await?; - - Ok(()) -} - #[inline] -async fn deploy_all_profiles( +async fn push_all_profiles( node: &Node, node_name: &str, supports_flakes: bool, repo: &str, top_settings: &GenericSettings, - prime: bool, check_sigs: bool, ) -> Result<(), Box> { info!("Deploying all profiles for `{}`", node_name); - if prime { - info!("Bootstrapping {}", node_name); + let mut profiles_list: Vec<&str> = node.profiles_order.iter().map(|x| x.as_ref()).collect(); + + // Add any profiles which weren't in the provided order list + for (profile_name, _) in &node.profiles { + if !profiles_list.contains(&profile_name.as_str()) { + profiles_list.push(&profile_name); + } + } - let profile = match node.profiles.get("system") { + for profile_name in profiles_list { + let profile = match node.profiles.get(profile_name) { Some(x) => x, - None => good_panic!("No system profile was found, needed for priming"), + None => good_panic!("No profile was found named `{}`", profile_name), }; - deploy_profile_todo( - top_settings, + let mut merged_settings = top_settings.clone(); + merged_settings.merge(node.generic_settings.clone()); + merged_settings.merge(profile.generic_settings.clone()); + + let deploy_data = make_deploy_data(profile_name, node_name, &merged_settings).await?; + + push_profile( profile, - "system", + profile_name, node, node_name, supports_flakes, check_sigs, repo, + &merged_settings, + &deploy_data, ) .await?; } + Ok(()) +} + +#[inline] +async fn deploy_all_profiles( + node: &Node, + node_name: &str, + top_settings: &GenericSettings, +) -> Result<(), Box> { + info!("Deploying all profiles for `{}`", node_name); + let mut profiles_list: Vec<&str> = node.profiles_order.iter().map(|x| x.as_ref()).collect(); // Add any profiles which weren't in the provided order list @@ -441,20 +423,19 @@ async fn deploy_all_profiles( None => good_panic!("No profile was found named `{}`", profile_name), }; - // This will have already been deployed - if prime && profile_name == "system" { - continue; - } + let mut merged_settings = top_settings.clone(); + merged_settings.merge(node.generic_settings.clone()); + merged_settings.merge(profile.generic_settings.clone()); + + let deploy_data = make_deploy_data(profile_name, node_name, &merged_settings).await?; - deploy_profile_todo( - top_settings, + deploy_profile( profile, profile_name, node, node_name, - supports_flakes, - check_sigs, - repo, + &merged_settings, + &deploy_data, ) .await?; } @@ -547,8 +528,14 @@ async fn main() -> Result<(), Box> { None => good_panic!("No profile was found named `{}`", profile_name), }; - deploy_profile_todo( - &data.generic_settings, + let mut merged_settings = data.generic_settings.clone(); + merged_settings.merge(node.generic_settings.clone()); + merged_settings.merge(profile.generic_settings.clone()); + + let deploy_data = + make_deploy_data(profile_name, node_name, &merged_settings).await?; + + push_profile( profile, profile_name, node, @@ -556,6 +543,18 @@ async fn main() -> Result<(), Box> { supports_flakes, deploy_opts.checksigs, repo, + &merged_settings, + &deploy_data, + ) + .await?; + + deploy_profile( + profile, + profile_name, + node, + node_name, + &merged_settings, + &deploy_data, ) .await?; } @@ -565,32 +564,36 @@ async fn main() -> Result<(), Box> { None => good_panic!("No node was found named `{}`", node_name), }; - deploy_all_profiles( + push_all_profiles( node, node_name, supports_flakes, repo, &data.generic_settings, - deploy_opts.prime, deploy_opts.checksigs, ) .await?; + + deploy_all_profiles(node, node_name, &data.generic_settings).await?; } (None, None) => { info!("Deploying all profiles on all nodes"); for (node_name, node) in &data.nodes { - deploy_all_profiles( + push_all_profiles( node, node_name, supports_flakes, repo, &data.generic_settings, - deploy_opts.prime, deploy_opts.checksigs, ) .await?; } + + for (node_name, node) in &data.nodes { + deploy_all_profiles(node, node_name, &data.generic_settings).await?; + } } (None, Some(_)) => good_panic!( "Profile provided without a node, this is not (currently) supported" -- cgit v1.2.3