apexherbert200 commited on
Commit
9b0dc4d
·
1 Parent(s): 4abb273

Switch to python:3.11-slim base image for better compatibility

Browse files

- Replace zenika/alpine-chrome with standard Python image
- Install all required system dependencies for Playwright
- Install Playwright browsers during build
- Create non-root user for security
- Should resolve all import and compatibility issues

Files changed (1) hide show
  1. Dockerfile +36 -15
Dockerfile CHANGED
@@ -1,30 +1,51 @@
1
- FROM zenika/alpine-chrome:with-playwright
2
-
3
- # Switch to root user to install packages
4
- USER root
5
 
6
  WORKDIR /app
7
 
8
- # Install Python and pip
9
- RUN apk add --no-cache python3 py3-pip
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Copy requirements first for better caching
12
  COPY requirements.txt .
13
- RUN python3 -m pip install --no-cache-dir --break-system-packages -r requirements.txt
14
 
15
- # Set environment variable to use existing browsers
16
- ENV PLAYWRIGHT_BROWSERS_PATH=/usr/bin
17
 
18
  # Copy your code
19
  COPY . .
20
 
21
- # Switch back to chrome user for security
22
- USER chrome
23
-
24
- # FastAPI and Uvicorn are already installed via requirements.txt
25
- # Playwright browsers are already available in the base image
26
 
27
  EXPOSE 7860
28
 
29
  # Run the FastAPI application
30
- CMD ["python3", "-m", "uvicorn", "scrape:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ FROM python:3.11-slim
 
 
 
2
 
3
  WORKDIR /app
4
 
5
+ # Install system dependencies for Playwright
6
+ RUN apt-get update && apt-get install -y \
7
+ wget \
8
+ gnupg \
9
+ ca-certificates \
10
+ fonts-liberation \
11
+ libasound2 \
12
+ libatk-bridge2.0-0 \
13
+ libatk1.0-0 \
14
+ libatspi2.0-0 \
15
+ libcups2 \
16
+ libdbus-1-3 \
17
+ libdrm2 \
18
+ libgtk-3-0 \
19
+ libnspr4 \
20
+ libnss3 \
21
+ libwayland-client0 \
22
+ libx11-6 \
23
+ libx11-xcb1 \
24
+ libxcb1 \
25
+ libxcomposite1 \
26
+ libxdamage1 \
27
+ libxext6 \
28
+ libxfixes3 \
29
+ libxrandr2 \
30
+ libxss1 \
31
+ libxtst6 \
32
+ && rm -rf /var/lib/apt/lists/*
33
 
34
  # Copy requirements first for better caching
35
  COPY requirements.txt .
36
+ RUN pip install --no-cache-dir -r requirements.txt
37
 
38
+ # Install Playwright browsers
39
+ RUN python -m playwright install chromium
40
 
41
  # Copy your code
42
  COPY . .
43
 
44
+ # Create a non-root user for security
45
+ RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
46
+ USER appuser
 
 
47
 
48
  EXPOSE 7860
49
 
50
  # Run the FastAPI application
51
+ CMD ["python", "-m", "uvicorn", "scrape:app", "--host", "0.0.0.0", "--port", "7860"]