Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +41 -28
Dockerfile
CHANGED
@@ -1,47 +1,60 @@
|
|
1 |
# Use official Python slim image
|
2 |
FROM python:3.9-slim
|
3 |
|
|
|
4 |
WORKDIR /app
|
5 |
|
6 |
-
#
|
7 |
RUN apt-get update && apt-get install -y \
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# Redirect Selenium
|
21 |
ENV XDG_CACHE_HOME=/tmp/.cache
|
22 |
-
RUN mkdir -p /tmp/.cache/selenium /tmp/chrome-user-data
|
23 |
-
|
24 |
-
# Tell webdriver‑manager to cache under /tmp/.wdm instead of /.wdm
|
25 |
ENV WDM_LOCAL=/tmp/.wdm
|
26 |
-
RUN mkdir -p /tmp/.wdm
|
27 |
-
|
28 |
|
29 |
-
#
|
30 |
COPY requirements.txt .
|
31 |
RUN pip install --no-cache-dir -r requirements.txt
|
32 |
|
33 |
-
#
|
34 |
COPY . .
|
35 |
|
36 |
-
#
|
37 |
RUN wget -q -O /tmp/chrome.deb \
|
38 |
https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
EXPOSE 7860
|
45 |
|
46 |
-
#
|
47 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
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 \
|
12 |
+
curl \
|
13 |
+
libgtk-3-0 \
|
14 |
+
libdbus-glib-1-2 \
|
15 |
+
libx11-xcb1 \
|
16 |
+
libxtst6 \
|
17 |
+
libxrandr2 \
|
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"]
|