From 8ed77d7ab484121e9d70158e14c9fd6c243f1c70 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 12 Feb 2024 14:58:08 +0100 Subject: Close #9. Config impl with struct and files --- src/config.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 4c79810..e88ddab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,25 @@ -use config::Config; -use once_cell::sync::Lazy; +use config::File; +use serde::Deserialize; -pub static SETTINGS: Lazy = Lazy::new(setup); +#[derive(Debug, Clone, Deserialize)] +pub struct Config { + pub database_url: String, + pub apikey: String, + pub serveraddr: String, + pub pingtimeout: i64, +} + +impl Config { + pub fn load() -> Result { + let config = config::Config::builder() + .set_default("serveraddr", "0.0.0.0:7229")? + .set_default("pingtimeout", 10)? + .add_source(File::with_name("config.toml").required(false)) + .add_source(File::with_name("config.dev.toml").required(false)) + .add_source(config::Environment::with_prefix("WEBOL").separator("_")) + .build()?; + + config.try_deserialize() + } +} -fn setup() -> Config { - Config::builder() - .add_source(config::Environment::with_prefix("WEBOL").separator("_")) - .build() - .unwrap() -} \ No newline at end of file -- cgit v1.2.3 From c9034a7276dbdf87649c9946ef5072de58097259 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 12 Feb 2024 15:50:58 +0100 Subject: remove cargo chef --- Dockerfile | 15 ++++----------- src/config.rs | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'src/config.rs') diff --git a/Dockerfile b/Dockerfile index d4473e9..b75a0e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,22 +5,15 @@ RUN cd /tmp && \ mkdir /dpkg && \ for deb in *.deb; do dpkg --extract $deb /dpkg || exit 10; done -FROM lukemathwalker/cargo-chef:latest-rust-1.73.0 as chef -WORKDIR app - -FROM chef AS planner +FROM rust:1.76 as builder +WORKDIR /app COPY . . -RUN cargo chef prepare --recipe-path recipe.json +RUN SQLX_OFFLINE=true cargo install --path . -FROM chef as builder -COPY --from=planner /app/recipe.json recipe.json -RUN cargo chef cook --release --recipe-path recipe.json -COPY . . -RUN cargo build --release FROM gcr.io/distroless/cc COPY --from=builder /app/target/release/webol / COPY --from=deb_extractor /dpkg / EXPOSE 7229 -ENTRYPOINT ["./webol"] \ No newline at end of file +ENTRYPOINT ["./webol"] diff --git a/src/config.rs b/src/config.rs index e88ddab..4319ffc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,7 @@ impl Config { .set_default("pingtimeout", 10)? .add_source(File::with_name("config.toml").required(false)) .add_source(File::with_name("config.dev.toml").required(false)) - .add_source(config::Environment::with_prefix("WEBOL").separator("_")) + .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) .build()?; config.try_deserialize() -- cgit v1.2.3