Skip to content

Commit

Permalink
WIP for deployment with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahbenizzy committed Aug 3, 2024
1 parent cef3454 commit 5487491
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 9 deletions.
27 changes: 27 additions & 0 deletions burr/log_setup.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions burr/tracking/server/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
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)
Expand Down
2 changes: 2 additions & 0 deletions burr/tracking/server/s3/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ async def load_snapshot(self):
# 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
Expand Down
40 changes: 40 additions & 0 deletions burr/tracking/server/s3/deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;'"]
17 changes: 17 additions & 0 deletions burr/tracking/server/s3/deployment/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
7 changes: 1 addition & 6 deletions examples/streaming-fastapi/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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",
Expand Down Expand Up @@ -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()
)
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 5487491

Please sign in to comment.