Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +25 -3
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# Use an official PyTorch image as a base
|
| 2 |
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
|
| 3 |
|
| 4 |
# Set the working directory inside the container
|
|
@@ -9,6 +9,21 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
build-essential \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Install Python dependencies
|
| 13 |
RUN pip install --no-cache-dir \
|
| 14 |
pandas \
|
|
@@ -21,17 +36,24 @@ RUN pip install --no-cache-dir \
|
|
| 21 |
uvicorn[standard] \
|
| 22 |
pydantic \
|
| 23 |
python-multipart \
|
| 24 |
-
huggingface_hub
|
|
|
|
| 25 |
|
| 26 |
# Copy the necessary files into the container
|
| 27 |
COPY plant_data_chunks_and_embeddings.csv /app/plant_data_chunks_and_embeddings.csv
|
| 28 |
COPY main.py /app/main.py
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Set the environment variable to point to the app directory
|
| 31 |
ENV PYTHONPATH=/app
|
| 32 |
|
| 33 |
# Expose the port the app will run on
|
| 34 |
EXPOSE 5000
|
| 35 |
|
| 36 |
-
# Command to run the app using Uvicorn
|
| 37 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]
|
|
|
|
| 1 |
+
# Use an official PyTorch image as a base
|
| 2 |
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
|
| 3 |
|
| 4 |
# Set the working directory inside the container
|
|
|
|
| 9 |
build-essential \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# Create a non-root user
|
| 13 |
+
RUN useradd -m -u 1000 appuser
|
| 14 |
+
|
| 15 |
+
# Create cache directories and set permissions
|
| 16 |
+
RUN mkdir -p /.cache/huggingface && \
|
| 17 |
+
mkdir -p /.cache/torch && \
|
| 18 |
+
mkdir -p /.cache/sentence_transformers && \
|
| 19 |
+
chown -R appuser:appuser /.cache && \
|
| 20 |
+
chmod -R 777 /.cache
|
| 21 |
+
|
| 22 |
+
# Set environment variables for cache locations
|
| 23 |
+
ENV HF_HOME="/.cache/huggingface"
|
| 24 |
+
ENV TORCH_HOME="/.cache/torch"
|
| 25 |
+
ENV SENTENCE_TRANSFORMERS_HOME="/.cache/sentence_transformers"
|
| 26 |
+
|
| 27 |
# Install Python dependencies
|
| 28 |
RUN pip install --no-cache-dir \
|
| 29 |
pandas \
|
|
|
|
| 36 |
uvicorn[standard] \
|
| 37 |
pydantic \
|
| 38 |
python-multipart \
|
| 39 |
+
huggingface_hub \
|
| 40 |
+
accelerate>=0.26.0
|
| 41 |
|
| 42 |
# Copy the necessary files into the container
|
| 43 |
COPY plant_data_chunks_and_embeddings.csv /app/plant_data_chunks_and_embeddings.csv
|
| 44 |
COPY main.py /app/main.py
|
| 45 |
|
| 46 |
+
# Set proper permissions for the app directory
|
| 47 |
+
RUN chown -R appuser:appuser /app
|
| 48 |
+
|
| 49 |
+
# Switch to non-root user
|
| 50 |
+
USER appuser
|
| 51 |
+
|
| 52 |
# Set the environment variable to point to the app directory
|
| 53 |
ENV PYTHONPATH=/app
|
| 54 |
|
| 55 |
# Expose the port the app will run on
|
| 56 |
EXPOSE 5000
|
| 57 |
|
| 58 |
+
# Command to run the app using Uvicorn
|
| 59 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]
|