Skip to content

Commit

Permalink
enha: allow custom env when local (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-aranha-cw authored Aug 6, 2024
1 parent 8951b35 commit 6d55242
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 10 additions & 0 deletions config/stratus-follower.env.local
Original file line number Diff line number Diff line change
@@ -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/
6 changes: 2 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:5432/stratus")
external_rpc := "http://spec.testnet.cloudwalk.network:9934/"
external_rpc_ws := "ws://spec.testnet.cloudwalk.network:9946/"

# Project: Show available tasks
default:
Expand Down Expand Up @@ -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="":
Expand Down
15 changes: 11 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6d55242

Please sign in to comment.