From 781052485490a2e5aea0d148264cf23a97678f70 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Wed, 13 Mar 2024 10:24:49 -0400 Subject: [PATCH 01/11] initial commit --- tembo-cli/examples/set/tembo.toml | 9 -------- tembo-cli/src/cli/file_utils.rs | 38 +++++++++++-------------------- tembo-cli/src/cmd/init.rs | 13 ++++++++--- 3 files changed, 23 insertions(+), 37 deletions(-) delete mode 100644 tembo-cli/examples/set/tembo.toml diff --git a/tembo-cli/examples/set/tembo.toml b/tembo-cli/examples/set/tembo.toml deleted file mode 100644 index dd996e4e6..000000000 --- a/tembo-cli/examples/set/tembo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[set] -environment = "dev" -instance_name = "set" -cpu = "1" -memory = "2Gi" -storage = "10Gi" -replicas = 1 -stack_type = "Standard" - diff --git a/tembo-cli/src/cli/file_utils.rs b/tembo-cli/src/cli/file_utils.rs index d5c498594..49733e869 100644 --- a/tembo-cli/src/cli/file_utils.rs +++ b/tembo-cli/src/cli/file_utils.rs @@ -3,7 +3,7 @@ use simplelog::*; use std::env; use std::fs::{self, File}; use std::io::Write; -use std::path::Path; +use std::path::{Path, PathBuf}; pub struct FileUtils {} @@ -54,35 +54,23 @@ impl FileUtils { } pub fn download_file( - file_path: &str, - download_location: &str, - recreate: bool, + source: &PathBuf, + destination: &Path, + overwrite: bool, ) -> std::io::Result<()> { - let path = Path::new(&download_location); - if !recreate && path.exists() { - info!("Tembo {} file exists", download_location); + // Check if the destination file exists and if overwrite is false, return early + if !overwrite && destination.exists() { + println!( + "Tembo.toml file exists in this path {}", + destination.display() + ); return Ok(()); } - let mut dst = Vec::new(); - let mut easy = Easy::new(); - easy.url(file_path).unwrap(); - let _redirect = easy.follow_location(true); + // Copy the file from the source to the destination + fs::copy(source, destination)?; - { - let mut transfer = easy.transfer(); - transfer - .write_function(|data| { - dst.extend_from_slice(data); - Ok(data.len()) - }) - .unwrap(); - transfer.perform().unwrap(); - } - { - let mut file = File::create(download_location)?; - file.write_all(dst.as_slice())?; - } + println!("File copied successfully to {}", destination.display()); Ok(()) } diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index b47e29d65..c84bee405 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -5,6 +5,8 @@ use crate::cli::context::{ use crate::cli::file_utils::FileUtils; use crate::tui::confirmation; use clap::Args; +use std::env; +use std::path::Path; /// Initializes a local environment. Creates a sample context and configuration files. #[derive(Args)] @@ -43,10 +45,15 @@ pub fn execute() -> Result<(), anyhow::Error> { } let filename = "tembo.toml"; - let filepath = - "https://raw.githubusercontent.com/tembo-io/tembo/main/tembo-cli/examples/single-instance/tembo.toml"; + let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - FileUtils::download_file(filepath, filename, false)?; + let relative_path = "tembo-cli/examples/single-instance/tembo.toml"; // Relative path from the project root + let filepath = Path::new(&cargo_manifest_dir).join(relative_path); + + // Assuming you want to copy the file to the current working directory + let destination_path = Path::new(&FileUtils::get_current_working_dir()).join("tembo.toml"); + + FileUtils::download_file(&filepath, &destination_path, false)?; confirmation("Tembo initialized successfully!"); From 7dfad2e0df97f61063f73a404a8ae63ea06b5f54 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Wed, 13 Mar 2024 23:55:45 -0400 Subject: [PATCH 02/11] updates --- tembo-cli/examples/set/tembo.toml | 8 ++++++++ tembo-cli/src/cli/file_utils.rs | 2 -- tembo-cli/src/cmd/init.rs | 4 +--- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 tembo-cli/examples/set/tembo.toml diff --git a/tembo-cli/examples/set/tembo.toml b/tembo-cli/examples/set/tembo.toml new file mode 100644 index 000000000..698f291cc --- /dev/null +++ b/tembo-cli/examples/set/tembo.toml @@ -0,0 +1,8 @@ +[set] +environment = "dev" +instance_name = "set" +cpu = "1" +memory = "2Gi" +storage = "10Gi" +replicas = 1 +stack_type = "Standard" diff --git a/tembo-cli/src/cli/file_utils.rs b/tembo-cli/src/cli/file_utils.rs index 49733e869..85bebc9f7 100644 --- a/tembo-cli/src/cli/file_utils.rs +++ b/tembo-cli/src/cli/file_utils.rs @@ -58,7 +58,6 @@ impl FileUtils { destination: &Path, overwrite: bool, ) -> std::io::Result<()> { - // Check if the destination file exists and if overwrite is false, return early if !overwrite && destination.exists() { println!( "Tembo.toml file exists in this path {}", @@ -67,7 +66,6 @@ impl FileUtils { return Ok(()); } - // Copy the file from the source to the destination fs::copy(source, destination)?; println!("File copied successfully to {}", destination.display()); diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index c84bee405..c9e05a902 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -44,13 +44,11 @@ pub fn execute() -> Result<(), anyhow::Error> { } } - let filename = "tembo.toml"; let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let relative_path = "tembo-cli/examples/single-instance/tembo.toml"; // Relative path from the project root + let relative_path = "tembo/tembo-cli/examples/single-instance/tembo.toml"; let filepath = Path::new(&cargo_manifest_dir).join(relative_path); - // Assuming you want to copy the file to the current working directory let destination_path = Path::new(&FileUtils::get_current_working_dir()).join("tembo.toml"); FileUtils::download_file(&filepath, &destination_path, false)?; From 9b12d48da2f5f0477926b5cde9213e7b62315136 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Thu, 14 Mar 2024 11:08:36 -0400 Subject: [PATCH 03/11] final changes --- tembo-cli/src/cli/file_utils.rs | 2 -- tembo-cli/src/cmd/init.rs | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tembo-cli/src/cli/file_utils.rs b/tembo-cli/src/cli/file_utils.rs index 85bebc9f7..4b1910e06 100644 --- a/tembo-cli/src/cli/file_utils.rs +++ b/tembo-cli/src/cli/file_utils.rs @@ -1,4 +1,3 @@ -use curl::easy::Easy; use simplelog::*; use std::env; use std::fs::{self, File}; @@ -68,7 +67,6 @@ impl FileUtils { fs::copy(source, destination)?; - println!("File copied successfully to {}", destination.display()); Ok(()) } diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index c9e05a902..5237c96b3 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -44,13 +44,20 @@ pub fn execute() -> Result<(), anyhow::Error> { } } - let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let cargo_manifest_dir = + env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env var not set"); let relative_path = "tembo/tembo-cli/examples/single-instance/tembo.toml"; let filepath = Path::new(&cargo_manifest_dir).join(relative_path); - let destination_path = Path::new(&FileUtils::get_current_working_dir()).join("tembo.toml"); + if !filepath.exists() { + return Err(anyhow::anyhow!( + "The specified file was not found: {}", + filepath.display() + )); + } + let destination_path = Path::new(&FileUtils::get_current_working_dir()).join("tembo.toml"); FileUtils::download_file(&filepath, &destination_path, false)?; confirmation("Tembo initialized successfully!"); From 5454d53452a852af2e970dc5a49733e3672cdf7b Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Thu, 14 Mar 2024 14:03:51 -0400 Subject: [PATCH 04/11] modifying path to file --- tembo-cli/src/cmd/init.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index 5237c96b3..8667cd30b 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -47,7 +47,7 @@ pub fn execute() -> Result<(), anyhow::Error> { let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env var not set"); - let relative_path = "tembo/tembo-cli/examples/single-instance/tembo.toml"; + let relative_path = "examples/single-instance/tembo.toml"; let filepath = Path::new(&cargo_manifest_dir).join(relative_path); if !filepath.exists() { From cd4d90b34cafc59c54eb5ba13d35156d27f14b1b Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Thu, 14 Mar 2024 15:14:25 -0400 Subject: [PATCH 05/11] removing unnecessary space --- tembo-cli/examples/set/tembo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tembo-cli/examples/set/tembo.toml b/tembo-cli/examples/set/tembo.toml index 698f291cc..2eb716b03 100644 --- a/tembo-cli/examples/set/tembo.toml +++ b/tembo-cli/examples/set/tembo.toml @@ -5,4 +5,4 @@ cpu = "1" memory = "2Gi" storage = "10Gi" replicas = 1 -stack_type = "Standard" +stack_type = "Standard" \ No newline at end of file From bd1ad152d6001cbc98077c5ef04b6bc78d3d29c5 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Thu, 14 Mar 2024 21:03:44 -0400 Subject: [PATCH 06/11] addresing comments --- tembo-cli/src/cli/file_utils.rs | 20 ++++--------- tembo-cli/src/cmd/init.rs | 50 ++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/tembo-cli/src/cli/file_utils.rs b/tembo-cli/src/cli/file_utils.rs index 4b1910e06..b7596476d 100644 --- a/tembo-cli/src/cli/file_utils.rs +++ b/tembo-cli/src/cli/file_utils.rs @@ -2,7 +2,7 @@ use simplelog::*; use std::env; use std::fs::{self, File}; use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::Path; pub struct FileUtils {} @@ -52,20 +52,12 @@ impl FileUtils { Ok(()) } - pub fn download_file( - source: &PathBuf, - destination: &Path, - overwrite: bool, - ) -> std::io::Result<()> { - if !overwrite && destination.exists() { - println!( - "Tembo.toml file exists in this path {}", - destination.display() - ); - return Ok(()); - } + pub fn save_tembo_toml(default_text: &str) -> Result<(), Box> { + let parent_dir = FileUtils::get_current_working_dir(); + let tembo_toml_path = Path::new(&parent_dir).join("tembo.toml"); - fs::copy(source, destination)?; + let mut file = File::create(&tembo_toml_path)?; + file.write_all(default_text.as_bytes())?; Ok(()) } diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index 8667cd30b..0dbc29e8b 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -5,8 +5,38 @@ use crate::cli::context::{ use crate::cli::file_utils::FileUtils; use crate::tui::confirmation; use clap::Args; -use std::env; -use std::path::Path; + +pub const TEMBO_DEFAULT_TEXT: &str = r#"[test-instance] +environment = "dev" +instance_name = "test-instance" +cpu = "1" +memory = "2Gi" +storage = "10Gi" +replicas = 1 +stack_type = "Standard" + +[test-instance.postgres_configurations] +shared_preload_libraries = 'pg_stat_statements' +statement_timeout = 60 +pg_partman_bgw.dbname = 'postgres' +pg_partman_bgw.interval = "60" +pg_partman_bgw.role = 'postgres' + +[test-instance.extensions.pg_jsonschema] +enabled = true +trunk_project = "pg_jsonschema" +trunk_project_version = "0.1.4" + +[test-instance.extensions.pgmq] +enabled = true +trunk_project = "pgmq" +trunk_project_version = "0.33.3" + +[test-instance.extensions.pg_partman] +enabled = true +trunk_project = "pg_partman" +trunk_project_version = "4.7.4" +"#; /// Initializes a local environment. Creates a sample context and configuration files. #[derive(Args)] @@ -44,21 +74,7 @@ pub fn execute() -> Result<(), anyhow::Error> { } } - let cargo_manifest_dir = - env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env var not set"); - - let relative_path = "examples/single-instance/tembo.toml"; - let filepath = Path::new(&cargo_manifest_dir).join(relative_path); - - if !filepath.exists() { - return Err(anyhow::anyhow!( - "The specified file was not found: {}", - filepath.display() - )); - } - - let destination_path = Path::new(&FileUtils::get_current_working_dir()).join("tembo.toml"); - FileUtils::download_file(&filepath, &destination_path, false)?; + let _ = FileUtils::save_tembo_toml(TEMBO_DEFAULT_TEXT); confirmation("Tembo initialized successfully!"); From e6bc8ddd8c1b4fe0496674a5a0e849f39d3dabc0 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Fri, 15 Mar 2024 14:51:46 -0400 Subject: [PATCH 07/11] modifying integration_tests_cloud --- tembo-cli/tests/integration_tests_cloud.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tembo-cli/tests/integration_tests_cloud.rs b/tembo-cli/tests/integration_tests_cloud.rs index 3f8097ab6..04f963ef9 100644 --- a/tembo-cli/tests/integration_tests_cloud.rs +++ b/tembo-cli/tests/integration_tests_cloud.rs @@ -11,6 +11,7 @@ use tembo::cli::context::{ use temboclient::apis::configuration::Configuration; use temboclient::apis::instance_api::get_all; use temboclient::models::{Instance, State}; +use tokio::time::Duration; const CARGO_BIN: &str = "tembo"; @@ -52,13 +53,22 @@ async fn minimal_cloud() -> Result<(), Box> { ..Default::default() }; - let maybe_instance = get_instance(&instance_name, &config, &env).await?; - if let Some(instance) = maybe_instance { - assert_eq!(instance.state, State::Up, "Instance isn't Up") - } else { - assert!(false, "Instance isn't Up") - } + for attempt in 1..=5 { + println!("---- Attempt {attempt}"); + tokio::time::sleep(Duration::from_secs(25)).await; + let maybe_instance = get_instance(&instance_name, &config, &env).await?; + if let Some(instance) = maybe_instance { + println!("Instance is {:?}", instance.state); + if instance.state == State::Up { + break; + } + if attempt == 5 { + assert_eq!(instance.state, State::Up, "Instance isn't Up") + } + } else if attempt == 5 { + panic!("Failed to get instance"); + }} // tembo delete let mut cmd = Command::cargo_bin(CARGO_BIN)?; cmd.arg("delete"); From 0bf48496749607b37319d0982109b5c17a12064f Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Fri, 15 Mar 2024 15:02:04 -0400 Subject: [PATCH 08/11] Update integration_tests_cloud.rs --- tembo-cli/tests/integration_tests_cloud.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tembo-cli/tests/integration_tests_cloud.rs b/tembo-cli/tests/integration_tests_cloud.rs index 04f963ef9..b14108bce 100644 --- a/tembo-cli/tests/integration_tests_cloud.rs +++ b/tembo-cli/tests/integration_tests_cloud.rs @@ -55,7 +55,7 @@ async fn minimal_cloud() -> Result<(), Box> { for attempt in 1..=5 { println!("---- Attempt {attempt}"); - tokio::time::sleep(Duration::from_secs(25)).await; + tokio::time::sleep(Duration::from_secs(200)).await; let maybe_instance = get_instance(&instance_name, &config, &env).await?; if let Some(instance) = maybe_instance { println!("Instance is {:?}", instance.state); From c0748f7ab57d8d4c38b0bba4ac734be9f781005b Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Sun, 17 Mar 2024 20:11:51 -0400 Subject: [PATCH 09/11] removing errors --- tembo-cli/tests/integration_tests_cloud.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tembo-cli/tests/integration_tests_cloud.rs b/tembo-cli/tests/integration_tests_cloud.rs index ba67ae541..2b818c3eb 100644 --- a/tembo-cli/tests/integration_tests_cloud.rs +++ b/tembo-cli/tests/integration_tests_cloud.rs @@ -12,7 +12,6 @@ use tembo::cli::context::{ use temboclient::apis::configuration::Configuration; use temboclient::apis::instance_api::get_all; use temboclient::models::{Instance, State}; -use tokio::time::Duration; const CARGO_BIN: &str = "tembo"; @@ -73,12 +72,6 @@ async fn minimal_cloud() -> Result<(), Box> { tokio::time::sleep(Duration::from_secs(30)).await; } - if attempt == 5 { - assert_eq!(instance.state, State::Up, "Instance isn't Up") - } - } else if attempt == 5 { - panic!("Failed to get instance"); - }} // tembo delete let mut cmd = Command::cargo_bin(CARGO_BIN)?; cmd.arg("delete"); From 16ea2f796f7acbb1a3ff8a17916598e781ef53fa Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Mon, 18 Mar 2024 23:47:26 -0400 Subject: [PATCH 10/11] adding requested changes --- tembo-cli/src/cli/file_utils.rs | 13 ++++++++++--- tembo-cli/src/cmd/init.rs | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tembo-cli/src/cli/file_utils.rs b/tembo-cli/src/cli/file_utils.rs index b7596476d..3e9e9cfb7 100644 --- a/tembo-cli/src/cli/file_utils.rs +++ b/tembo-cli/src/cli/file_utils.rs @@ -1,3 +1,4 @@ +use crate::tui::confirmation; use simplelog::*; use std::env; use std::fs::{self, File}; @@ -56,10 +57,16 @@ impl FileUtils { let parent_dir = FileUtils::get_current_working_dir(); let tembo_toml_path = Path::new(&parent_dir).join("tembo.toml"); - let mut file = File::create(&tembo_toml_path)?; - file.write_all(default_text.as_bytes())?; + if tembo_toml_path.exists() { + print!("Tembo.toml file already exists in this path"); + Ok(()) + } else { + let mut file = File::create(&tembo_toml_path)?; + file.write_all(default_text.as_bytes())?; + confirmation("Tembo.toml initialized successfully!"); - Ok(()) + Ok(()) + } } pub fn get_current_working_dir() -> String { diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index 0dbc29e8b..88b03ea61 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -3,7 +3,6 @@ use crate::cli::context::{ CREDENTIALS_DEFAULT_TEXT, }; use crate::cli::file_utils::FileUtils; -use crate::tui::confirmation; use clap::Args; pub const TEMBO_DEFAULT_TEXT: &str = r#"[test-instance] @@ -76,7 +75,5 @@ pub fn execute() -> Result<(), anyhow::Error> { let _ = FileUtils::save_tembo_toml(TEMBO_DEFAULT_TEXT); - confirmation("Tembo initialized successfully!"); - Ok(()) } From 500dfab62ebe73e377a3285afff349b310435f91 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Mon, 18 Mar 2024 23:53:22 -0400 Subject: [PATCH 11/11] changing tembo.toml to minimal --- tembo-cli/src/cmd/init.rs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index 88b03ea61..75856c23b 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -6,35 +6,13 @@ use crate::cli::file_utils::FileUtils; use clap::Args; pub const TEMBO_DEFAULT_TEXT: &str = r#"[test-instance] -environment = "dev" +environment = "prod" instance_name = "test-instance" -cpu = "1" -memory = "2Gi" +cpu = "0.25" +memory = "1Gi" storage = "10Gi" replicas = 1 stack_type = "Standard" - -[test-instance.postgres_configurations] -shared_preload_libraries = 'pg_stat_statements' -statement_timeout = 60 -pg_partman_bgw.dbname = 'postgres' -pg_partman_bgw.interval = "60" -pg_partman_bgw.role = 'postgres' - -[test-instance.extensions.pg_jsonschema] -enabled = true -trunk_project = "pg_jsonschema" -trunk_project_version = "0.1.4" - -[test-instance.extensions.pgmq] -enabled = true -trunk_project = "pgmq" -trunk_project_version = "0.33.3" - -[test-instance.extensions.pg_partman] -enabled = true -trunk_project = "pg_partman" -trunk_project_version = "4.7.4" "#; /// Initializes a local environment. Creates a sample context and configuration files.