add log level to config, create /data dir in docker image
This commit is contained in:
parent
8b59e2b32a
commit
12827ca37e
|
@ -34,7 +34,9 @@ ARG GID=1000
|
||||||
RUN adduser --disabled-password --gecos "" $UNAME -s -G $GID -u $UID
|
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
|
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
|
USER $UNAME
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ listen_address = "127.0.0.1"
|
||||||
listen_port = "3000"
|
listen_port = "3000"
|
||||||
url = "http://localhost:3000/"
|
url = "http://localhost:3000/"
|
||||||
|
|
||||||
|
# error, warn, info, debug, trace
|
||||||
|
log_level = "debug"
|
||||||
|
|
||||||
[storage]
|
[storage]
|
||||||
driver = "filesystem"
|
driver = "filesystem"
|
||||||
path = "/app/blobs"
|
path = "/app/blobs"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
use anyhow::anyhow;
|
||||||
use figment::{Figment, providers::{Env, Toml, Format}};
|
use figment::{Figment, providers::{Env, Toml, Format}};
|
||||||
use figment_cliarg_provider::FigmentCliArgsProvider;
|
use figment_cliarg_provider::FigmentCliArgsProvider;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Deserializer};
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
@ -56,6 +58,8 @@ pub struct Config {
|
||||||
pub listen_address: String,
|
pub listen_address: String,
|
||||||
pub listen_port: String,
|
pub listen_port: String,
|
||||||
url: Option<String>,
|
url: Option<String>,
|
||||||
|
#[serde(deserialize_with = "serialize_log_level", default = "default_log_level")]
|
||||||
|
pub log_level: Level,
|
||||||
pub ldap: Option<LdapConnectionConfig>,
|
pub ldap: Option<LdapConnectionConfig>,
|
||||||
pub database: DatabaseConfig,
|
pub database: DatabaseConfig,
|
||||||
pub storage: StorageConfig,
|
pub storage: StorageConfig,
|
||||||
|
@ -102,4 +106,30 @@ impl Config {
|
||||||
None => format!("http://{}:{}", self.listen_address, self.listen_port)
|
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
|
12
src/main.rs
12
src/main.rs
|
@ -24,7 +24,7 @@ use tower_layer::Layer;
|
||||||
use sqlx::sqlite::{SqlitePoolOptions, SqliteConnectOptions, SqliteJournalMode};
|
use sqlx::sqlite::{SqlitePoolOptions, SqliteConnectOptions, SqliteJournalMode};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tower_http::normalize_path::NormalizePathLayer;
|
use tower_http::normalize_path::NormalizePathLayer;
|
||||||
use tracing::{debug, Level};
|
use tracing::{debug, Level, info};
|
||||||
|
|
||||||
use app_state::AppState;
|
use app_state::AppState;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
@ -62,13 +62,13 @@ async fn change_request_paths<B>(mut request: Request<B>, next: Next<B>) -> Resu
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
tracing_subscriber::fmt()
|
|
||||||
.with_max_level(Level::DEBUG)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let config = Config::new()
|
let config = Config::new()
|
||||||
.expect("Failure to parse config!");
|
.expect("Failure to parse config!");
|
||||||
|
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_max_level(config.log_level)
|
||||||
|
.init();
|
||||||
|
|
||||||
let sqlite_config = match &config.database {
|
let sqlite_config = match &config.database {
|
||||||
DatabaseConfig::Sqlite(sqlite) => sqlite,
|
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));
|
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)
|
axum::Server::bind(&app_addr)
|
||||||
.serve(layered_app.into_make_service())
|
.serve(layered_app.into_make_service())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
Loading…
Reference in New Issue