Navyssh commited on
Commit
eb84b8e
·
verified ·
1 Parent(s): 29f4cdf

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -14
Dockerfile CHANGED
@@ -1,6 +1,8 @@
 
1
  FROM python:3.13-slim
2
 
3
- # --- System deps required by Playwright browsers ---
 
4
  RUN apt-get update && apt-get install -y \
5
  wget gnupg ca-certificates curl unzip \
6
  libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libxkbcommon0 \
@@ -8,26 +10,38 @@ RUN apt-get update && apt-get install -y \
8
  libxfixes3 libpango-1.0-0 libcairo2 \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # --- Install Playwright + Chromium ---
12
- RUN pip install playwright && playwright install --with-deps chromium
13
 
14
- # --- Install uv package manager ---
15
- RUN pip install uv
16
 
17
- # --- Copy app to container ---
18
- WORKDIR /app
 
 
 
19
 
 
 
 
 
20
  COPY . .
21
 
 
 
 
 
 
 
 
 
22
  ENV PYTHONUNBUFFERED=1
23
  ENV PYTHONIOENCODING=utf-8
 
24
 
25
- # --- Install project dependencies using uv ---
26
- RUN uv sync --frozen
27
-
28
- # HuggingFace Spaces exposes port 7860
29
  EXPOSE 7860
30
 
31
- # --- Run your FastAPI app ---
32
- # uvicorn must be in pyproject dependencies
33
- CMD ["uv", "run", "main.py"]
 
1
+ # Use Python 3.13
2
  FROM python:3.13-slim
3
 
4
+ # 1. Install system dependencies required for Playwright
5
+ # We group these to reduce image layers and size
6
  RUN apt-get update && apt-get install -y \
7
  wget gnupg ca-certificates curl unzip \
8
  libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libxkbcommon0 \
 
10
  libxfixes3 libpango-1.0-0 libcairo2 \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # 2. Set working directory
14
+ WORKDIR /app
15
 
16
+ # 3. Install uv and Playwright
17
+ RUN pip install uv playwright
18
 
19
+ # 4. Install Playwright Browsers (Chromium only to save space)
20
+ RUN playwright install --with-deps chromium
21
+
22
+ # 5. Copy requirements file first (for caching)
23
+ COPY requirements.txt .
24
 
25
+ # 6. Install dependencies using uv's pip interface (Much faster and reliable here)
26
+ RUN uv pip install --system -r requirements.txt
27
+
28
+ # 7. Copy the rest of your application code
29
  COPY . .
30
 
31
+ # 8. Create a non-root user (Required for security on HF Spaces)
32
+ RUN useradd -m -u 1000 user
33
+ # Give the user permission to write to the app folder (for downloads/temp files)
34
+ RUN chown -R user:user /app
35
+ # Switch to non-root user
36
+ USER user
37
+
38
+ # 9. Set Environment Variables
39
  ENV PYTHONUNBUFFERED=1
40
  ENV PYTHONIOENCODING=utf-8
41
+ ENV PATH="/home/user/.local/bin:$PATH"
42
 
43
+ # 10. Expose the port
 
 
 
44
  EXPOSE 7860
45
 
46
+ # 11. Run the app using standard python command
47
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]