Exit with non-zero code if any node fails to deploy

The exit codes are in flux and should not be relied upon.

Fixes #28.
This commit is contained in:
Zhaofeng Li 2021-05-24 00:15:38 -07:00
parent 960af8f793
commit 22ae18f5e7
3 changed files with 23 additions and 6 deletions

View file

@ -233,9 +233,13 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
let deployment = Arc::new(deployment);
if goal_arg == "keys" {
deployment.upload_keys().await;
let success = if goal_arg == "keys" {
deployment.upload_keys().await
} else {
deployment.execute().await;
deployment.execute().await
};
if !success {
quit::with_code(10);
}
}

View file

@ -126,7 +126,11 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
deployment.set_options(options);
let deployment = Arc::new(deployment);
deployment.execute().await;
let success = deployment.execute().await;
if !success {
quit::with_code(10);
}
}
async fn escalate(sudo: &str) -> ! {

View file

@ -255,7 +255,7 @@ impl Deployment {
}
/// Uploads keys only (user-facing)
pub async fn upload_keys(self: Arc<Self>) {
pub async fn upload_keys(self: Arc<Self>) -> bool {
let progress = {
let mut progress = Progress::default();
progress.set_label_width(self.label_width);
@ -306,12 +306,14 @@ impl Deployment {
}
arc_self.print_logs().await;
arc_self.all_successful().await
}
/// Executes the deployment (user-facing)
///
/// Self must be wrapped inside an Arc.
pub async fn execute(self: Arc<Self>) {
pub async fn execute(self: Arc<Self>) -> bool {
let progress = {
let mut progress = if !self.options.progress_bar {
Progress::with_style(OutputStyle::Plain)
@ -429,6 +431,13 @@ impl Deployment {
}
arc_self.print_logs().await;
arc_self.all_successful().await
}
async fn all_successful(&self) -> bool {
let results = self.results.lock().await;
results.iter().filter(|r| !r.is_successful()).count() == 0
}
async fn print_logs(&self) {