AbdoIR commited on
Commit
97a7477
·
verified ·
1 Parent(s): eb3d5ed

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -10
Dockerfile CHANGED
@@ -1,19 +1,39 @@
 
1
  FROM python:3.9-slim
2
 
3
- WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/*
6
 
7
- RUN mkdir -p /app/.u2net && chmod 777 /app/.u2net
 
8
 
9
- ENV U2NET_HOME=/app/.u2net
10
- ENV NUMBA_CACHE_DIR=/tmp
11
- # ENV NUMBA_DISABLE_JIT=1
12
 
13
- COPY requirements.txt .
 
 
 
14
 
15
- RUN pip install --no-cache-dir -r requirements.txt
 
16
 
17
- COPY . .
 
18
 
19
- CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:7860", "api:app"]
 
 
 
1
+ # Use a slim Python base image
2
  FROM python:3.9-slim
3
 
4
+ # Install system build deps (adjust if you know you don't need them)
5
+ RUN apt-get update && \
6
+ apt-get install -y --no-install-recommends \
7
+ build-essential \
8
+ gcc \
9
+ libgomp1 \
10
+ git && \
11
+ rm -rf /var/lib/apt/lists/*
12
+
13
+ # Prevent Python from writing .pyc files and enable unbuffered logging
14
+ ENV PYTHONDONTWRITEBYTECODE=1 \
15
+ PYTHONUNBUFFERED=1
16
 
17
+ WORKDIR /app
18
 
19
+ # Copy only requirements first to leverage Docker cache
20
+ COPY requirements.txt /app/requirements.txt
21
 
22
+ # Install Python packages globally (as root)
23
+ RUN pip install --no-cache-dir --upgrade pip && \
24
+ pip install --no-cache-dir -r /app/requirements.txt
25
 
26
+ # Create a non-root user and switch to it
27
+ RUN useradd -m -u 1000 user
28
+ USER user
29
+ ENV PATH="/home/user/.local/bin:$PATH"
30
 
31
+ # Copy application code as the non-root user
32
+ COPY --chown=user:root . /app
33
 
34
+ # Expose the port expected by Hugging Face Spaces (7860)
35
+ EXPOSE 7860
36
 
37
+ # Run uvicorn pointing at your FastAPI app.
38
+ # Note: your FastAPI app instance is `app` in `backend.py`, so we use `backend:app`.
39
+ CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]