Spaces:
Sleeping
Sleeping
DariusGiannoli commited on
Commit ·
82625e4
1
Parent(s): 73cad76
fix: use CPU torch index, non-root user, libgomp1 for HF Spaces
Browse files- Dockerfile +25 -13
Dockerfile
CHANGED
|
@@ -1,26 +1,38 @@
|
|
| 1 |
# 1. Use an official Python base image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
# 2. Install system dependencies
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
libgl1-mesa-glx \
|
| 7 |
libglib2.0-0 \
|
| 8 |
-
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
# 3.
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# 4.
|
| 15 |
-
|
| 16 |
-
RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
| 17 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
|
| 19 |
-
# 5. Copy
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# 6.
|
|
|
|
|
|
|
|
|
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
|
|
|
| 1 |
# 1. Use an official Python base image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# 2. Install system dependencies
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
libgl1-mesa-glx \
|
| 7 |
libglib2.0-0 \
|
| 8 |
+
libgomp1 \
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
+
# 3. Create non-root user required by Hugging Face Spaces
|
| 12 |
+
RUN useradd -m -u 1000 user
|
| 13 |
+
USER user
|
| 14 |
+
ENV HOME=/home/user \
|
| 15 |
+
PATH=/home/user/.local/bin:$PATH
|
| 16 |
|
| 17 |
+
# 4. Set working directory
|
| 18 |
+
WORKDIR $HOME/app
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# 5. Copy and install requirements — install everything in one pass so the
|
| 21 |
+
# dependency resolver won't re-pull a CUDA torch when ultralytics is installed.
|
| 22 |
+
# --index-url sets PyTorch CPU wheel index as primary;
|
| 23 |
+
# --extra-index-url adds PyPI for all other packages.
|
| 24 |
+
COPY --chown=user requirements.txt .
|
| 25 |
+
RUN pip install --no-cache-dir \
|
| 26 |
+
--index-url https://download.pytorch.org/whl/cpu \
|
| 27 |
+
--extra-index-url https://pypi.org/simple/ \
|
| 28 |
+
torch torchvision \
|
| 29 |
+
-r requirements.txt
|
| 30 |
|
| 31 |
+
# 6. Copy the rest of the project
|
| 32 |
+
COPY --chown=user . .
|
| 33 |
+
|
| 34 |
+
# 7. Expose Streamlit port
|
| 35 |
EXPOSE 7860
|
| 36 |
|
| 37 |
+
# 8. Run the app
|
| 38 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|