| FROM python:3.11-slim | |
| # Install build dependencies with optimizations for smaller image | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| cmake \ | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && apt-get clean | |
| WORKDIR /code | |
| # Copy and install requirements with optimizations | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy application code | |
| COPY . . | |
| # Create model directory and set permissions | |
| RUN mkdir -p /code/model && \ | |
| chmod -R 777 /code && \ | |
| find /code -type f -name "*.py" -exec chmod +x {} \; | |
| # Optimize Python performance | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONOPTIMIZE=1 | |
| EXPOSE 7860 | |
| # Use optimized uvicorn settings for free tier | |
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--loop", "asyncio", "--access-log"] | |