James Frecheville commited on
Commit
85dc94a
·
1 Parent(s): 5cf7c58

Move browser installation to build phase and remove runtime installation

Browse files
Files changed (2) hide show
  1. Dockerfile +8 -2
  2. app.py +0 -11
Dockerfile CHANGED
@@ -53,6 +53,12 @@ RUN useradd -m -u 1000 user && \
53
  COPY requirements.txt .
54
  RUN pip install --no-cache-dir -r requirements.txt
55
 
 
 
 
 
 
 
56
  # Copy the rest of the application
57
  COPY . .
58
  RUN chown -R user:user /app
@@ -72,5 +78,5 @@ USER user
72
  # Expose the port
73
  EXPOSE 7860
74
 
75
- # Run the application with Xvfb and install browsers
76
- CMD Xvfb :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & playwright install chromium && python app.py
 
53
  COPY requirements.txt .
54
  RUN pip install --no-cache-dir -r requirements.txt
55
 
56
+ # Install Playwright browsers as root
57
+ RUN mkdir -p /home/user/.cache/ms-playwright && \
58
+ playwright install chromium && \
59
+ playwright install-deps && \
60
+ chown -R user:user /home/user/.cache/ms-playwright
61
+
62
  # Copy the rest of the application
63
  COPY . .
64
  RUN chown -R user:user /app
 
78
  # Expose the port
79
  EXPOSE 7860
80
 
81
+ # Run the application with Xvfb
82
+ CMD Xvfb :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & python app.py
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import sys
3
- import subprocess
4
  from pathlib import Path
5
 
6
  # Add the current directory to Python path
@@ -11,16 +10,6 @@ if str(current_dir) not in sys.path:
11
  # Set environment variables for Playwright
12
  os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/home/user/.cache/ms-playwright"
13
 
14
- # Ensure browser is installed
15
- try:
16
- from playwright.sync_api import sync_playwright
17
- with sync_playwright() as p:
18
- p.chromium.launch()
19
- except Exception as e:
20
- print(f"Browser installation error: {e}")
21
- print("Attempting to install browser...")
22
- subprocess.run(["playwright", "install", "chromium"], check=True)
23
-
24
  from owl.webapp import create_ui
25
  import gradio as gr
26
 
 
1
  import os
2
  import sys
 
3
  from pathlib import Path
4
 
5
  # Add the current directory to Python path
 
10
  # Set environment variables for Playwright
11
  os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/home/user/.cache/ms-playwright"
12
 
 
 
 
 
 
 
 
 
 
 
13
  from owl.webapp import create_ui
14
  import gradio as gr
15