FROM python:3.11-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    postgresql-client \
    curl \
    xvfb \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Playwright + Chromium for Booking.com scraper
RUN playwright install chromium --with-deps

COPY . .

EXPOSE 8000

# Run under a virtual X display so Chromium launches headful (headful fingerprints
# far cleaner than headless — real GPU strings, plugins, chrome.runtime).
# Start Xvfb directly rather than via xvfb-run: as container PID 1, xvfb-run's
# SIGUSR1 readiness handshake never fires and it hangs without exec'ing the app.
ENV DISPLAY=:99
CMD ["/bin/sh", "-c", "Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp & sleep 1; exec uvicorn main:app --host 0.0.0.0 --port 8000"]
