Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker and nginx support #388

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add docker and nginx support
api.localhost will direct to api on port 7242 and telemetry.localhost will open the Burr UI
  • Loading branch information
97k committed Oct 11, 2024
commit 54a77358465740284c0c70a4148efb431218e47a
23 changes: 23 additions & 0 deletions examples/email-assistant/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use an official Python runtime as a parent image
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"]
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;
}
}
}
9 changes: 6 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 @@ -186,10 +186,13 @@ def validate_environment() -> Optional[str]:
"You can still look at chat history/examples."
)

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