Skip to content

Commit

Permalink
feat: add docker and nginx support (DAGWorks-Inc#388)
Browse files Browse the repository at this point in the history
* feat: add docker and nginx support

api.localhost will direct to api on port 7242 and telemetry.localhost will open the Burr UI

* doc: add docker support

* Fixes pre-commit

---------

Co-authored-by: Stefan Krawczyk <stefan@dagworks.io>
  • Loading branch information
97k and skrawcz authored Oct 13, 2024
1 parent 87e4064 commit a1a0b3b
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 3 deletions.
26 changes: 26 additions & 0 deletions examples/email-assistant/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions examples/email-assistant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions examples/email-assistant/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions examples/email-assistant/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
12 changes: 9 additions & 3 deletions examples/email-assistant/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,9 +187,15 @@ def validate_environment() -> Optional[str]:
)


app.include_router(router, prefix="/email_assistant", tags=["email-assistant-api"])


@app.get("/")
def root():
return {"message": "Email Assistant API"}


if __name__ == "__main__":
import uvicorn

app.include_router(router, prefix="/")

uvicorn.run(app, host="localhost", port=7242)
7 changes: 7 additions & 0 deletions examples/email-assistant/wrapper.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a1a0b3b

Please sign in to comment.