GitHub Actions commited on
Commit
1ff9d81
·
1 Parent(s): 1e1788c

deploy: sync from GitHub be48f2dc47ff6f6f61f967468e5a725162b4a648

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -32
Dockerfile CHANGED
@@ -1,14 +1,24 @@
1
- # CPU image - use Dockerfile.gpu for GPU support
2
- FROM python:3.12.13-slim-trixie
3
- # Cache bust: 2026-03-19
 
 
4
 
5
- # run updates before switching over to non-root user
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
 
 
7
  libglib2.0-0 \
8
  && rm -rf /var/lib/apt/lists/*
9
 
 
 
 
 
10
  # add new user with ID 1000 to avoid permission issues on HF spaces
11
- RUN useradd -m -u 1000 user
 
12
  USER user
13
 
14
  # Set home to user's home dir and add local bin to PATH
@@ -21,24 +31,16 @@ ENV HOME=/home/user \
21
  # Set the working directory in the container
22
  WORKDIR $HOME/app
23
 
24
- # Try and run pip command after setting the user with `USER user` to avoid permission issues with Python
25
- # NOTE - this is from the HF Spaces docs, not sure if necessary
26
  COPY --chown=user ./requirements.txt .
27
- RUN pip install --no-cache-dir torch==2.7.1 torchvision --index-url https://download.pytorch.org/whl/cpu
28
- RUN pip install --no-cache-dir --only-binary :all: -r requirements.txt
29
  # Force headless opencv after ultralytics (which pulls in full opencv-python as a dependency)
30
- RUN pip install --no-cache-dir --force-reinstall opencv-python-headless==4.13.0.92
31
 
32
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
33
  COPY --chown=user . $HOME/app
34
 
35
- # Install any needed packages specified in requirements.txt
36
- # --no-cache-dir: Disables the cache to reduce image size.
37
- # -r requirements.txt: Specifies the file containing the list of packages to install.
38
- # RUN pip install --no-cache-dir -r requirements.txt
39
-
40
  # Create the necessary dirs
41
- # we should not need to chown, since we are using USER user above
42
  RUN mkdir -p uploads results annotated .yolo_config
43
 
44
  # Point YOLO config to /tmp so it is writable under Apptainer (read-only SIF)
@@ -46,20 +48,6 @@ RUN mkdir -p uploads results annotated .yolo_config
46
  # as a fallback when the container filesystem is writable (plain Docker).
47
  ENV YOLO_CONFIG_DIR=/tmp/nemaquant/.yolo_config
48
 
49
- # Copy the rest of the application code into the container at /app
50
- # This includes app.py, nemaquant.py, templates/, static/, etc.
51
- # COPY . .
52
-
53
- # Make port 7860 available to the world outside this container
54
- # This is the port Flask will run on (as configured in app.py)
55
- # Hugging Face Spaces typically uses this port
56
  EXPOSE 7860
57
 
58
- # Define environment variables (optional, can be useful)
59
- # ENV NAME=World
60
-
61
- # Run app.py when the container launches
62
- # Use gunicorn for production deployment if preferred over Flask's development server
63
- # CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
64
- # For simplicity during development and typical HF Spaces use:
65
- CMD ["python", "/home/user/app/app.py"]
 
1
+ # GPU image following HF Spaces guidelines: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # Use: docker build -f Dockerfile.gpu -t cristaniguti/nemaquant:gpu .
3
+ # Requires nvidia-container-toolkit on the host (provided by HF Spaces GPU instances).
4
+ # PyTorch CUDA wheels bundle their own cuDNN/CUDA libs, so base variant is sufficient.
5
+ FROM nvidia/cuda:12.8.1-base-ubuntu24.04
6
 
7
+ # Install Python 3.12 and pip
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ python3.12 \
10
+ python3.12-venv \
11
+ python3-pip \
12
  libglib2.0-0 \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
+ # Make python3.12 the default python
16
+ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 \
17
+ && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
18
+
19
  # add new user with ID 1000 to avoid permission issues on HF spaces
20
+ # Rename the existing UID 1000 user ('ubuntu') to 'user' for HF Spaces compatibility
21
+ RUN usermod -l user ubuntu && usermod -d /home/user -m user
22
  USER user
23
 
24
  # Set home to user's home dir and add local bin to PATH
 
31
  # Set the working directory in the container
32
  WORKDIR $HOME/app
33
 
 
 
34
  COPY --chown=user ./requirements.txt .
35
+ RUN pip install --no-cache-dir --break-system-packages torch==2.7.1 torchvision --index-url https://download.pytorch.org/whl/cu128
36
+ RUN pip install --no-cache-dir --break-system-packages --only-binary :all: -r requirements.txt
37
  # Force headless opencv after ultralytics (which pulls in full opencv-python as a dependency)
38
+ RUN pip install --no-cache-dir --break-system-packages --force-reinstall opencv-python-headless==4.13.0.92
39
 
40
+ # Copy the current directory contents into the container
41
  COPY --chown=user . $HOME/app
42
 
 
 
 
 
 
43
  # Create the necessary dirs
 
44
  RUN mkdir -p uploads results annotated .yolo_config
45
 
46
  # Point YOLO config to /tmp so it is writable under Apptainer (read-only SIF)
 
48
  # as a fallback when the container filesystem is writable (plain Docker).
49
  ENV YOLO_CONFIG_DIR=/tmp/nemaquant/.yolo_config
50
 
 
 
 
 
 
 
 
51
  EXPOSE 7860
52
 
53
+ CMD ["python", "/home/user/app/app.py"]