FROM python:3.11-slim # Set environment variables ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONPATH=/app ENV NODE_ENV=production ENV APP_ENV=production # Set work directory WORKDIR /app # Install system dependencies RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \ build-essential \ libpq-dev \ postgresql-client \ curl \ ffmpeg \ && rm -rf /var/lib/apt/lists/* # Copy requirements and install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Optional: Install NLP requirements if needed # COPY requirements-nlp.txt . # RUN pip install --no-cache-dir -r requirements-nlp.txt # Copy application code COPY . . # Copy and make migration script executable COPY scripts/migrate.sh /usr/local/bin/migrate.sh RUN chmod +x /usr/local/bin/migrate.sh # Create non-root user for security RUN useradd --create-home --shell /bin/bash app && \ chown -R app:app /app USER app # Create logs directory RUN mkdir -p logs # Expose port EXPOSE 8000 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8000/health || exit 1 # Run the application in production mode CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]