build(Dockerfile.database): fixing build issues

This commit is contained in:
Krrish Dholakia 2024-01-08 19:31:12 +05:30
parent 6b3cf217a4
commit 4ff4180a53
3 changed files with 54 additions and 20 deletions

View file

@ -50,16 +50,6 @@ RUN pip install --no-cache-dir --find-links=/wheels/ -r requirements.txt \
&& pip install *.whl \
&& rm -f *.whl
# Check if the with_database argument is set to 'true'
RUN echo "Value of with_database is: ${with_database}"
# If true, execute the following instructions
RUN if [ "$with_database" = "true" ]; then \
prisma generate; \
chmod +x /app/retry_push.sh; \
/app/retry_push.sh; \
fi
EXPOSE 4000/tcp
# Set your entrypoint and command

View file

@ -45,20 +45,14 @@ COPY --from=builder /app/dist/*.whl .
COPY --from=builder /wheels/ /wheels/
# Install the built wheel using pip; again using a wildcard if it's the only file
RUN pip install --no-cache-dir --find-links=/wheels/ -r requirements.txt \
&& pip install *.whl \
RUN pip install *.whl \
&& rm -f *.whl
# If true, execute the following instructions
# Generate prisma client
RUN prisma generate
RUN chmod +x /app/retry_push.sh
RUN /app/retry_push.sh
RUN chmod +x entrypoint.sh
EXPOSE 4000/tcp
# Set your entrypoint and command
ENTRYPOINT ["litellm"]
CMD ["--num_workers", "8", "--port", "4000"]
CMD ["./entrypoint.sh"]

50
entrypoint.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/sh
# Check if DATABASE_URL is not set
if [ -z "$DATABASE_URL" ]; then
# Check if all required variables are provided
if [ -n "$DATABASE_HOST" ] && [ -n "$DATABASE_USERNAME" ] && [ -n "$DATABASE_PASSWORD" ] && [ -n "$DATABASE_NAME" ]; then
# Construct DATABASE_URL from the provided variables
DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}"
export DATABASE_URL
else
echo "Error: Required database environment variables are not set. Provide a postgres url for DATABASE_URL."
exit 1
fi
fi
# Set DIRECT_URL to the value of DATABASE_URL if it is not set, required for migrations
if [ -z "$DIRECT_URL" ]; then
export DIRECT_URL=$DATABASE_URL
fi
# Apply migrations
retry_count=0
max_retries=3
exit_code=1
until [ $retry_count -ge $max_retries ] || [ $exit_code -eq 0 ]
do
retry_count=$((retry_count+1))
echo "Attempt $retry_count..."
# Run the Prisma db push command
prisma db push --accept-data-loss
exit_code=$?
if [ $exit_code -ne 0 ] && [ $retry_count -lt $max_retries ]; then
echo "Retrying in 10 seconds..."
sleep 10
fi
done
if [ $exit_code -ne 0 ]; then
echo "Unable to push database changes after $max_retries retries."
exit 1
fi
echo "Database push successful!"
# Start server
litellm --port 4000 --num_workers 8