File size: 2,799 Bytes
6b02257
 
ce5833a
6b02257
 
 
ce5833a
75d729f
ce5833a
 
 
 
 
75d729f
 
 
 
 
 
 
 
 
 
 
 
6b02257
 
75d729f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48ee87c
6b02257
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"]