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.

feat: add docker and nginx support (#388)

Aditya Kaushika1a0b3bcb0f6
diff --git a/examples/email-assistant/Dockerfile b/examples/email-assistant/Dockerfile
new file mode 100644
index 00000000..8b87727f
--- /dev/null
+++ b/examples/email-assistant/Dockerfile
@@ -0,0 +1,26 @@
+# Dockerfile for Email Assistant
+# This container sets up a Python environment for running the Email Assistant server
+# along with the Burr UI. It exposes ports 7241 and 7242 for the UI and API respectively.
+
+FROM python:3.11-bookworm
+
+# Set the working directory in the container
+WORKDIR /app
+
+# Install any needed packages specified in requirements.txt
+# Assuming you have a requirements.txt file with all the necessary dependencies
+COPY requirements.txt /app/
+RUN pip install -r requirements.txt
+
+# Copy the current directory contents into the container at /app
+COPY server.py /app
+COPY wrapper.sh /app
+
+# Make port 7241 and 7242 available to the world outside this container
+EXPOSE 7241 7242
+
+# Make the wrapper script executable
+RUN chmod +x wrapper.sh
+
+# Run wrapper.sh when the container launches
+CMD ["./wrapper.sh"]
diff --git a/examples/email-assistant/README.md b/examples/email-assistant/README.md
index 0a961fca..723b5804 100644
--- a/examples/email-assistant/README.md
+++ b/examples/email-assistant/README.md
@@ -32,3 +32,30 @@ Note we will be adding two things to this demo:
Open the notebook <a target="_blank" href="https://colab.research.google.com/github/dagworks-inc/burr/blob/main/examples/email-assistant/notebook.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
</a>
+
+## Running the UI with Email Server Backend in a Docker Container
+
+We have added Docker support along with a compose file and nginx as a proxy for the API and Burr UI. To run the email assistant app with these new features:
+
+1. Run the following command:
+ ```
+ docker compose up --build
+ ```
+
+2. This will start the email assistant app along with nginx, which allows you to access:
+ - BURR UI on `telemetry.localhost`
+ - API on `api.localhost`
+
+3. If you prefer not to use subdomains powered by nginx, you can also access:
+ - Email server running Burr: Navigate to `localhost:7242/docs`
+ - Burr UI: Navigate to `localhost:7241`
+
+4. If you don't have a UI, go to demos and play with the email-assistant. Otherwise, connect to the Burr email server with your UI code.
+
+Note: This setup does not mount a persistent volume, so state is lost once the container goes down.
+
+## Additional Information
+
+We will be adding two things to this demo:
+1. An integration with the Burr web app
+2. A standalone server example with a walkthrough
diff --git a/examples/email-assistant/docker-compose.yaml b/examples/email-assistant/docker-compose.yaml
new file mode 100644
index 00000000..129672d1
--- /dev/null
+++ b/examples/email-assistant/docker-compose.yaml
@@ -0,0 +1,25 @@
+version: '3.8'
+
+services:
+ app:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ ports:
+ - "7241:7241"
+ - "7242:7242"
+ environment:
+ - OPENAI_API_KEY=${OPENAI_API_KEY}
+
+ nginx:
+ image: nginx:alpine
+ ports:
+ - "80:80"
+ volumes:
+ - ./nginx.conf:/etc/nginx/nginx.conf:ro
+ depends_on:
+ - app
+
+networks:
+ default:
+ name: fastapi-burr-network
diff --git a/examples/email-assistant/nginx.conf b/examples/email-assistant/nginx.conf
new file mode 100644
index 00000000..d59511ff
--- /dev/null
+++ b/examples/email-assistant/nginx.conf
@@ -0,0 +1,31 @@
+events {
+ worker_connections 1024;
+}
+
+http {
+ server {
+ listen 80;
+ server_name telemetry.localhost;
+
+ location / {
+ proxy_pass http://app:7241;
+ 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;
+ }
+ }
+
+ server {
+ listen 80;
+ server_name api.localhost;
+
+ location / {
+ proxy_pass http://app:7242;
+ 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/email-assistant/server.py b/examples/email-assistant/server.py
index e68fecd1..2f2cc739 100644
--- a/examples/email-assistant/server.py
+++ b/examples/email-assistant/server.py
@@ -85,7 +85,7 @@ def _get_application(project_id: str, app_id: str) -> Application:
return builder.build()
-def _run_through(project_id: str, app_id: [str], inputs: Dict[str, Any]) -> EmailAssistantState:
+def _run_through(project_id: str, app_id: str, inputs: Dict[str, Any]) -> EmailAssistantState:
"""This advances the state machine, moving through to the next 'halting' point"""
if app_id == "create_new": # quick hack to allow for null
app_id = None
@@ -187,9 +187,15 @@ def validate_environment() -> Optional[str]:
)
+app.include_router(router, prefix="/email_assistant", tags=["email-assistant-api"])
+
+
+def root():
+ return {"message": "Email Assistant API"}
+
+
if __name__ == "__main__":
import uvicorn
- app.include_router(router, prefix="/")
-
uvicorn.run(app, host="localhost", port=7242)
diff --git a/examples/email-assistant/wrapper.sh b/examples/email-assistant/wrapper.sh
new file mode 100644
index 00000000..6c47bf4d
--- /dev/null
+++ b/examples/email-assistant/wrapper.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# Start the Burr UI
+burr --host 0.0.0.0 &
+
+# Start the FastAPI server using uvicorn
+uvicorn server:app --host 0.0.0.0 --port 7242