build(config.yml): reintroduce mounting config.yaml

This commit is contained in:
Krrish Dholakia 2024-01-10 18:03:57 +05:30
parent 94259c944a
commit b06d7f0cb6
3 changed files with 24 additions and 31 deletions

View file

@ -103,9 +103,10 @@ jobs:
command: |
docker run -d \
-p 4000:4000 \
-e DATABASE_URL=$PROXY_DOCKER_DB_URL \
--name my-app \
my-app:latest
-v $(pwd)/proxy_server_config.yaml:/app/config.yaml \
my-app:latest \
--config /app/config.yaml
- run:
name: Install curl and dockerize
command: |

View file

@ -5,7 +5,7 @@ import random
from datetime import datetime
import importlib
from dotenv import load_dotenv
import operator
sys.path.append(os.getcwd())
@ -32,29 +32,6 @@ def run_ollama_serve():
) # noqa
def clone_subfolder(repo_url, subfolder, destination):
# Clone the full repo
repo_name = repo_url.split("/")[-1]
repo_master = os.path.join(destination, "repo_master")
subprocess.run(["git", "clone", repo_url, repo_master])
# Move into the subfolder
subfolder_path = os.path.join(repo_master, subfolder)
# Copy subfolder to destination
for file_name in os.listdir(subfolder_path):
source = os.path.join(subfolder_path, file_name)
if os.path.isfile(source):
shutil.copy(source, destination)
else:
dest_path = os.path.join(destination, file_name)
shutil.copytree(source, dest_path)
# Remove cloned repo folder
subprocess.run(["rm", "-rf", os.path.join(destination, "repo_master")])
feature_telemetry(feature="create-proxy")
def is_port_in_use(port):
import socket
@ -371,6 +348,20 @@ def run_server(
raise ImportError(
"Uvicorn needs to be imported. Run - `pip install uvicorn`"
)
if os.getenv("DATABASE_URL", None) is not None:
# run prisma db push, before starting server
# Save the current working directory
original_dir = os.getcwd()
# set the working directory to where this script is
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
try:
subprocess.run(
["prisma", "db", "push", "--accept-data-loss"]
) # this looks like a weird edge case when prisma just wont start on render. we need to have the --accept-data-loss
finally:
os.chdir(original_dir)
if port == 8000 and is_port_in_use(port):
port = random.randint(1024, 49152)
uvicorn.run(

View file

@ -253,10 +253,11 @@ class PrismaClient:
print_verbose(
"LiteLLM: DATABASE_URL Set in config, trying to 'pip install prisma'"
)
## init logging object
## init logging object
self.proxy_logging_obj = proxy_logging_obj
if os.getenv("DATABASE_URL", None) is None: # setup hasn't taken place
try:
from prisma import Prisma # type: ignore
except:
os.environ["DATABASE_URL"] = database_url
# Save the current working directory
original_dir = os.getcwd()
@ -272,8 +273,8 @@ class PrismaClient:
) # this looks like a weird edge case when prisma just wont start on render. we need to have the --accept-data-loss
finally:
os.chdir(original_dir)
# Now you can import the Prisma Client
from prisma import Prisma # type: ignore
# Now you can import the Prisma Client
from prisma import Prisma # type: ignore
self.db = Prisma(
http={