From 6d5524212109418c035fdf56c95c7e20527e836c Mon Sep 17 00:00:00 2001 From: gabriel-aranha-cw <166405807+gabriel-aranha-cw@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:02:38 -0300 Subject: [PATCH] enha: allow custom env when local (#1602) --- config/stratus-follower.env.local | 10 ++++++++++ justfile | 6 ++---- src/config.rs | 15 +++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 config/stratus-follower.env.local diff --git a/config/stratus-follower.env.local b/config/stratus-follower.env.local new file mode 100644 index 000000000..fc4272a38 --- /dev/null +++ b/config/stratus-follower.env.local @@ -0,0 +1,10 @@ +RUST_LOG=info,stratus::eth::rpc::rpc_subscriptions::rx=off,stratus::eth::consensus::rx=off,stratus::eth::consensus=off,jsonrpsee-server=debug + +CHAIN_ID=2008 +EVMS=1 + +PERM_STORAGE=inmemory +TEMP_STORAGE=inmemory + +EXTERNAL_RPC=http://spec.testnet.cloudwalk.network:9934/ +EXTERNAL_RPC_WS=ws://spec.testnet.cloudwalk.network:9946/ diff --git a/justfile b/justfile index 9465a7253..b6e883218 100644 --- a/justfile +++ b/justfile @@ -8,8 +8,6 @@ export RUST_BACKTRACE := env("RUST_BACKTRACE", "0") nightly_flag := if env("NIGHTLY", "") =~ "(true|1)" { "+nightly" } else { "" } release_flag := if env("RELEASE", "") =~ "(true|1)" { "--release" } else { "" } database_url := env("DATABASE_URL", "postgres://postgres:123@0.0.0.0:5432/stratus") -external_rpc := "http://spec.testnet.cloudwalk.network:9934/" -external_rpc_ws := "ws://spec.testnet.cloudwalk.network:9946/" # Project: Show available tasks default: @@ -92,8 +90,8 @@ stratus *args="": cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --leader {{args}} # Bin: Stratus main service as follower -stratus-follower external_rpc=external_rpc external_rpc_ws=external_rpc_ws *args="": - cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --follower --external-rpc {{external_rpc}} --external-rpc-ws {{external_rpc_ws}} {{args}} +stratus-follower *args="": + LOCAL_ENV_PATH=stratus-follower cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --follower {{args}} # Bin: Download external RPC blocks and receipts to temporary storage rpc-downloader *args="": diff --git a/src/config.rs b/src/config.rs index 24e9de709..3a2f5b9c2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,16 +35,23 @@ pub fn load_dotenv_file() { Ok(env) => Environment::from_str(env.as_str()), Err(_) => Ok(Environment::Local), }; - let env = match env { - Ok(env) => env, + + // determine the .env file to load + let env_filename = match env { + Ok(Environment::Local) => { + // local environment only + match std::env::var("LOCAL_ENV_PATH") { + Ok(local_path) => format!("config/{}.env.local", local_path), + Err(_) => format!("config/{}.env.local", build_info::binary_name()), + } + } + Ok(env) => format!("config/{}.env.{}", build_info::binary_name(), env), Err(e) => { println!("{e}"); return; } }; - // load .env file - let env_filename = format!("config/{}.env.{}", build_info::binary_name(), env); println!("reading env file | filename={}", env_filename); if let Err(e) = dotenvy::from_filename(env_filename) {