Improve nix copy stuff

This commit is contained in:
notgne2 2020-10-01 12:43:33 -07:00
parent 05a9975584
commit ea5aab7684
No known key found for this signature in database
GPG Key ID: BB661E172B42A7F8
4 changed files with 33 additions and 29 deletions

View File

@ -149,6 +149,8 @@ async fn get_deployment_data(
repo: &str, repo: &str,
extra_build_args: &[String], extra_build_args: &[String],
) -> Result<utils::data::Data, Box<dyn std::error::Error>> { ) -> Result<utils::data::Data, Box<dyn std::error::Error>> {
info!("Evaluating flake in {}", repo);
let mut c = match supports_flakes { let mut c = match supports_flakes {
true => Command::new("nix"), true => Command::new("nix"),
false => Command::new("nix-instanciate"), false => Command::new("nix-instanciate"),

View File

@ -6,30 +6,6 @@ use super::data;
use tokio::process::Command; use tokio::process::Command;
fn deploy_path_to_activate_path_str(
deploy_path: &std::path::Path,
) -> Result<String, Box<dyn std::error::Error>> {
Ok(format!(
"{}/activate",
deploy_path
.parent()
.ok_or("Deploy path too short")?
.to_str()
.ok_or("Deploy path is not valid utf8")?
.to_owned()
))
}
#[test]
fn test_activate_path_generation() {
match deploy_path_to_activate_path_str(&std::path::PathBuf::from(
"/blah/blah/deploy-rs/bin/deploy",
)) {
Err(_) => panic!(""),
Ok(x) => assert_eq!(x, "/blah/blah/deploy-rs/bin/activate".to_string()),
}
}
fn build_activate_command( fn build_activate_command(
activate_path_str: String, activate_path_str: String,
sudo: &Option<String>, sudo: &Option<String>,
@ -105,7 +81,7 @@ pub async fn deploy_profile(
profile_name, node_name profile_name, node_name
); );
let activate_path_str = deploy_path_to_activate_path_str(&deploy_data.current_exe)?; let activate_path_str = super::deploy_path_to_activate_path_str(&deploy_data.current_exe)?;
let self_activate_command = build_activate_command( let self_activate_command = build_activate_command(
activate_path_str, activate_path_str,

View File

@ -136,3 +136,27 @@ pub async fn make_deploy_data<'a>(
current_exe, current_exe,
}) })
} }
pub fn deploy_path_to_activate_path_str(
deploy_path: &std::path::Path,
) -> Result<String, Box<dyn std::error::Error>> {
Ok(format!(
"{}/activate",
deploy_path
.parent()
.ok_or("Deploy path too short")?
.to_str()
.ok_or("Deploy path is not valid utf8")?
.to_owned()
))
}
#[test]
fn test_activate_path_generation() {
match deploy_path_to_activate_path_str(&std::path::PathBuf::from(
"/blah/blah/deploy-rs/bin/deploy",
)) {
Err(_) => panic!(""),
Ok(x) => assert_eq!(x, "/blah/blah/deploy-rs/bin/activate".to_string()),
}
}

View File

@ -66,7 +66,9 @@ pub async fn push_profile(
.arg("-k") .arg("-k")
.arg(local_key) .arg(local_key)
.arg(&profile.profile_settings.path) .arg(&profile.profile_settings.path)
.arg(&deploy_data.current_exe) .arg(&super::deploy_path_to_activate_path_str(
&deploy_data.current_exe,
)?)
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn()? .spawn()?
@ -101,10 +103,10 @@ pub async fn push_profile(
deploy_data.ssh_user, node.node_settings.hostname deploy_data.ssh_user, node.node_settings.hostname
)) ))
.arg(&profile.profile_settings.path) .arg(&profile.profile_settings.path)
.arg(&deploy_data.current_exe) .arg(&super::deploy_path_to_activate_path_str(
&deploy_data.current_exe,
)?)
.env("NIX_SSHOPTS", ssh_opts_str) .env("NIX_SSHOPTS", ssh_opts_str)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()? .spawn()?
.await?; .await?;