mobadara commited on
Commit
bdc1936
·
1 Parent(s): e1f421c

adjusted DockerFile

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. backend/DockerFile +24 -38
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🫁
4
  colorFrom: blue
5
  colorTo: indigo
6
  sdk: docker
7
- app_port: 8000
8
  pinned: false
9
  license: apache-2.0
10
  ---
 
4
  colorFrom: blue
5
  colorTo: indigo
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  license: apache-2.0
10
  ---
backend/DockerFile CHANGED
@@ -1,52 +1,38 @@
1
- # --- Step 1: Base Build Stage ---
2
- # Use an official Python slim image for a lightweight foundation
3
- FROM python:3.11-slim as builder
 
 
 
4
 
5
- # Set build-time environment variables
 
6
  ENV PYTHONDONTWRITEBYTECODE=1
7
  ENV PYTHONUNBUFFERED=1
8
 
9
- # Set the working directory inside the container
10
  WORKDIR /app
11
 
12
- # Install minimal system-level dependencies required for building/running certain wheels
13
- # (Even with headless OpenCV, some underlying OS libraries are helpful)
 
14
  RUN apt-get update && apt-get install -y --no-install-recommends \
15
  build-essential \
16
  curl \
 
 
17
  && rm -rf /var/lib/apt/lists/*
 
18
 
19
- # Copy only the requirements file first to maximize Docker layer caching
20
- COPY requirements.txt .
21
-
22
- # Install dependencies into a local deployment wheelhouse/directory
23
- # We use --no-cache-dir to minimize final image size
24
- RUN pip install --upgrade pip && \
25
- pip install --no-cache-dir -r requirements.txt
26
-
27
- # --- Step 2: Final Runtime Stage ---
28
- FROM python:3.11-slim
29
-
30
- WORKDIR /app
31
-
32
- # Set runtime environment parameters
33
- ENV PYTHONDONTWRITEBYTECODE=1
34
- ENV PYTHONUNBUFFERED=1
35
- ENV PORT=8000
36
-
37
- # Copy installed dependencies from the builder stage
38
- COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
39
- COPY --from=builder /usr/local/bin /usr/local/bin
40
-
41
- # Copy the application source code into the execution environment
42
- COPY . .
43
 
44
- # Expose the internal port that Uvicorn will listen on
45
- EXPOSE ${PORT}
46
 
47
- # Healthcheck to verify the container is alive and responding
48
- HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
49
- CMD curl -f http://localhost:${PORT}/docs || exit 1
50
 
51
- # Launch the Uvicorn application server
52
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
1
+ # --- Base Build Stage ---
2
+ FROM python:3.11-slim
3
+
4
+ # Create a non-root user specifically for Hugging Face (User ID 1000)
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
 
8
+ # Set environment variables for the user path and standard Python vars
9
+ ENV PATH="/home/user/.local/bin:$PATH"
10
  ENV PYTHONDONTWRITEBYTECODE=1
11
  ENV PYTHONUNBUFFERED=1
12
 
13
+ # Set the working directory to the user's home app folder
14
  WORKDIR /app
15
 
16
+ # Install system dependencies (required for OpenCV headless)
17
+ # Note: We must temporarily switch to root to run apt-get, then switch back
18
+ USER root
19
  RUN apt-get update && apt-get install -y --no-install-recommends \
20
  build-essential \
21
  curl \
22
+ libgl1 \
23
+ libglib2.0-0 \
24
  && rm -rf /var/lib/apt/lists/*
25
+ USER user
26
 
27
+ # Copy requirements and install
28
+ COPY --chown=user ./requirements.txt requirements.txt
29
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ # Copy the rest of the application files
32
+ COPY --chown=user . /app
33
 
34
+ # Hugging Face explicitly requires listening on port 7860
35
+ EXPOSE 7860
 
36
 
37
+ # Launch Uvicorn on port 7860
38
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]