Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +35 -29
Dockerfile
CHANGED
|
@@ -1,22 +1,12 @@
|
|
| 1 |
# =====================================================================
|
| 2 |
-
# 1.
|
| 3 |
# =====================================================================
|
| 4 |
FROM python:3.10-slim
|
| 5 |
|
| 6 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 7 |
ENV PYTHONUNBUFFERED=1
|
| 8 |
-
ENV HOME=/home/user
|
| 9 |
-
ENV PYTHONPATH=/home/user/app
|
| 10 |
-
# Locks Playwright browser binaries completely inside the application scope
|
| 11 |
-
ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/app/.cache/ms-playwright
|
| 12 |
-
|
| 13 |
-
# Pre-render Hugging Face user context
|
| 14 |
-
RUN useradd -m -u 1000 user
|
| 15 |
-
WORKDIR /home/user/app
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
# 2. MANUAL CHROMIUM SYSTEM DEPENDENCIES (Bypasses Playwright Sudo Script)
|
| 19 |
-
# =====================================================================
|
| 20 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 21 |
curl \
|
| 22 |
git \
|
|
@@ -36,35 +26,51 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 36 |
libpango-1.0-0 \
|
| 37 |
libcairo2 \
|
| 38 |
libasound2 \
|
|
|
|
|
|
|
| 39 |
&& rm -rf /var/lib/apt/lists/*
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# =====================================================================
|
| 42 |
-
#
|
| 43 |
# =====================================================================
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
RUN pip install --no-cache-dir
|
| 53 |
-
playwright install chromium
|
| 54 |
|
| 55 |
# =====================================================================
|
| 56 |
-
#
|
| 57 |
# =====================================================================
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
USER user
|
| 65 |
EXPOSE 7860
|
| 66 |
|
| 67 |
# =====================================================================
|
| 68 |
-
#
|
| 69 |
# =====================================================================
|
| 70 |
-
|
|
|
|
|
|
| 1 |
# =====================================================================
|
| 2 |
+
# 1. SYSTEM LAYER (Executed safely as Root)
|
| 3 |
# =====================================================================
|
| 4 |
FROM python:3.10-slim
|
| 5 |
|
| 6 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 7 |
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Install bare-metal system libraries required by Chromium
|
|
|
|
|
|
|
| 10 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 11 |
curl \
|
| 12 |
git \
|
|
|
|
| 26 |
libpango-1.0-0 \
|
| 27 |
libcairo2 \
|
| 28 |
libasound2 \
|
| 29 |
+
libxshmfence1 \
|
| 30 |
+
ca-certificates \
|
| 31 |
&& rm -rf /var/lib/apt/lists/*
|
| 32 |
|
| 33 |
+
# Create the Hugging Face user profile
|
| 34 |
+
RUN useradd -m -u 1000 user
|
| 35 |
+
|
| 36 |
+
# Create empty target directories and give ownership to the user immediately
|
| 37 |
+
RUN mkdir -p /home/user/app /home/user/venv && \
|
| 38 |
+
chown -R user:user /home/user
|
| 39 |
+
|
| 40 |
# =====================================================================
|
| 41 |
+
# 2. USER SANDBOX LAYER (Safe from Hugging Face Permission Blocks)
|
| 42 |
# =====================================================================
|
| 43 |
+
USER user
|
| 44 |
+
WORKDIR /home/user/app
|
| 45 |
|
| 46 |
+
# Instantiate and force the Virtual Environment to be the primary system path
|
| 47 |
+
RUN python -m venv /home/user/venv
|
| 48 |
+
ENV PATH="/home/user/venv/bin:$PATH"
|
| 49 |
+
ENV PYTHONPATH=/home/user/app
|
| 50 |
+
ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/venv/ms-playwright
|
| 51 |
|
| 52 |
+
# Upgrade pip inside our isolated sandbox space
|
| 53 |
+
RUN pip install --no-cache-dir --upgrade pip
|
|
|
|
| 54 |
|
| 55 |
# =====================================================================
|
| 56 |
+
# 3. DEPENDENCY & CODE INGESTION
|
| 57 |
# =====================================================================
|
| 58 |
+
# 🔥 FIXED: Copy requirements.txt directly from the repository root workspace
|
| 59 |
+
COPY --chown=user:user requirements.txt ./
|
| 60 |
|
| 61 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 62 |
+
|
| 63 |
+
# Install Playwright and the Chromium binaries entirely within user space
|
| 64 |
+
RUN pip install --no-cache-dir playwright && \
|
| 65 |
+
playwright install chromium
|
| 66 |
+
|
| 67 |
+
# Bring in the rest of your app files under native user ownership
|
| 68 |
+
COPY --chown=user:user . .
|
| 69 |
|
|
|
|
| 70 |
EXPOSE 7860
|
| 71 |
|
| 72 |
# =====================================================================
|
| 73 |
+
# 4. RUNTIME EXECUTION
|
| 74 |
# =====================================================================
|
| 75 |
+
# 🔥 FIXED: Targeted directly to main:app since main.py sits at repository root level
|
| 76 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|