feat: configurable port, use HUB_DATA and HUB_PORT env vars
This commit is contained in:
1 parent
6be745a6f4
commit
248146056a
5 files changed
+16
-12
No files matched your search
+4
-3
@@ -437,9 +437,10 @@ class App(ChatMixin):
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
# Get data directory from environment variable
|
# Get data directory from environment variable
|
||||||
data_directory = os.getenv("HORDE_DATA_DIR")
|
data_directory = os.getenv("HUB_DATA")
|
||||||
if not data_directory:
|
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
|
# 1. Initialize Database First
|
||||||
await db.init_database(data_directory)
|
await db.init_database(data_directory)
|
||||||
@@ -456,7 +457,7 @@ async def main():
|
|||||||
# manually trigger server shutdown, avoids hypercorn installing signal handlers
|
# manually trigger server shutdown, avoids hypercorn installing signal handlers
|
||||||
shutdown_event = asyncio.Event()
|
shutdown_event = asyncio.Event()
|
||||||
# TODO: get port from env or don't pass it (actually server should handle none)
|
# 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
|
# 4. Graceful Termination
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ def tortoise_config(data_directory):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Only used for tortoise tool
|
# 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
|
# Considering creating a migration script "makemigration.py" or similar, that will load the config and make migration
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def encode_json(value):
|
|||||||
return repr(value)
|
return repr(value)
|
||||||
return json.dumps(value, default=encode_unknown)
|
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 = Quart(__name__, static_folder=frontend_path)
|
||||||
server.secret_key = 'horde-secret'
|
server.secret_key = 'horde-secret'
|
||||||
auth_manager = QuartAuth(server, mode="bearer")
|
auth_manager = QuartAuth(server, mode="bearer")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export OPENAI_API_KEY=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
|
|||||||
export REPLICATE_API_KEY=r8_J1lnphqfZNUtK9CIh81SE4uHWWKJuvR3tr8S2
|
export REPLICATE_API_KEY=r8_J1lnphqfZNUtK9CIh81SE4uHWWKJuvR3tr8S2
|
||||||
export OPENROUTER_API_KEY=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
|
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
|
echo Starting Horde Server
|
||||||
$INSTALL_PATH/.venv/bin/python3 $INSTALL_PATH/backend/src/app.py
|
$INSTALL_PATH/.venv/bin/python3 $INSTALL_PATH/backend/src/app.py
|
||||||
@@ -11,11 +11,11 @@ else
|
|||||||
echo "Write a .env file with the variables: REPLICATE_API_TOKEN"
|
echo "Write a .env file with the variables: REPLICATE_API_TOKEN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export HORDE_DATA_DIR=$(realpath ./local-data)
|
export HUB_DATA=$(realpath ./local-data)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"")
|
"")
|
||||||
mkdir -p $HORDE_DATA_DIR
|
mkdir -p $HUB_DATA
|
||||||
python backend/src/app.py
|
python backend/src/app.py
|
||||||
;;
|
;;
|
||||||
"cli")
|
"cli")
|
||||||
@@ -23,9 +23,9 @@ case "$1" in
|
|||||||
node cli/main.js "$2"
|
node cli/main.js "$2"
|
||||||
;;
|
;;
|
||||||
"test")
|
"test")
|
||||||
export HORDE_DATA_DIR=$(realpath ./test-data)
|
export HUB_DATA=$(realpath ./test-data)
|
||||||
mkdir -p $HORDE_DATA_DIR
|
mkdir -p $HUB_DATA
|
||||||
rm -rf $HORDE_DATA_DIR/*
|
rm -rf $HUB_DATA/*
|
||||||
|
|
||||||
# Start backend in the background
|
# Start backend in the background
|
||||||
python backend/src/app.py &
|
python backend/src/app.py &
|
||||||
@@ -63,7 +63,7 @@ case "$1" in
|
|||||||
# Execute with custom home directory if it exists
|
# Execute with custom home directory if it exists
|
||||||
*)
|
*)
|
||||||
if [ -d "$1" ]; then
|
if [ -d "$1" ]; then
|
||||||
export HORDE_DATA_DIR=$(realpath $1)
|
export HUB_DATA=$(realpath $1)
|
||||||
python backend/src/app.py
|
python backend/src/app.py
|
||||||
else
|
else
|
||||||
echo "Error: unknown command or directory '$1'"
|
echo "Error: unknown command or directory '$1'"
|
||||||
|
|||||||
Reference in new issue
Block a user