| # βββ SmartClass API Server βββββββββββββββββββββββββββββββββββββββββββ | |
| FROM python:3.11-slim AS base | |
| LABEL maintainer="SmartClass Team" | |
| LABEL description="SmartClass API Server - FastAPI" | |
| # System dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libpq-dev \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create non-root user | |
| RUN useradd -m -s /bin/bash smartclass | |
| WORKDIR /opt/smartclass-api | |
| # Install Python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application code | |
| COPY app/ ./app/ | |
| COPY alembic/ ./alembic/ | |
| COPY alembic.ini . | |
| # Create necessary directories | |
| RUN mkdir -p /opt/smartclass-api/logs \ | |
| && chown -R smartclass:smartclass /opt/smartclass-api | |
| ENV PYTHONUNBUFFERED=1 | |
| # Switch to non-root user | |
| USER smartclass | |
| # Expose API port | |
| EXPOSE 8000 | |
| # Health check | |
| HEALTHCHECK --interval=15s --timeout=5s --retries=3 --start-period=30s \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health')" | |
| # Start with uvicorn | |
| CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"] | |