diff --git a/Dockerfile b/Dockerfile index bb0b2ea6a..a9a9cd3ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Dockerfile.database b/Dockerfile.database index 9eed2baf9..afd301369 100644 --- a/Dockerfile.database +++ b/Dockerfile.database @@ -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"] \ No newline at end of file +CMD ["./entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 000000000..9071a5249 --- /dev/null +++ b/entrypoint.sh @@ -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 \ No newline at end of file