atharvawarade9807 commited on
Commit
ea8f716
·
verified ·
1 Parent(s): 69c3c08

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -20
Dockerfile CHANGED
@@ -1,60 +1,54 @@
1
  # =====================================================================
2
- # 1. STABLE LINUX BASE ENGINE
3
  # =====================================================================
4
  FROM python:3.10-slim
5
 
6
- # Force Python logs to stream in real-time and prevent bytecode junk
7
  ENV PYTHONDONTWRITEBYTECODE=1
8
  ENV PYTHONUNBUFFERED=1
9
-
10
- # 🔥 THE FIX: Anchor paths inside the isolated user-writable directory
11
  ENV HOME=/home/user
12
  ENV PYTHONPATH=/home/user/app
 
13
  ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/app/.cache/ms-playwright
14
 
15
- # Create Hugging Face's exact mandatory non-root user profile
16
  RUN useradd -m -u 1000 user
17
  WORKDIR /home/user/app
18
 
19
  # =====================================================================
20
- # 2. SYSTEM DEPENDENCIES (Executed safely as Root)
21
  # =====================================================================
 
 
22
  RUN apt-get update && apt-get install -y --no-install-recommends \
23
  curl \
24
  git \
 
 
25
  && rm -rf /var/lib/apt/lists/*
26
 
27
  # =====================================================================
28
- # 3. DEPENDENCY & BROWSER PROVISIONING
29
  # =====================================================================
30
- # Copy requirements files safely under user ownership layers
31
  COPY --chown=user:user Server/requirements.txt* ./Server/
32
  COPY --chown=user:user requirements.txt* ./
33
 
34
- # Upgrade pip and execute installation based on file location
35
  RUN pip install --no-cache-dir --upgrade pip && \
36
  if [ -f "Server/requirements.txt" ]; then pip install --no-cache-dir -r Server/requirements.txt; \
37
  else pip install --no-cache-dir -r requirements.txt; fi
38
 
39
- # Install Playwright and force its system libraries to bind inside /home/user
40
- RUN pip install --no-cache-dir playwright && \
41
- playwright install --with-deps chromium
42
-
43
  # =====================================================================
44
- # 4. CODE INGESTION & RUNTIME PRIVILEGES
45
  # =====================================================================
46
- # Pull down your codebase (preserves Engine structures and Server folders)
47
  COPY --chown=user:user . .
48
 
49
- # Global safety switch to guarantee user 1000 owns absolutely everything
50
  RUN chown -R user:user /home/user
51
 
52
- # Drop root permissions permanently before launching the server
53
  USER user
54
  EXPOSE 7860
55
 
56
  # =====================================================================
57
- # 5. ADAPTIVE BOOT SYSTEM
58
  # =====================================================================
59
- # Smart routing command: Autodetects whether main.py is inside /Server or at root
60
- CMD ["sh", "-c", "if [ -f 'Server/main.py' ]; then uvicorn Server.main:app --host 0.0.0.0 --port 7860; else uvicorn main:app --host 0.0.0.0 --port 7860; fi"]
 
1
  # =====================================================================
2
+ # 1. CORE OPERATING SYSTEM ENGINE
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
+ # Forces Playwright to store browser engines in the accessible user workspace
11
  ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/app/.cache/ms-playwright
12
 
13
+ # Configure Hugging Face standard non-root user context
14
  RUN useradd -m -u 1000 user
15
  WORKDIR /home/user/app
16
 
17
  # =====================================================================
18
+ # 2. SYSTEM DEPENDENCIES & PLAYWRIGHT SUB-SYSTEMS (Root Clearance)
19
  # =====================================================================
20
+ # 🔥 THE FIX: apt-get update must run right alongside playwright install
21
+ # so the Linux package manager can find the required browser libraries.
22
  RUN apt-get update && apt-get install -y --no-install-recommends \
23
  curl \
24
  git \
25
+ && pip install --no-cache-dir playwright \
26
+ && playwright install --with-deps chromium \
27
  && rm -rf /var/lib/apt/lists/*
28
 
29
  # =====================================================================
30
+ # 3. PYTHON PACKAGES PIPELINE
31
  # =====================================================================
 
32
  COPY --chown=user:user Server/requirements.txt* ./Server/
33
  COPY --chown=user:user requirements.txt* ./
34
 
 
35
  RUN pip install --no-cache-dir --upgrade pip && \
36
  if [ -f "Server/requirements.txt" ]; then pip install --no-cache-dir -r Server/requirements.txt; \
37
  else pip install --no-cache-dir -r requirements.txt; fi
38
 
 
 
 
 
39
  # =====================================================================
40
+ # 4. CODE DEPLOYMENT & PERMISSION ALIGNMENT
41
  # =====================================================================
 
42
  COPY --chown=user:user . .
43
 
44
+ # Grant full permission control to the execution user profile
45
  RUN chown -R user:user /home/user
46
 
47
+ # Securely drop down to Hugging Face sandbox privileges
48
  USER user
49
  EXPOSE 7860
50
 
51
  # =====================================================================
52
+ # 5. CONTAINER BOOT GATEWAY
53
  # =====================================================================
54
+ CMD ["uvicorn", "Server.main:app", "--host", "0.0.0.0", "--port", "7860"]