FROM python:3.11-slim

WORKDIR /app

# Install Chromium and dependencies for Selenium (works on both ARM64 and AMD64)
RUN apt-get update && apt-get install -y \
    chromium \
    chromium-driver \
    && rm -rf /var/lib/apt/lists/*

# Set environment variable for Chromium
ENV CHROME_BIN=/usr/bin/chromium
ENV CHROMEDRIVER_PATH=/usr/bin/chromedriver

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

# Copy crawler files
COPY *.py /app/
COPY *.sh /app/

# Make start script executable
RUN chmod +x /app/start.sh

# Expose port for API
EXPOSE 5002

# Run both API and worker
CMD ["/app/start.sh"]
