From 757e670dbb2de9a7fcd67181615a4303cb88ed83 Mon Sep 17 00:00:00 2001 From: Imbus Date: Mon, 6 Nov 2023 00:23:44 +0100 Subject: [PATCH] Require DATABASE_URL to be set --- container/ContainerfileDebug | 2 ++ justfile | 4 +++- server/src/state.rs | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/container/ContainerfileDebug b/container/ContainerfileDebug index 5fd4ef3..8b9166b 100644 --- a/container/ContainerfileDebug +++ b/container/ContainerfileDebug @@ -28,6 +28,8 @@ RUN addgroup -S user && adduser -S user -G user WORKDIR /runner # Copy the server binary and the public directory, note the debug binary COPY --from=builder /build/target/x86_64-unknown-linux-musl/debug/server /runner/server +RUN mkdir /runner/public +RUN echo "Debug build!" > /runner/public/index.html # Make sure the user can access the files RUN chown -R user:user /runner diff --git a/justfile b/justfile index 86c5efe..8d39699 100644 --- a/justfile +++ b/justfile @@ -22,7 +22,7 @@ build-container-server-debug: # Builds a debug container and runs it [private] start-debug: build-container-server-debug remove-podman-containers - {{runtime}} run -d -p 8080:8080 --name frostbyte-debug fb-server-debug + {{runtime}} run -d -e DATABASE_URL=sqlite:debug.db -p 8080:8080 --name frostbyte-debug fb-server-debug @echo "Debug server started." # Builds a release container @@ -32,6 +32,7 @@ build-container-release: # Builds a release container and runs it start-release: build-container-release remove-podman-containers + {{runtime}} network create fb_network --ignore {{runtime}} run -d --network fb_network -e DATABASE_URL=sqlite:release.db -p 8080:8080 --name frostbyte fb-server init-sqlx: @@ -43,6 +44,7 @@ init-sqlx: # Removes and stops any containers related to the project [private] remove-podman-containers: + {{runtime}} network rm -f fb_network {{runtime}} container rm -f frostbyte {{runtime}} container rm -f frostbyte-debug diff --git a/server/src/state.rs b/server/src/state.rs index b828927..51cda7b 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -31,7 +31,11 @@ impl ServerState { pub async fn new() -> Self { // This is almost certainly bad practice for more reasons than I can count dotenvy::dotenv().ok(); - let db_url = dotenvy::var("DATABASE_URL").unwrap_or(":memory:".to_string()); + let db_url = dotenvy::var("DATABASE_URL").unwrap_or_else(|_| { + error!("DATABASE_URL not set in environment!"); + std::process::exit(1); + }); + info!("Using db_url: {}", &db_url); if !sqlx::Sqlite::database_exists(&db_url).await.unwrap() {