diff options
author | Yannik Sander | 2021-03-30 17:32:58 +0200 |
---|---|---|
committer | Yannik Sander | 2021-06-22 13:41:15 +0200 |
commit | 1a2d35be27de412bd2c406ed01189dc93ae0985a (patch) | |
tree | 93dcc7af9e4e8e62ba73d4da5429e77c81f3572c /src/lib.rs | |
parent | 70d71b3027b1793b780f1e2435bdbbe1b0cb9ac6 (diff) |
Add multi node support
Run multiple deployments in sequence
Resolve targets later
Extend context by deployed flake
Apply clippy suggestions
Add revoke command builder
Track succeeded deploys
Add revoke function
Register revoke error as deploy error
Prepare revoke command in activate
Extend logger to handle revoke
Implement revoke command client side
Run revoke on previously suceeded
Control whether to override by flag
Adhere profile configuration auto_rollback setting
Cargo fmt
Correctly provide profile path to activation script when revoking
Document multi flake mode in README
Resolve a typo in README.md
Co-authored-by: notgne2 <gen2@gen2.space>
Use existing teminology
rename revoke_suceeded -> rollback_suceeded
Use more open CLI argument name `targets` instead of `flakes`
Document name changes in README
Add sudo command support for revokes
Call run_deploy with `dry_active` flag
Test revoke commands contains sudo
Set default temp_path in activate binary
Require temp_path for wait and activate subcommands
Add copyright comment
Address review change requests
Fix typo in README
Co-authored-by: Alexander Bantyev <balsoft@balsoft.ru>
Diffstat (limited to '')
-rw-r--r-- | src/lib.rs | 82 |
1 files changed, 55 insertions, 27 deletions
@@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: 2020 Serokell <https://serokell.io/> // SPDX-FileCopyrightText: 2020 Andreas Fuchs <asf@boinkor.net> +// SPDX-FileCopyrightText: 2021 Yannik Sander <contact@ysndr.de> // // SPDX-License-Identifier: MPL-2.0 @@ -59,6 +60,22 @@ pub fn logger_formatter_wait( ) } +pub fn logger_formatter_revoke( + w: &mut dyn std::io::Write, + _now: &mut DeferredNow, + record: &Record, +) -> Result<(), std::io::Error> { + let level = record.level(); + + write!( + w, + "↩️ {} [revoke] [{}] {}", + make_emoji(level), + style(level, level.to_string()), + record.args() + ) +} + pub fn logger_formatter_deploy( w: &mut dyn std::io::Write, _now: &mut DeferredNow, @@ -79,6 +96,7 @@ pub enum LoggerType { Deploy, Activate, Wait, + Revoke, } pub fn init_logger( @@ -90,6 +108,7 @@ pub fn init_logger( LoggerType::Deploy => logger_formatter_deploy, LoggerType::Activate => logger_formatter_activate, LoggerType::Wait => logger_formatter_wait, + LoggerType::Revoke => logger_formatter_revoke, }; if let Some(log_dir) = log_dir { @@ -107,6 +126,7 @@ pub fn init_logger( match logger_type { LoggerType::Activate => logger = logger.discriminant("activate"), LoggerType::Wait => logger = logger.discriminant("wait"), + LoggerType::Revoke => logger = logger.discriminant("revoke"), LoggerType::Deploy => (), } @@ -324,19 +344,25 @@ impl<'a> DeployData<'a> { None => whoami::username(), }; - let profile_user = match self.merged_settings.user { - Some(ref x) => x.clone(), - None => match self.merged_settings.ssh_user { - Some(ref x) => x.clone(), - None => { - return Err(DeployDataDefsError::NoProfileUser( - self.profile_name.to_owned(), - self.node_name.to_owned(), - )) - } - }, + let profile_user = self.get_profile_user()?; + + let profile_path = self.get_profile_path()?; + + let sudo: Option<String> = match self.merged_settings.user { + Some(ref user) if user != &ssh_user => Some(format!("sudo -u {}", user)), + _ => None, }; + Ok(DeployDefs { + ssh_user, + profile_user, + profile_path, + sudo, + }) + } + + fn get_profile_path(&'a self) -> Result<String, DeployDataDefsError> { + let profile_user = self.get_profile_user()?; let profile_path = match self.profile.profile_settings.profile_path { None => match &profile_user[..] { "root" => format!("/nix/var/nix/profiles/{}", self.profile_name), @@ -347,18 +373,23 @@ impl<'a> DeployData<'a> { }, Some(ref x) => x.clone(), }; + Ok(profile_path) + } - let sudo: Option<String> = match self.merged_settings.user { - Some(ref user) if user != &ssh_user => Some(format!("sudo -u {}", user)), - _ => None, + fn get_profile_user(&'a self) -> Result<String, DeployDataDefsError> { + let profile_user = match self.merged_settings.user { + Some(ref x) => x.clone(), + None => match self.merged_settings.ssh_user { + Some(ref x) => x.clone(), + None => { + return Err(DeployDataDefsError::NoProfileUser( + self.profile_name.to_owned(), + self.node_name.to_owned(), + )) + } + }, }; - - Ok(DeployDefs { - ssh_user, - profile_user, - profile_path, - sudo, - }) + Ok(profile_user) } } @@ -396,15 +427,12 @@ pub fn make_deploy_data<'a, 's>( } DeployData { - profile, - profile_name, - node, node_name, - + node, + profile_name, + profile, cmd_overrides, - merged_settings, - debug_logs, log_dir, } |