add log level to config, create /data dir in docker image

This commit is contained in:
SeanOMik 2023-06-17 00:55:12 -04:00
parent 8b59e2b32a
commit 12827ca37e
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
4 changed files with 44 additions and 9 deletions

View File

@ -34,7 +34,9 @@ ARG GID=1000
RUN adduser --disabled-password --gecos "" $UNAME -s -G $GID -u $UID
COPY --from=builder --chown=$UID:$GID /app/src/target/release/orca-registry /app/orca-registry
RUN chown -R $UID:$GID /app
RUN mkdir /data && \
chown -R $UID:$GID /data && \
chown -R $UID:$GID /app
USER $UNAME

View File

@ -2,6 +2,9 @@ listen_address = "127.0.0.1"
listen_port = "3000"
url = "http://localhost:3000/"
# error, warn, info, debug, trace
log_level = "debug"
[storage]
driver = "filesystem"
path = "/app/blobs"

View File

@ -1,6 +1,8 @@
use anyhow::anyhow;
use figment::{Figment, providers::{Env, Toml, Format}};
use figment_cliarg_provider::FigmentCliArgsProvider;
use serde::Deserialize;
use serde::{Deserialize, Deserializer};
use tracing::Level;
use std::env;
@ -56,6 +58,8 @@ pub struct Config {
pub listen_address: String,
pub listen_port: String,
url: Option<String>,
#[serde(deserialize_with = "serialize_log_level", default = "default_log_level")]
pub log_level: Level,
pub ldap: Option<LdapConnectionConfig>,
pub database: DatabaseConfig,
pub storage: StorageConfig,
@ -102,4 +106,30 @@ impl Config {
None => format!("http://{}:{}", self.listen_address, self.listen_port)
}
}
}
}
fn default_log_level() -> Level {
Level::INFO
}
fn serialize_log_level<'de, D>(deserializer: D) -> Result<Level, D::Error>
where D: Deserializer<'de> {
let s = String::deserialize(deserializer)?.to_lowercase();
let s = s.as_str();
match s {
"error" => Ok(Level::ERROR),
"warn" => Ok(Level::WARN),
"info" => Ok(Level::INFO),
"debug" => Ok(Level::DEBUG),
"trace" => Ok(Level::TRACE),
_ => Err(serde::de::Error::custom(format!("Unknown log level: '{}'", s))),
}
}
/* fn<'de, D> serialize_log_level(D) -> Result<Level, D::Error>
where D: Deserializer<'de>
{
} */
//fn serialize_log_level() -> Level

View File

@ -24,7 +24,7 @@ use tower_layer::Layer;
use sqlx::sqlite::{SqlitePoolOptions, SqliteConnectOptions, SqliteJournalMode};
use tokio::sync::Mutex;
use tower_http::normalize_path::NormalizePathLayer;
use tracing::{debug, Level};
use tracing::{debug, Level, info};
use app_state::AppState;
use database::Database;
@ -62,13 +62,13 @@ async fn change_request_paths<B>(mut request: Request<B>, next: Next<B>) -> Resu
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
.init();
let config = Config::new()
.expect("Failure to parse config!");
tracing_subscriber::fmt()
.with_max_level(config.log_level)
.init();
let sqlite_config = match &config.database {
DatabaseConfig::Sqlite(sqlite) => sqlite,
};
@ -136,7 +136,7 @@ async fn main() -> anyhow::Result<()> {
let layered_app = NormalizePathLayer::trim_trailing_slash().layer(path_middleware.layer(app));
debug!("Starting http server, listening on {}", app_addr);
info!("Starting http server, listening on {}", app_addr);
axum::Server::bind(&app_addr)
.serve(layered_app.into_make_service())
.await?;