Eng-Musa commited on
Commit
e5dbb4b
·
1 Parent(s): 88fd288

dockerfile modification"

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -14
Dockerfile CHANGED
@@ -1,27 +1,34 @@
1
- # 1. Use even smaller base image
2
- FROM python:3.11-slim AS base
3
 
4
- # 2. Set working directory
 
 
 
 
 
5
  WORKDIR /app
6
 
7
- # 3. Install only essential system dependencies
8
- # --no-install-recommends avoids extra packages
 
9
  RUN apt-get update && \
10
  apt-get install -y --no-install-recommends gcc libpq-dev && \
11
  rm -rf /var/lib/apt/lists/*
 
12
 
13
- # 4. Copy requirements first for caching
14
- COPY requirements.txt .
15
 
16
- # 5. Upgrade pip & install Python deps with no cache
17
  RUN python -m pip install --upgrade pip \
18
  && pip install --no-cache-dir -r requirements.txt
19
 
20
- # 6. Copy app code
21
- COPY . .
22
 
23
- # 7. Expose default FastAPI port (Uvicorn)
24
- EXPOSE 8000
25
 
26
- # 8. Run Uvicorn directly (better than python main.py)
27
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
 
1
+ # 1. Use Hugging Face recommended Python image
2
+ FROM python:3.9
3
 
4
+ # 2. Create non-root user (required by Hugging Face Spaces)
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
+ ENV PATH="/home/user/.local/bin:$PATH"
8
+
9
+ # 3. Set working directory
10
  WORKDIR /app
11
 
12
+ # 4. Install essential system dependencies
13
+ # - switched to root temporarily
14
+ USER root
15
  RUN apt-get update && \
16
  apt-get install -y --no-install-recommends gcc libpq-dev && \
17
  rm -rf /var/lib/apt/lists/*
18
+ USER user
19
 
20
+ # 5. Copy requirements first for caching
21
+ COPY --chown=user requirements.txt .
22
 
23
+ # 6. Upgrade pip & install Python dependencies
24
  RUN python -m pip install --upgrade pip \
25
  && pip install --no-cache-dir -r requirements.txt
26
 
27
+ # 7. Copy the rest of the app code
28
+ COPY --chown=user . .
29
 
30
+ # 8. Expose Hugging Face default port
31
+ EXPOSE 7860
32
 
33
+ # 9. Run Uvicorn server for FastAPI app
34
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]