ci: docker_tag=ext

Support des variables d'environnement dans config.rs:
- Lecture prioritaire des variables d'environnement
- Fallback vers fichier de configuration si variables non définies
- Support des variables SDK_RELAY_* centralisées dans lecoffre_node
This commit is contained in:
4NK Dev 2025-09-21 20:21:00 +00:00
parent 7c985add5c
commit 664c1542be
2 changed files with 40 additions and 30 deletions

16
.env
View File

@ -1,16 +0,0 @@
core_url=http://bitcoin:38332
ws_url=0.0.0.0:8090
wallet_name=default
network=signet
blindbit_url=http://localhost:8000
zmq_url=tcp://bitcoin:29000
storage=https://dev4.4nkweb.com/storage
data_dir=/home/bitcoin/.4nk
bitcoin_data_dir=/home/bitcoin/.bitcoin
bootstrap_url=ws://dev3.4nkweb.com:8090
bootstrap_faucet=true
RUST_LOG=DEBUG,reqwest=DEBUG,tokio_tungstenite=DEBUG
NODE_OPTIONS=--max-old-space-size=2048
SIGNER_API_KEY=your-api-key-change-this
VITE_JWT_SECRET_KEY=52b3d77617bb00982dfee15b08effd52cfe5b2e69b2f61cc4848cfe1e98c0bc9

View File

@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::{self, BufRead};
use std::env;
use anyhow::{Error, Result};
@ -23,25 +24,50 @@ pub struct Config {
impl Config {
pub fn read_from_file(filename: &str) -> Result<Self> {
let mut file_content = HashMap::new();
if let Ok(file) = File::open(filename) {
let reader = io::BufReader::new(file);
// Try to read from environment variables first
let env_vars = [
("core_url", "CORE_URL"),
("ws_url", "WS_URL"),
("wallet_name", "WALLET_NAME"),
("network", "NETWORK"),
("blindbit_url", "BLINDBIT_URL"),
("zmq_url", "ZMQ_URL"),
("storage", "STORAGE"),
("data_dir", "DATA_DIR"),
("bitcoin_data_dir", "BITCOIN_DATA_DIR"),
("bootstrap_url", "BOOTSTRAP_URL"),
("bootstrap_faucet", "BOOTSTRAP_FAUCET"),
];
// Read the file line by line
for line in reader.lines() {
if let Ok(l) = line {
// Ignore comments and empty lines
if l.starts_with('#') || l.trim().is_empty() {
continue;
}
for (config_key, env_key) in env_vars.iter() {
if let Ok(env_value) = env::var(env_key) {
file_content.insert(config_key.to_string(), env_value);
}
}
// Split the line into key and value
if let Some((k, v)) = l.split_once('=') {
file_content.insert(k.to_owned(), v.trim_matches('\"').to_owned());
// Fallback to file if environment variables are not set
if file_content.is_empty() {
if let Ok(file) = File::open(filename) {
let reader = io::BufReader::new(file);
// Read the file line by line
for line in reader.lines() {
if let Ok(l) = line {
// Ignore comments and empty lines
if l.starts_with('#') || l.trim().is_empty() {
continue;
}
// Split the line into key and value
if let Some((k, v)) = l.split_once('=') {
file_content.insert(k.to_owned(), v.trim_matches('\"').to_owned());
}
}
}
} else {
return Err(anyhow::Error::msg("Failed to find conf file and no environment variables set"));
}
} else {
return Err(anyhow::Error::msg("Failed to find conf file"));
}
// Now set the Config