blackboxai-api / Dockerfile
teletubbies's picture
Scale runtime for 20-user target load
decd9fb
Raw
History Blame Contribute Delete
1.45 kB
# Use the official Python 3.11 image directly, since pydantic-core works well on 3.11
FROM python:3.11-slim
# Build argument for port configuration (default: 7860 for HF Spaces)
ARG PORT=7860
# Set working directory
WORKDIR /app
# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
ENV PORT=${PORT}
ENV WEB_CONCURRENCY=2
# Install system dependencies (needed for compiling some python packages if wheels aren't available)
# Also include curl for health checks
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
default-libmysqlclient-dev \
pkg-config \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the entire backend application into the container
COPY . /app
# Create directories for logs and temporary files
RUN mkdir -p /app/logs /app/tmp && chmod 755 /app/logs /app/tmp
# Expose the API port (default 7860 for HuggingFace Spaces)
EXPOSE ${PORT}
# Health check: Verify the API is responding
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:${PORT}/docs || exit 1
# Start Uvicorn
# Using the PORT environment variable allows flexibility in port configuration
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT} --workers ${WEB_CONCURRENCY}"]