diff --git a/backend/src/app.py b/backend/src/app.py index 46a654e..1c67a55 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -437,9 +437,10 @@ class App(ChatMixin): async def main(): # Get data directory from environment variable - data_directory = os.getenv("HORDE_DATA_DIR") + data_directory = os.getenv("HUB_DATA") if not data_directory: - raise ValueError("HORDE_DATA_DIR environment variable must be set") + raise ValueError("HUB_DATA environment variable must be set") + port = os.getenv("HUB_PORT", 17922) # 1. Initialize Database First await db.init_database(data_directory) @@ -456,7 +457,7 @@ async def main(): # manually trigger server shutdown, avoids hypercorn installing signal handlers shutdown_event = asyncio.Event() # TODO: get port from env or don't pass it (actually server should handle none) - server_task = asyncio.create_task(start_server(horde_app, shutdown_event)) + server_task = asyncio.create_task(start_server(horde_app, port, shutdown_event)) # 4. Graceful Termination loop = asyncio.get_running_loop() diff --git a/backend/src/database.py b/backend/src/database.py index d53f6c2..3418151 100644 --- a/backend/src/database.py +++ b/backend/src/database.py @@ -23,7 +23,9 @@ def tortoise_config(data_directory): } # Only used for tortoise tool -TORTOISE_ORM=tortoise_config(os.getenv("HORDE_DATA_DIR")) +# TODO: Should move somewhere tool specific and using the same directory as app +# computing this here unconditionally is dirty +TORTOISE_ORM=tortoise_config(os.getenv("HUB_DATA")) # Considering creating a migration script "makemigration.py" or similar, that will load the config and make migration diff --git a/backend/src/server.py b/backend/src/server.py index c02510f..267bae2 100644 --- a/backend/src/server.py +++ b/backend/src/server.py @@ -25,7 +25,7 @@ def encode_json(value): return repr(value) return json.dumps(value, default=encode_unknown) -async def start_server(app, shutdown_event, port=17922): +async def start_server(app, port, shutdown_event): server = Quart(__name__, static_folder=frontend_path) server.secret_key = 'horde-secret' auth_manager = QuartAuth(server, mode="bearer") diff --git a/deploy/template/launch-hub.sh b/deploy/template/launch-hub.sh index c4de0e6..98c28c9 100644 --- a/deploy/template/launch-hub.sh +++ b/deploy/template/launch-hub.sh @@ -4,6 +4,7 @@ export OPENAI_API_KEY=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 export REPLICATE_API_KEY=r8_J1lnphqfZNUtK9CIh81SE4uHWWKJuvR3tr8S2 export OPENROUTER_API_KEY=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 -export HORDE_DATA_DIR=$DATA_PATH +export HUB_DATA=$DATA_PATH +export HUB_PORT=$PORT echo Starting Horde Server $INSTALL_PATH/.venv/bin/python3 $INSTALL_PATH/backend/src/app.py \ No newline at end of file diff --git a/run.sh b/run.sh index 0928329..1442851 100644 --- a/run.sh +++ b/run.sh @@ -11,11 +11,11 @@ else echo "Write a .env file with the variables: REPLICATE_API_TOKEN" fi -export HORDE_DATA_DIR=$(realpath ./local-data) +export HUB_DATA=$(realpath ./local-data) case "$1" in "") - mkdir -p $HORDE_DATA_DIR + mkdir -p $HUB_DATA python backend/src/app.py ;; "cli") @@ -23,9 +23,9 @@ case "$1" in node cli/main.js "$2" ;; "test") - export HORDE_DATA_DIR=$(realpath ./test-data) - mkdir -p $HORDE_DATA_DIR - rm -rf $HORDE_DATA_DIR/* + export HUB_DATA=$(realpath ./test-data) + mkdir -p $HUB_DATA + rm -rf $HUB_DATA/* # Start backend in the background python backend/src/app.py & @@ -63,7 +63,7 @@ case "$1" in # Execute with custom home directory if it exists *) if [ -d "$1" ]; then - export HORDE_DATA_DIR=$(realpath $1) + export HUB_DATA=$(realpath $1) python backend/src/app.py else echo "Error: unknown command or directory '$1'"