From 220dcc30d4517a8bb0f97c6740a14b475f84e437 Mon Sep 17 00:00:00 2001 From: John Kristensen Date: Thu, 10 Apr 2025 11:48:57 +1000 Subject: [PATCH] Only create DB directory if using embedded DB If an external database is being used there is no need to create the local database files. This prevents the database files from being created unless the embedded database is being used. --- entrypoint.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index c7fb543e..6753353f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,10 @@ #!/bin/sh set -e +if [ "$DATABASE_URL" = "postgresql://postgres@localhost:5432/sourcebot" ]; then + DATABASE_EMBEDDED="true" +fi + echo -e "\e[34m[Info] Sourcebot version: $NEXT_PUBLIC_SOURCEBOT_VERSION\e[0m" # If we don't have a PostHog key, then we need to disable telemetry. @@ -30,7 +34,7 @@ if [ ! -d "$DATA_CACHE_DIR" ]; then fi # Check if DATABASE_DATA_DIR exists, if not initialize it -if [ ! -d "$DATABASE_DATA_DIR" ]; then +if [ "$DATABASE_EMBEDDED" = "true" ] && [ ! -d "$DATABASE_DATA_DIR" ]; then echo -e "\e[34m[Info] Initializing database at $DATABASE_DATA_DIR...\e[0m" mkdir -p $DATABASE_DATA_DIR && chown -R postgres:postgres "$DATABASE_DATA_DIR" su postgres -c "initdb -D $DATABASE_DATA_DIR" @@ -129,7 +133,7 @@ echo "{\"version\": \"$NEXT_PUBLIC_SOURCEBOT_VERSION\", \"install_id\": \"$SOURC # Start the database and wait for it to be ready before starting any other service -if [ "$DATABASE_URL" = "postgresql://postgres@localhost:5432/sourcebot" ]; then +if [ "$DATABASE_EMBEDDED" = "true" ]; then su postgres -c "postgres -D $DATABASE_DATA_DIR" & until pg_isready -h localhost -p 5432 -U postgres; do echo -e "\e[34m[Info] Waiting for the database to be ready...\e[0m"