File size: 1,202 Bytes
02d44c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
FROM python:3.10-slim

# Optimizations for RunPod / Production
# 1. Prevent Python from buffering stdout/stderr (ensures logs show up immediately in RunPod console)
ENV PYTHONUNBUFFERED=1
# 2. Prevent Python from writing .pyc files
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR /app

# Install system dependencies
# 'build-essential' is often needed for compiling python packages
# 'curl' is added for the Healthcheck
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Expose the API port
EXPOSE 8000

# Healthcheck (Optional but recommended for RunPod reliability)
# It pings the root endpoint to ensure the server is responsive
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://0.0.0.0:8000/ || exit 1

# Launch the FastAPI server
# 0.0.0.0 is critical for container networking
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]