forked from phoenix/litellm-mirror
build(Dockerfile): fixes the build time setup
This commit is contained in:
parent
0f7c37355a
commit
a7245dba07
4 changed files with 52 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -31,3 +31,4 @@ proxy_server_config_@.yaml
|
||||||
.gitignore
|
.gitignore
|
||||||
proxy_server_config_2.yaml
|
proxy_server_config_2.yaml
|
||||||
litellm/proxy/secret_managers/credentials.json
|
litellm/proxy/secret_managers/credentials.json
|
||||||
|
hosted_config.yaml
|
||||||
|
|
31
Dockerfile
31
Dockerfile
|
@ -1,10 +1,36 @@
|
||||||
|
# Base image for building
|
||||||
|
ARG LITELLM_BUILD_IMAGE=python:3.9
|
||||||
|
|
||||||
# Runtime image
|
# Runtime image
|
||||||
ARG LITELLM_RUNTIME_IMAGE=python:3.9-slim
|
ARG LITELLM_RUNTIME_IMAGE=python:3.9-slim
|
||||||
# Builder stage
|
# Builder stage
|
||||||
FROM $LITELLM_BUILD_IMAGE as builder
|
FROM $LITELLM_BUILD_IMAGE as builder
|
||||||
|
|
||||||
@@ -35,8 +34,12 @@ RUN pip wheel --no-cache-dir --wheel-dir=/wheels/ -r requirements.txt
|
# Set the working directory to /app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install build dependencies
|
||||||
|
RUN apt-get clean && apt-get update && \
|
||||||
|
apt-get install -y gcc python3-dev && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip && \
|
||||||
|
pip install build
|
||||||
|
|
||||||
|
# Copy the current directory contents into the container at /app
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the package
|
||||||
|
RUN rm -rf dist/* && python -m build
|
||||||
|
|
||||||
|
# There should be only one wheel file now, assume the build only creates one
|
||||||
|
RUN ls -1 dist/*.whl | head -1
|
||||||
|
|
||||||
|
# Install the package
|
||||||
|
RUN pip install dist/*.whl
|
||||||
|
|
||||||
|
# install dependencies as wheels
|
||||||
|
RUN pip wheel --no-cache-dir --wheel-dir=/wheels/ -r requirements.txt
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
FROM $LITELLM_RUNTIME_IMAGE as runtime
|
FROM $LITELLM_RUNTIME_IMAGE as runtime
|
||||||
|
@ -17,7 +43,8 @@ RUN ls -la /app
|
||||||
|
|
||||||
# Copy the built wheel from the builder stage to the runtime stage; assumes only one wheel file is present
|
# Copy the built wheel from the builder stage to the runtime stage; assumes only one wheel file is present
|
||||||
COPY --from=builder /app/dist/*.whl .
|
COPY --from=builder /app/dist/*.whl .
|
||||||
@@ -45,9 +48,17 @@ COPY --from=builder /wheels/ /wheels/
|
COPY --from=builder /wheels/ /wheels/
|
||||||
|
|
||||||
# Install the built wheel using pip; again using a wildcard if it's the only file
|
# Install the built wheel using pip; again using a wildcard if it's the only file
|
||||||
RUN pip install *.whl /wheels/* --no-index --find-links=/wheels/ && rm -f *.whl && rm -rf /wheels
|
RUN pip install *.whl /wheels/* --no-index --find-links=/wheels/ && rm -f *.whl && rm -rf /wheels
|
||||||
|
|
||||||
|
|
|
@ -1103,6 +1103,11 @@ async def startup_event():
|
||||||
# check if master key set in environment - load from there
|
# check if master key set in environment - load from there
|
||||||
master_key = litellm.get_secret("LITELLM_MASTER_KEY", None)
|
master_key = litellm.get_secret("LITELLM_MASTER_KEY", None)
|
||||||
|
|
||||||
|
### CONNECT TO DB ###
|
||||||
|
# check if DATABASE_URL in environment - load from there
|
||||||
|
if os.getenv("DATABASE_URL", None) is not None and prisma_client is None:
|
||||||
|
prisma_setup(database_url=os.getenv("DATABASE_URL"))
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
worker_config = litellm.get_secret("WORKER_CONFIG")
|
worker_config = litellm.get_secret("WORKER_CONFIG")
|
||||||
print_verbose(f"worker_config: {worker_config}")
|
print_verbose(f"worker_config: {worker_config}")
|
||||||
|
|
|
@ -253,23 +253,25 @@ class PrismaClient:
|
||||||
print_verbose(
|
print_verbose(
|
||||||
"LiteLLM: DATABASE_URL Set in config, trying to 'pip install prisma'"
|
"LiteLLM: DATABASE_URL Set in config, trying to 'pip install prisma'"
|
||||||
)
|
)
|
||||||
## init logging object
|
## init logging object
|
||||||
self.proxy_logging_obj = proxy_logging_obj
|
self.proxy_logging_obj = proxy_logging_obj
|
||||||
os.environ["DATABASE_URL"] = database_url
|
|
||||||
# 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:
|
if os.getenv("DATABASE_URL", None) is None: # setup hasn't taken place
|
||||||
subprocess.run(["prisma", "generate"])
|
os.environ["DATABASE_URL"] = database_url
|
||||||
subprocess.run(
|
# Save the current working directory
|
||||||
["prisma", "db", "push", "--accept-data-loss"]
|
original_dir = os.getcwd()
|
||||||
) # this looks like a weird edge case when prisma just wont start on render. we need to have the --accept-data-loss
|
# set the working directory to where this script is
|
||||||
finally:
|
abspath = os.path.abspath(__file__)
|
||||||
os.chdir(original_dir)
|
dname = os.path.dirname(abspath)
|
||||||
|
os.chdir(dname)
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.run(["prisma", "generate"])
|
||||||
|
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)
|
||||||
# Now you can import the Prisma Client
|
# Now you can import the Prisma Client
|
||||||
from prisma import Prisma # type: ignore
|
from prisma import Prisma # type: ignore
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue