ci: docker_tag=ext - Fix config file reading logic to properly read from file when env vars are missing

This commit is contained in:
4NK Dev 2025-09-21 21:04:08 +00:00
parent 0a02c708fc
commit 0180d32472

View File

@ -46,28 +46,32 @@ impl Config {
}
}
// 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 from file to complete missing environment variables
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;
}
// 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());
// Split the line into key and value
if let Some((k, v)) = l.split_once('=') {
let key = k.trim().to_owned();
let value = v.trim().trim_matches('\"').to_owned();
// Only insert if not already set by environment variables
if !file_content.contains_key(&key) {
file_content.insert(key, value);
}
}
}
} else {
return Err(anyhow::Error::msg("Failed to find conf file and no environment variables set"));
}
} else if file_content.is_empty() {
return Err(anyhow::Error::msg("Failed to find conf file and no environment variables set"));
}
// Now set the Config