# ── Stage 1: Builder ──────────────────────────────────────────── FROM python:3.11-slim AS builder WORKDIR /build # Install build dependencies RUN apt-get update && \ apt-get install -y --no-install-recommends gcc g++ && \ rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip install --no-cache-dir --prefix=/install -r requirements.txt # ── Stage 2: Runtime ──────────────────────────────────────────── FROM python:3.11-slim LABEL maintainer="LinkGuard Team " LABEL description="Phishing URL Detector — FastAPI inference server" WORKDIR /app # Copy installed packages from builder COPY --from=builder /install /usr/local # Copy application code COPY . . # Create required directories RUN mkdir -p models/saved outputs data/raw # Non-root user for security RUN useradd --create-home --shell /bin/bash appuser && \ chown -R appuser:appuser /app USER appuser # Expose the API port EXPOSE 8000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1 # Start the server CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]