From e8fae5d2d282bd73b8915dc9bf3355813cc1918c Mon Sep 17 00:00:00 2001 From: Joe Bellus Date: Mon, 14 Feb 2022 22:22:07 -0500 Subject: [PATCH] Fixes to database path when using --data opt --- Cargo.toml | 2 +- Dockerfile | 2 +- src/main.rs | 16 +++++++++------- src/socket_session.rs | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f0b02b..bce2d54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ tokio = { version = "1.16.1", features=["full"] } base64 = "0.13.0" sqlx = { version = "^0.5", features=["sqlite", "migrate"] } reqwest = { version = "0.11.9", features = ["rustls-tls"], default-features=false } -clap = { version = "3.0.14", features=["cargo", "env"] } +clap = { version = "^3.0", features=["cargo", "env"] } [target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator] diff --git a/Dockerfile b/Dockerfile index 6585cde..3d3e2d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,4 @@ COPY target/x86_64-unknown-linux-musl/release/vade /app/vade EXPOSE 8089 WORKDIR app RUN mkdir data -CMD ["./vade", "--db data/"] +CMD ./vade --data data/ diff --git a/src/main.rs b/src/main.rs index a8f747e..b0c630f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, path::Path}; use actix::SystemService; use actix_web::{get, web, App, HttpResponse, HttpServer}; -use clap::crate_version; +use clap::rate_version; use rust_embed::RustEmbed; use sea_orm::{prelude::*, Database}; use tokio::sync::Mutex; @@ -29,7 +29,7 @@ pub struct AppState { #[actix_rt::main] async fn main() { let opts = clap::App::new("Vade Mecum") - .version(crate_version!()) + .version(rate_version!()) .arg( clap::Arg::new("port") .short('p') @@ -172,13 +172,15 @@ async fn dist(path: web::Path) -> HttpResponse { #[instrument] async fn setup_database(db_path: &str) -> error::Result { let db_fname = "data.db"; - - if !Path::new(db_path).join(db_fname).exists() { - std::fs::File::create(db_fname)?; + let full_path = Path::new(db_path).join(db_fname); + println!("path: {:?}", full_path); + if !full_path.exists() { + std::fs::File::create(full_path.clone())?; } - let pool = sqlx::SqlitePool::connect("sqlite://data.db").await?; + let conn = format!("sqlite://{}", full_path.to_str().unwrap()); + let pool = sqlx::SqlitePool::connect(&conn).await?; sqlx::migrate!("./migrations").run(&pool).await?; tracing::info!("Database migrated"); - Ok(Database::connect("sqlite://data.db").await?) + Ok(Database::connect(&conn).await?) } diff --git a/src/socket_session.rs b/src/socket_session.rs index 70a4a87..7ee8e3c 100644 --- a/src/socket_session.rs +++ b/src/socket_session.rs @@ -59,6 +59,7 @@ impl StreamHandler> for EventSession { } } +#[tracing::instrument(skip(req, stream, state))] pub async fn event_session_index( req: HttpRequest, stream: web::Payload,