Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

WIP for deployment with docker

elijahbenizzybc8e5120a0d3
diff --git a/burr/log_setup.py b/burr/log_setup.py
new file mode 100644
index 00000000..85c9a11b
--- /dev/null
+++ b/burr/log_setup.py
@@ -0,0 +1,27 @@
+import logging
+import sys
+
+LOG_LEVELS = {
+ "CRITICAL": logging.CRITICAL,
+ "ERROR": logging.ERROR,
+ "WARNING": logging.WARNING,
+ "INFO": logging.INFO,
+ "DEBUG": logging.DEBUG,
+}
+
+
+# this is suboptimal but python has no public mapping of log names to levels
+
+
+def setup_logging(log_level: int = logging.INFO):
+ """Helper function to setup logging to console.
+ :param log_level: Log level to use when logging
+ """
+ root_logger = logging.getLogger("") # root logger
+ formatter = logging.Formatter("[%(levelname)s] %(asctime)s %(name)s(%(lineno)s): %(message)s")
+ stream_handler = logging.StreamHandler(sys.stdout)
+ stream_handler.setFormatter(formatter)
+ if not len(root_logger.handlers):
+ # assumes we have already been set up.
+ root_logger.addHandler(stream_handler)
+ root_logger.setLevel(log_level)
diff --git a/burr/tracking/server/run.py b/burr/tracking/server/run.py
index 3020dbf9..b289b099 100644
--- a/burr/tracking/server/run.py
+++ b/burr/tracking/server/run.py
@@ -5,10 +5,10 @@ from contextlib import asynccontextmanager
from importlib.resources import files
from typing import Sequence
-# TODO -- remove this, just for testing
-from hamilton.log_setup import setup_logging
from starlette import status
+# TODO -- remove this, just for testing
+from burr.log_setup import setup_logging
from burr.tracking.server.backend import BackendBase, IndexingBackendMixin, SnapshottingBackendMixin
setup_logging(logging.INFO)
diff --git a/burr/tracking/server/s3/backend.py b/burr/tracking/server/s3/backend.py
index 41fe847e..e393ede9 100644
--- a/burr/tracking/server/s3/backend.py
+++ b/burr/tracking/server/s3/backend.py
@@ -167,12 +167,12 @@ class SQLiteS3Backend(BackendBase, IndexingBackendMixin, SnapshottingBackendMixi
# if it already exists then return
if os.path.exists(path):
return
+ if not os.path.exists(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
async with self._session.create_client("s3") as client:
objects = await client.list_objects_v2(
Bucket=self._bucket, Prefix=self._snapshot_prefix, MaxKeys=1
)
- # nothing there
- # TODO --
if len(objects["Contents"]) == 0:
return
# get the latest snapshot -- it's organized by alphabetical order
diff --git a/burr/tracking/server/s3/deployment/Dockerfile b/burr/tracking/server/s3/deployment/Dockerfile
new file mode 100644
index 00000000..ae601dfd
--- /dev/null
+++ b/burr/tracking/server/s3/deployment/Dockerfile
@@ -0,0 +1,40 @@
+# Use an official Python runtime as a parent image
+FROM python:3.11-slim
+
+# Set environment variables
+ENV PYTHONUNBUFFERED=1
+
+# Set working directory
+WORKDIR /app
+
+# Copy the current directory contents into the container at /app
+COPY . /app
+
+# Install dependencies and git
+RUN apt-get update && apt-get install -y \
+ git \
+ nginx \
+ && apt-get clean
+
+# Install the dependencies
+# TODO -- use the right version
+#RUN pip install "git+https://github.com/dagworks-inc/burr.git@tracker-s3#egg=burr[tracking-server-s3]"
+RUN pip install "burr[tracking-server-s3]==0.26.0rc4"
+
+# Copy the nginx config file
+COPY nginx.conf /etc/nginx/nginx.conf
+
+# Expose the port FastAPI will run on and the port NGINX will listen to
+EXPOSE 8000
+EXPOSE 80
+
+ENV BURR_S3_BUCKET=burr-prod-test
+ENV BURR_load_snapshot_on_start=True
+ENV BURR_snapshot_interval_milliseconds=3_600_000
+ENV BURR_BACKEND_IMPL=s3
+ENV ENV DEBIAN_FRONTEND=noninteractive
+ENV BURR_BACKEND_IMPL=burr.tracking.server.s3.backend.SQLiteS3Backend
+
+
+# Command to run FastAPI server and NGINX
+CMD ["sh", "-c", "uvicorn burr.tracking.server.run:app --host 0.0.0.0 --port 8000 & nginx -g 'daemon off;'"]
diff --git a/burr/tracking/server/s3/deployment/nginx.conf b/burr/tracking/server/s3/deployment/nginx.conf
new file mode 100644
index 00000000..0a447a06
--- /dev/null
+++ b/burr/tracking/server/s3/deployment/nginx.conf
@@ -0,0 +1,17 @@
+events {
+ worker_connections 1024;
+}
+
+http {
+ server {
+ listen 80;
+
+ location / {
+ proxy_pass http://127.0.0.1:8000;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+ }
+}
diff --git a/examples/streaming-fastapi/application.py b/examples/streaming-fastapi/application.py
index 63a84d29..e8c4d48f 100644
--- a/examples/streaming-fastapi/application.py
+++ b/examples/streaming-fastapi/application.py
@@ -7,7 +7,6 @@ import openai
from burr.core import ApplicationBuilder, State, default, when
from burr.core.action import action, streaming_action
from burr.core.graph import GraphBuilder
-from burr.tracking.s3client import S3TrackingClient
MODES = [
"answer_question",
@@ -175,11 +174,7 @@ def application(app_id: Optional[str] = None):
.with_state(chat_history=[])
.with_graph(graph)
# .with_tracker(project="demo_chatbot_streaming")
- .with_tracker(
- tracker=S3TrackingClient(
- bucket="burr-prod-test", project="demo_chatbot_streaming", non_blocking=True
- )
- )
+ .with_tracker(project="demo_chatbot_streaming")
.with_identifiers(app_id=app_id)
.build()
)
diff --git a/pyproject.toml b/pyproject.toml
index f55e6419..2addc13e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "burr"
-version = "0.25.0"
+version = "0.26.0rc4"
dependencies = [] # yes, there are none
requires-python = ">=3.9"
authors = [
@@ -85,6 +85,16 @@ tracking-client-s3 = [
"aiobotocore"
]
+tracking-server-s3 = [
+ "aerich",
+ "aiobotocore",
+ "fastapi-utils",
+ "fastapi",
+ "tortoise-orm[accel, asyncmy]",
+ "burr[tracking-server]",
+ "typing-inspect"
+]
+
tracking-server = [
"click",
"fastapi",