Skip to content

Commit 78235f4

Browse files
committed
include default settings in binary, allow overriding settings path
1 parent 06f5e72 commit 78235f4

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

services/src/util/config.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::contexts::SessionId;
22
use crate::datasets::upload::VolumeName;
33
use crate::error::{self, Result};
44
use crate::util::parsing::{deserialize_api_prefix, deserialize_base_url_option};
5-
use config::{Config, Environment, File};
5+
use config::{Config, Environment, File, FileFormat};
66
use geoengine_datatypes::primitives::TimeInterval;
77
use geoengine_operators::util::raster_stream_to_geotiff::GdalCompressionNumThreads;
88
use serde::Deserialize;
@@ -15,26 +15,33 @@ use url::Url;
1515

1616
static SETTINGS: OnceLock<RwLock<Config>> = OnceLock::new();
1717

18+
const SETTINGS_FILE_PATH_OVERRIDE_ENV_VAR: &str = "GEOENGINE_SETTINGS_FILE_PATH";
19+
1820
// TODO: change to `LazyLock' once stable
1921
fn init_settings() -> RwLock<Config> {
2022
let mut settings = Config::builder();
2123

2224
let dir: PathBuf = retrieve_settings_dir().expect("settings directory should exist");
2325

24-
#[cfg(test)]
25-
let files = ["Settings-default.toml", "Settings-test.toml"];
26-
27-
#[cfg(not(test))]
28-
let files = ["Settings-default.toml", "Settings.toml"];
26+
// include the default settings in the binary
27+
let default_settings = include_str!("../../../Settings-default.toml");
2928

30-
let files: Vec<File<_, _>> = files
31-
.iter()
32-
.map(|f| dir.join(f))
33-
.filter(|p| p.exists())
34-
.map(File::from)
35-
.collect();
29+
settings = settings.add_source(File::from_str(default_settings, FileFormat::Toml));
3630

37-
settings = settings.add_source(files);
31+
if let Ok(settings_file_path) = std::env::var(SETTINGS_FILE_PATH_OVERRIDE_ENV_VAR) {
32+
// override the settings file path
33+
settings = settings.add_source(File::with_name(&settings_file_path));
34+
} else {
35+
// use the default settings file path
36+
#[cfg(test)]
37+
{
38+
settings = settings.add_source(File::from(dir.join("Settings-test.toml")));
39+
}
40+
#[cfg(not(test))]
41+
{
42+
settings = settings.add_source(File::from(dir.join("Settings.toml")));
43+
}
44+
}
3845

3946
// Override config with environment variables that start with `GEOENGINE_`,
4047
// e.g. `GEOENGINE_WEB__EXTERNAL_ADDRESS=https://path.to.geoengine.io`

services/tests/startup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl DroppingServer {
2020
fn new(schema_name: &str) -> Self {
2121
let process = Command::cargo_bin("main")
2222
.unwrap()
23-
.env("GEOENGINE_WEB__BACKEND", "postgres")
23+
.env("GEOENGINE_SETTINGS_FILE_PATH", "Settings-test.toml")
2424
.env("GEOENGINE_POSTGRES__SCHEMA", schema_name)
2525
.stderr(Stdio::piped())
2626
.spawn()

0 commit comments

Comments
 (0)