michelerussoAA commited on
Commit
1c936b3
·
verified ·
1 Parent(s): d6da54f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -32
Dockerfile CHANGED
@@ -1,11 +1,12 @@
1
- # Use official Python slim image
2
  FROM python:3.9-slim
3
 
4
- # 1) Set working directory
5
  WORKDIR /app
6
 
7
- # 2) Install system dependencies for Chrome + headless operation
8
- RUN apt-get update && apt-get install -y \
 
9
  wget \
10
  unzip \
11
  xvfb \
@@ -18,43 +19,29 @@ RUN apt-get update && apt-get install -y \
18
  libasound2 \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
- # 3) Redirect Selenium & webdriver-manager caches to /tmp (writable)
22
- ENV XDG_CACHE_HOME=/tmp/.cache
23
- ENV WDM_LOCAL=/tmp/.wdm
24
- RUN mkdir -p /tmp/.cache/selenium /tmp/chrome-user-data /tmp/.wdm
25
 
26
- # 4) Copy and install Python dependencies
 
 
 
27
  COPY requirements.txt .
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
30
- # 5) Copy your application code
31
  COPY . .
32
 
33
- # 6) Install Google Chrome
34
  RUN wget -q -O /tmp/chrome.deb \
35
  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
36
  && apt-get update \
37
  && apt-get install -y /tmp/chrome.deb \
38
- && rm /tmp/chrome.deb
39
-
40
- # 7) Install matching ChromeDriver for the installed Chrome
41
- RUN set -eux; \
42
- # grab first three components of Chrome version
43
- CHROME_VERSION=$(google-chrome --version | sed -E 's/.* ([0-9]+\.[0-9]+\.[0-9]+).*/\1/'); \
44
- CHROME_MAJOR=$(echo "$CHROME_VERSION" | cut -d. -f1); \
45
- echo "🔍 Detected Chrome $CHROME_VERSION (major $CHROME_MAJOR)"; \
46
- # fetch matching driver version
47
- DRIVER_VERSION=$(curl -fsSL "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR}"); \
48
- echo "⬇️ Downloading ChromeDriver $DRIVER_VERSION"; \
49
- wget -qO /tmp/chromedriver.zip \
50
- "https://chromedriver.storage.googleapis.com/${DRIVER_VERSION}/chromedriver_linux64.zip"; \
51
- unzip /tmp/chromedriver.zip -d /tmp; \
52
- mv /tmp/chromedriver /usr/local/bin/chromedriver; \
53
- chmod +x /usr/local/bin/chromedriver; \
54
- rm /tmp/chromedriver.zip
55
-
56
- # 8) Expose port for FastAPI ping
57
  EXPOSE 7860
58
 
59
- # 9) Launch the FastAPI app (which kicks off your scraper)
60
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use slim Python 3.9
2
  FROM python:3.9-slim
3
 
4
+ # work dir
5
  WORKDIR /app
6
 
7
+ # Install Chrome + GUI libs
8
+ RUN apt-get update && \
9
+ apt-get install -y \
10
  wget \
11
  unzip \
12
  xvfb \
 
19
  libasound2 \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
+ # Create Selenium‐Manager cache + Chrome user‐data folders
23
+ RUN mkdir -p /tmp/.cache/selenium /tmp/chrome-user-data
 
 
24
 
25
+ # Tell Selenium‑Manager to cache under /tmp
26
+ ENV SE_CACHE_PATH=/tmp/.cache/selenium
27
+
28
+ # Install Python deps
29
  COPY requirements.txt .
30
  RUN pip install --no-cache-dir -r requirements.txt
31
 
32
+ # Copy app code
33
  COPY . .
34
 
35
+ # Install Google Chrome Stable
36
  RUN wget -q -O /tmp/chrome.deb \
37
  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
38
  && apt-get update \
39
  && apt-get install -y /tmp/chrome.deb \
40
+ && rm /tmp/chrome.deb \
41
+ && rm -rf /var/lib/apt/lists/*
42
+
43
+ # Expose your app’s port (e.g. 7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  EXPOSE 7860
45
 
46
+ # Launch your scraper/app
47
+ CMD ["python", "scraper.py"]