From 464fdf94a919d94f8b0edebb757177c0195f9f33 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sun, 11 Aug 2024 00:16:54 -0400 Subject: [PATCH] fix: Out of bounds panic when not retrying push --- src/commands/build.rs | 10 +++++----- src/drivers.rs | 8 ++------ src/drivers/opts/build.rs | 4 ++-- utils/src/lib.rs | 9 ++++----- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/commands/build.rs b/src/commands/build.rs index 38ac4e6..fb206b0 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -63,10 +63,10 @@ pub struct BuildCommand { #[builder(default)] compression_format: CompressionType, - /// Block `bluebuild` from retrying to push the image. - #[arg(short, long, default_value_t = true)] + /// Enable retrying to push the image. + #[arg(short, long)] #[builder(default)] - no_retry_push: bool, + retry_push: bool, /// The number of times to retry pushing the image. #[arg(long, default_value_t = 1)] @@ -246,7 +246,7 @@ impl BuildCommand { .containerfile(&containerfile) .tags(tags.iter().map(String::as_str).collect::>()) .push(self.push) - .no_retry_push(self.no_retry_push) + .retry_push(self.retry_push) .retry_count(self.retry_count) .compression(self.compression_format) .squash(self.squash) @@ -292,7 +292,7 @@ impl BuildCommand { .containerfile(&containerfile) .tags(tags.iter().map(String::as_str).collect::>()) .push(self.push) - .no_retry_push(self.no_retry_push) + .retry_push(self.retry_push) .retry_count(self.retry_count) .compression(self.compression_format) .squash(self.squash) diff --git a/src/drivers.rs b/src/drivers.rs index cc0bfc2..468e8f5 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -216,15 +216,11 @@ pub trait BuildDriver: Sync + Send { self.tag(&tag_opts)?; if opts.push { - let retry_count = if opts.no_retry_push { - 0 - } else { - opts.retry_count - }; + let retry_count = if opts.retry_push { opts.retry_count } else { 0 }; debug!("Pushing all images"); // Push images with retries (1s delay between retries) - blue_build_utils::retry(retry_count, 1000, || { + blue_build_utils::retry(retry_count, 10, || { let tag_image = format!("{image}:{tag}"); debug!("Pushing image {tag_image}"); diff --git a/src/drivers/opts/build.rs b/src/drivers/opts/build.rs index 1ba135e..5cd6549 100644 --- a/src/drivers/opts/build.rs +++ b/src/drivers/opts/build.rs @@ -63,9 +63,9 @@ pub struct BuildTagPushOpts<'a> { #[builder(default)] pub push: bool, - /// Disable retry logic for pushing. + /// Enable retry logic for pushing. #[builder(default)] - pub no_retry_push: bool, + pub retry_push: bool, /// Number of times to retry pushing. /// diff --git a/utils/src/lib.rs b/utils/src/lib.rs index 9adc2ef..2c32d49 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -70,18 +70,17 @@ pub fn serde_yaml_err(contents: &str) -> impl Fn(serde_yaml::Error) -> SerdeErro /// /// # Errors /// Will error when retries have been expended. -pub fn retry(attempts: u8, delay: u64, f: F) -> miette::Result +pub fn retry(mut retries: u8, delay_secs: u64, f: F) -> miette::Result where F: Fn() -> miette::Result, { - let mut attempts = attempts; loop { match f() { Ok(v) => return Ok(v), - Err(e) if attempts == 1 => return Err(e), + Err(e) if retries == 0 => return Err(e), _ => { - attempts -= 1; - thread::sleep(Duration::from_secs(delay)); + retries -= 1; + thread::sleep(Duration::from_secs(delay_secs)); } }; }