42Cummer commited on
Commit
0878044
·
verified ·
1 Parent(s): 4a8615d

try forum suggestion

Browse files
Files changed (2) hide show
  1. Dockerfile +14 -6
  2. app.py +2 -2
Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
  FROM python:3.10
2
 
3
- # Install basic dependencies and Chrome runtime libraries
4
  RUN apt-get update && apt-get install -y \
5
  wget \
6
  gnupg \
@@ -11,13 +11,21 @@ RUN apt-get update && apt-get install -y \
11
 
12
  WORKDIR /app
13
 
14
- COPY requirements.txt requirements.txt
 
 
15
  RUN pip install -r requirements.txt
16
 
17
- # Install Playwright browsers and system dependencies
18
- ENV PLAYWRIGHT_BROWSERS_PATH=/tmp/playwright-browsers
19
- RUN playwright install-deps
20
- RUN playwright install chromium
 
 
 
 
 
 
21
 
22
  # Verify the installation and show the exact path
23
  RUN playwright --version && ls -la /tmp/playwright-browsers/ && find /tmp/playwright-browsers/ -name "chrome" -type f
 
1
  FROM python:3.10
2
 
3
+ # Install basic dependencies
4
  RUN apt-get update && apt-get install -y \
5
  wget \
6
  gnupg \
 
11
 
12
  WORKDIR /app
13
 
14
+ # Upgrade pip and install requirements
15
+ RUN pip install --upgrade pip
16
+ COPY requirements.txt .
17
  RUN pip install -r requirements.txt
18
 
19
+ # Install Playwright and download the required browsers
20
+ RUN playwright install --with-deps
21
+
22
+ # Create and switch to a non-root user
23
+ RUN useradd -m -u 1000 user
24
+ USER user
25
+ ENV PATH="/home/user/.local/bin:$PATH"
26
+
27
+ # Ensure Playwright browsers are installed for the non-root user
28
+ RUN playwright install
29
 
30
  # Verify the installation and show the exact path
31
  RUN playwright --version && ls -la /tmp/playwright-browsers/ && find /tmp/playwright-browsers/ -name "chrome" -type f
app.py CHANGED
@@ -254,8 +254,8 @@ def seek():
254
  }
255
  # Use Playwright to handle redirects and wait for page to load
256
  with sync_playwright() as p:
257
- # Use the known working Chrome executable path
258
- executable_path = "/tmp/playwright-browsers/chromium-1181/chrome-linux/chrome"
259
  print(f"Using Chrome executable: {executable_path}")
260
 
261
  browser = p.chromium.launch(
 
254
  }
255
  # Use Playwright to handle redirects and wait for page to load
256
  with sync_playwright() as p:
257
+ # Use the known working Chrome executable path (for non-root user)
258
+ executable_path = "/home/user/.cache/ms-playwright/chromium-*/chrome-linux/chrome"
259
  print(f"Using Chrome executable: {executable_path}")
260
 
261
  browser = p.chromium.launch(