FROM python:3.13-slim

# Set work directory
WORKDIR /app

# Install minimal system dependencies in a single layer to reduce image size
RUN apt-get update && apt-get install -y --no-install-recommends \
    wget \
    curl \
    ca-certificates \
    unzip \
    # Minimal Playwright dependencies based on GitHub issues
    libatk1.0-0 \
    libglib2.0-0 \
    libnss3 \
    libatk-bridge2.0-0 \
    libcups2 \
    libdrm2 \
    libdbus-1-3 \
    libxkbcommon0 \
    libxcomposite1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxrandr2 \
    libgbm1 \
    libpango-1.0-0 \
    libcairo2 \
    libasound2 \
    libatspi2.0-0 \
    xvfb \
    # Additional dependencies identified as missing
    libxcursor1 \
    libgtk-3-0 \
    # libgdk-3-0 - This package doesn't exist, removing
    libpangocairo-1.0-0 \
    libcairo-gobject2 \
    libgdk-pixbuf-2.0-0 \
    # Clean up in the same layer to save space
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /var/cache/apt/archives/*

# Copy requirements
COPY requirements.txt .

# Install Python dependencies and properly install Playwright browsers
RUN pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir python-dotenv requests beautifulsoup4 xlsxwriter croniter playwright && \
    # Install Playwright browsers properly
    python -m playwright install chromium && \
    # Clean up pip cache
    rm -rf /root/.cache/pip

# Copy application files
COPY . .

# Make setup script executable
RUN chmod +x setup.sh

# Set up volume for persistent data
VOLUME ["/app/logs"]

# Simple entrypoint for running the web server
CMD ["bash", "-c", "./setup.sh && python -m http.server ${PORT:-8080}"] 