FROM python:3.9-slim # Install system dependencies RUN apt-get update && apt-get install -y \ wget \ gnupg \ unzip \ curl \ libx11-6 \ libnss3 \ libgconf-2-4 \ libfontconfig1 \ libxrender1 \ libx11-xcb1 \ libxcomposite1 \ libxcursor1 \ libxdamage1 \ libxi6 \ libxtst6 \ libxrandr2 \ libasound2 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libcups2 \ libpangocairo-1.0-0 \ && rm -rf /var/lib/apt/lists/* # Add Google Chrome repository RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list # Install Chrome, try specific version first, fall back to latest RUN apt-get update && \ (apt-get install -y --no-install-recommends google-chrome-stable=136.0.7103.113-1 || \ (echo "Specific Chrome version 136.0.7103.113-1 unavailable, installing latest" && \ apt-get install -y --no-install-recommends google-chrome-stable)) && \ rm -rf /var/lib/apt/lists/* \ && google-chrome --version > /tmp/chrome-version.txt 2>&1 || echo "Chrome version check failed" > /tmp/chrome-version.txt # Get Chrome version and install matching ChromeDriver RUN CHROME_VERSION=$(cat /tmp/chrome-version.txt | grep -oP '\d+\.\d+\.\d+\.\d+' || echo "unknown") && \ echo "Detected Chrome version: $CHROME_VERSION" && \ if [ "$CHROME_VERSION" != "unknown" ]; then \ wget -q -O /tmp/chromedriver.zip "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_VERSION/linux64/chromedriver-linux64.zip" || \ (echo "ChromeDriver download failed for $CHROME_VERSION, trying fallback" && \ wget -q -O /tmp/chromedriver.zip "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%.*}/chromedriver_linux64.zip") && \ unzip /tmp/chromedriver.zip -d /usr/bin/ && \ mv /usr/bin/chromedriver-linux64/chromedriver /usr/bin/chromedriver && \ chmod +x /usr/bin/chromedriver && \ rm -rf /tmp/chromedriver.zip /usr/bin/chromedriver-linux64 && \ chromedriver --version > /tmp/chromedriver-version.txt 2>&1 || echo "ChromeDriver version check failed" > /tmp/chromedriver-version.txt; \ else \ echo "Chrome not installed, skipping ChromeDriver" > /tmp/chromedriver-version.txt; \ fi # Verify installations RUN echo "Checking installed files:" && \ ls -l /usr/bin/google-chrome /usr/bin/chromedriver || echo "One or more binaries not found" && \ cat /tmp/chrome-version.txt && \ cat /tmp/chromedriver-version.txt WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY app.py . ENV PORT=7860 CMD ["python", "app.py"]