Require DATABASE_URL to be set

This commit is contained in:
Imbus 2023-11-06 00:23:44 +01:00
parent b2095e98fb
commit 757e670dbb
3 changed files with 10 additions and 2 deletions

View file

@ -28,6 +28,8 @@ RUN addgroup -S user && adduser -S user -G user
WORKDIR /runner WORKDIR /runner
# Copy the server binary and the public directory, note the debug binary # 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 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 # Make sure the user can access the files
RUN chown -R user:user /runner RUN chown -R user:user /runner

View file

@ -22,7 +22,7 @@ build-container-server-debug:
# Builds a debug container and runs it # Builds a debug container and runs it
[private] [private]
start-debug: build-container-server-debug remove-podman-containers 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." @echo "Debug server started."
# Builds a release container # Builds a release container
@ -32,6 +32,7 @@ build-container-release:
# Builds a release container and runs it # Builds a release container and runs it
start-release: build-container-release remove-podman-containers 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 {{runtime}} run -d --network fb_network -e DATABASE_URL=sqlite:release.db -p 8080:8080 --name frostbyte fb-server
init-sqlx: init-sqlx:
@ -43,6 +44,7 @@ init-sqlx:
# Removes and stops any containers related to the project # Removes and stops any containers related to the project
[private] [private]
remove-podman-containers: remove-podman-containers:
{{runtime}} network rm -f fb_network
{{runtime}} container rm -f frostbyte {{runtime}} container rm -f frostbyte
{{runtime}} container rm -f frostbyte-debug {{runtime}} container rm -f frostbyte-debug

View file

@ -31,7 +31,11 @@ impl ServerState {
pub async fn new() -> Self { pub async fn new() -> Self {
// This is almost certainly bad practice for more reasons than I can count // This is almost certainly bad practice for more reasons than I can count
dotenvy::dotenv().ok(); 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); info!("Using db_url: {}", &db_url);
if !sqlx::Sqlite::database_exists(&db_url).await.unwrap() { if !sqlx::Sqlite::database_exists(&db_url).await.unwrap() {