diff --git a/.github/workflows/generate-diff.yml b/.github/workflows/generate-diff.yml index 1881aead..5af3d95c 100644 --- a/.github/workflows/generate-diff.yml +++ b/.github/workflows/generate-diff.yml @@ -27,7 +27,9 @@ jobs: - name: Generate Diff run: | + docker build . -f Dockerfile_AMD64 -t image docker run \ + -t \ --network=host \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(pwd)/main:/base-branch \ @@ -35,7 +37,7 @@ jobs: -v $(pwd)/output:/output \ -e TARGET_BRANCH=${{ github.head_ref }} \ -e REPO=${{ github.repository }} \ - dagandersen/argocd-diff-preview:v0.0.9 + image - name: Post diff as comment run: | diff --git a/Cargo.lock b/Cargo.lock index 7d5d0e40..c46acdad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,6 +89,7 @@ version = "0.0.9" dependencies = [ "base64", "env_logger", + "indicatif", "log", "regex", "schemars", @@ -183,12 +184,31 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.52.0", +] + [[package]] name = "dyn-clone" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "env_filter" version = "0.1.0" @@ -270,6 +290,28 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indicatif" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3" +dependencies = [ + "console", + "instant", + "number_prefix", + "portable-atomic", + "unicode-width", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "1.0.11" @@ -340,6 +382,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + [[package]] name = "object" version = "0.32.2" @@ -378,6 +426,12 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + [[package]] name = "proc-macro-error" version = "1.0.4" diff --git a/Cargo.toml b/Cargo.toml index 407a0342..72663680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,5 @@ schemars = "0.8.19" structopt = { version = "0.3" } regex = "1.10.4" log = "0.4.21" -env_logger = "0.11.3" \ No newline at end of file +env_logger = "0.11.3" +indicatif = "0.17.8" \ No newline at end of file diff --git a/src/argocd.rs b/src/argocd.rs index c2d0ed34..aca0f960 100644 --- a/src/argocd.rs +++ b/src/argocd.rs @@ -2,7 +2,7 @@ use base64::prelude::*; use std::{ error::Error, io::Write, - process::{Command, Stdio}, + process::{Command, Stdio}, time::Duration, }; use log::{debug, error, info}; @@ -24,7 +24,14 @@ data: "#; pub async fn install_argo_cd(version: Option<&str>) -> Result<(), Box> { - info!("🦑 Installing Argo CD..."); + let progress_bar = indicatif::ProgressBar::new(6); + progress_bar.enable_steady_tick(Duration::from_millis(100)); + progress_bar.set_style( + indicatif::ProgressStyle::default_bar() + .template("🦑 [{elapsed_precise}] [{bar:20.cyan/blue}] {pos}/{len} {msg}")? + .progress_chars("##-"), + ); + progress_bar.set_message("Installing Argo CD..."); match run_command("kubectl create ns argocd", None).await { Ok(_) => (), @@ -34,6 +41,8 @@ pub async fn install_argo_cd(version: Option<&str>) -> Result<(), Box } } + progress_bar.inc(1); + // Install Argo CD let install_url = format!( "https://raw.githubusercontent.com/argoproj/argo-cd/{}/manifests/install.yaml", @@ -46,7 +55,9 @@ pub async fn install_argo_cd(version: Option<&str>) -> Result<(), Box panic!("error: {}", String::from_utf8_lossy(&e.stderr)) } } - info!("🦑 Waiting for Argo CD to start..."); + + progress_bar.inc(1); + progress_bar.set_message("Waiting for Argo CD to start..."); // apply argocd-cmd-params-cm let mut child = Command::new("kubectl") @@ -78,7 +89,8 @@ pub async fn install_argo_cd(version: Option<&str>) -> Result<(), Box .await .expect("failed to wait for argocd-repo-server"); - info!("🦑 Logging in to Argo CD through CLI..."); + progress_bar.inc(1); + progress_bar.set_message("Logging in to Argo CD..."); debug!("Port-forwarding Argo CD server..."); // port-forward Argo CD server @@ -107,6 +119,8 @@ pub async fn install_argo_cd(version: Option<&str>) -> Result<(), Box } }; + progress_bar.inc(1); + let password_decoded_vec = BASE64_STANDARD .decode(password_encoded.stdout) .expect("failed to decode password"); @@ -134,10 +148,13 @@ pub async fn install_argo_cd(version: Option<&str>) -> Result<(), Box .await .expect("failed to login to argocd"); + progress_bar.inc(1); + run_command("argocd app list", None) .await .expect("Failed to run: argocd app list"); - info!("🦑 Argo CD installed successfully"); + progress_bar.inc(1); + progress_bar.finish_with_message("🦑 Argo CD installed successfully"); Ok(()) } diff --git a/src/extract.rs b/src/extract.rs index fca66b73..5a82388c 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -42,6 +42,18 @@ pub async fn get_resources( } } + let multi_progress = indicatif::MultiProgress::new(); + let progress_bar = multi_progress.add(indicatif::ProgressBar::new(100)); + let spinner_with_status = multi_progress.add(indicatif::ProgressBar::new_spinner()); + + // style including, emoji, progress bar, x out of y, and time left + progress_bar.set_style( + indicatif::ProgressStyle::default_bar() + .template("💦 [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} {msg}") + .expect("Failed to set style") + .progress_chars("##-"), + ); + let mut set_of_processed_apps = HashSet::new(); let mut set_of_failed_apps = BTreeMap::new(); @@ -59,6 +71,9 @@ pub async fn get_resources( break; } + progress_bar.set_length(items.len() as u64); + progress_bar.set_position(set_of_processed_apps.len() as u64); + if items.len() == set_of_processed_apps.len() { break; } @@ -70,9 +85,11 @@ pub async fn get_resources( for item in items { let name = item["metadata"]["name"].as_str().unwrap(); + spinner_with_status.set_message(format!("Timeout in {} seconds, Processing application: {}", timeout - start_time.elapsed().as_secs(), name)); if set_of_processed_apps.contains(name) { continue; } + match item["status"]["sync"]["status"].as_str() { Some("OutOfSync") | Some("Synced") => { debug!("Getting manifests for application: {}", name); @@ -87,6 +104,7 @@ pub async fn get_resources( Err(e) => error!("error: {}", String::from_utf8_lossy(&e.stderr)), } set_of_processed_apps.insert(name.to_string().clone()); + progress_bar.set_position(set_of_processed_apps.len() as u64); continue; } Some("Unknown") => { @@ -171,14 +189,7 @@ pub async fn get_resources( } } - if apps_left > 0 { - info!( - "⏳ Waiting for {} out of {} applications to become 'OutOfSync'. Retrying in 5 seconds. Timeout in {} seconds...", - apps_left, - items.len(), - timeout - time_elapsed - ); - } + spinner_with_status.set_message(format!("Timeout in {} seconds, Waiting for applications to sync...", timeout - start_time.elapsed().as_secs())); tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; }