# Build stage FROM python:3.11-slim AS builder WORKDIR /app # Install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ && rm -rf /var/lib/apt/lists/* # Set PATH for user-installed packages in builder stage ENV PATH=/root/.local/bin:$PATH # Copy requirements first for better caching COPY requirements.txt . # Copy the local rotator_library for editable install COPY src/rotator_library ./src/rotator_library # Install dependencies RUN pip install --no-cache-dir --user -r requirements.txt # Production stage FROM python:3.11-slim WORKDIR /app # Copy installed packages from builder COPY --from=builder /root/.local /root/.local # Make sure scripts in .local are usable ENV PATH=/root/.local/bin:$PATH # Copy application code COPY src/ ./src/ # Create directories for logs and oauth credentials RUN mkdir -p logs oauth_creds # Expose the default Hugging Face port EXPOSE 7860 # Set environment variables ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONPATH=/app/src # Worker configuration for concurrent request handling # 4 workers on 2 CPUs is optimal for I/O-bound proxy work (proxying = pure network waiting) # Each async worker can handle many concurrent requests via asyncio # Override via HF Space secret: UVICORN_WORKERS=N ENV UVICORN_WORKERS=4 ENV ROTATION_MODE_GEMINI_CLI=balanced # Default command - runs proxy on HF's expected port with multiple workers CMD ["python", "src/proxy_app/main.py", "--host", "0.0.0.0", "--port", "7860"]