imseldrith commited on
Commit
87f0e66
·
verified ·
1 Parent(s): 3d24b7c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -14
Dockerfile CHANGED
@@ -1,16 +1,12 @@
1
- # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
-
4
  FROM python:3.9
5
 
6
- RUN useradd -m -u 1000 user
7
- USER user
8
- ENV PATH="/home/user/.local/bin:$PATH"
9
 
10
- WORKDIR /app
11
  # Install system dependencies required by OpenCV and other libraries
12
- # libgl1-mesa-glx and libglib2.0-0 are common for OpenCV headless
13
- # Added more libraries to ensure libGL.so.1 and other dependencies are present
14
  RUN apt-get update && \
15
  apt-get install -y --no-install-recommends \
16
  libgl1-mesa-glx \
@@ -21,16 +17,37 @@ RUN apt-get update && \
21
  libsm6 \
22
  libxext6 \
23
  libxrender-dev \
24
- # ffmpeg is useful for video processing if cv2 needs it for certain codecs,
25
- # though cv2 often comes with its own ffmpeg bindings.
26
  # Add it if you encounter video format issues.
27
  # ffmpeg \
28
  && \
29
  apt-get clean && \
30
  rm -rf /var/lib/apt/lists/*
31
 
32
- COPY --chown=user ./requirements.txt requirements.txt
33
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- COPY --chown=user . /app
 
36
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use an official Python runtime as a parent image
 
 
2
  FROM python:3.9
3
 
4
+ # Set environment variables that don't depend on the user
5
+ ENV PYTHONUNBUFFERED 1
6
+ ENV PIP_NO_CACHE_DIR=1
7
 
 
8
  # Install system dependencies required by OpenCV and other libraries
9
+ # These commands need to run as root
 
10
  RUN apt-get update && \
11
  apt-get install -y --no-install-recommends \
12
  libgl1-mesa-glx \
 
17
  libsm6 \
18
  libxext6 \
19
  libxrender-dev \
20
+ # ffmpeg is useful for video processing if cv2 needs it for certain codecs.
 
21
  # Add it if you encounter video format issues.
22
  # ffmpeg \
23
  && \
24
  apt-get clean && \
25
  rm -rf /var/lib/apt/lists/*
26
 
27
+ # Now, create and switch to the non-root user
28
+ RUN useradd -m -u 1000 user
29
+ USER user
30
+ ENV PATH="/home/user/.local/bin:$PATH" # Set PATH for the non-root user
31
+
32
+ # Set the working directory in the container (as the non-root user)
33
+ WORKDIR /app
34
+
35
+ # Copy the requirements file into the container at /app
36
+ # Ensure the user owns this file after copying
37
+ COPY --chown=user:user ./requirements.txt requirements.txt
38
+
39
+ # Install any needed packages specified in requirements.txt
40
+ # This will run as the non-root user, installing packages into the user's site-packages
41
+ RUN pip install --no-cache-dir --upgrade pip && \
42
+ pip install --no-cache-dir -r requirements.txt
43
+
44
+ # Copy the rest of the application code into the container at /app
45
+ # Ensure the user owns these files
46
+ COPY --chown=user:user . /app
47
+
48
+ # Expose port (Hugging Face Spaces typically use 7860 for web apps)
49
+ EXPOSE 7860
50
 
51
+ # Command to run the application using uvicorn
52
+ # It will listen on all available network interfaces (0.0.0.0)
53
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]