# ==============================================================================
# REPUTATION REBRANDING TOOLKIT - DOCKERFILE
# Author: Pixelated Dwarf | Version: 3.0 | Date: October 2026
# License: Apache-2.0
# ==============================================================================
# See docs/docker-setup-instructions.txt for detailed setup guides
# ==============================================================================

FROM python:3.10-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# Install system dependencies for Playwright browsers
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    git \
    libnss3 \
    libnspr4 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libcups2 \
    libdrm2 \
    libdbus-1-3 \
    libxcb1 \
    libxkbcommon0 \
    libatspi2.0-0 \
    libxcomposite1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxrandr2 \
    xdg-utils \
    fonts-liberation \
    fonts-freefont-ttf \
    fonts-dejavu-core \
    && rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /app

# Copy requirements first for caching
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Install Playwright browsers (chromium, firefox, webkit)
RUN playwright install chromium firefox webkit

# Install Playwright system dependencies
RUN playwright install-deps chromium firefox webkit

# Copy application code
COPY . .

# Create necessary directories
RUN mkdir -p \
    /app/config \
    /app/generate/output/raw \
    /app/generate/output/critiqued \
    /app/generate/output/final \
    /app/content/validated \
    /app/content/archived \
    /app/deploy/manual_queue \
    /app/logs \
    /app/backups \
    /app/recon \
    /app/monitor \
    /app/generate/templates

# Set permissions
RUN chmod -R 755 /app

# Default command - keep container running for interactive use
CMD ["/bin/bash"]

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python3 -c "import sys; print('OK')" || exit 1