Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +11 -4
Dockerfile
CHANGED
|
@@ -7,21 +7,26 @@ ENV PYTHONUNBUFFERED=1 \
|
|
| 7 |
HF_HOME="/tmp/huggingface_cache" \
|
| 8 |
HUGGINGFACE_HUB_CACHE="/tmp/huggingface_cache"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
# Set working directory
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
# Copy requirements file
|
| 14 |
COPY requirements.txt .
|
| 15 |
|
| 16 |
-
# Install dependencies
|
| 17 |
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
RUN python -m venv /app/venv && \
|
| 20 |
/app/venv/bin/pip install --no-cache-dir --upgrade pip && \
|
| 21 |
/app/venv/bin/pip install --no-cache-dir -r requirements.txt
|
| 22 |
|
| 23 |
-
# Ensure the Hugging Face cache directory exists
|
| 24 |
-
RUN mkdir -p $HF_HOME &&
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Copy application files
|
| 27 |
COPY main.py .
|
|
@@ -30,7 +35,9 @@ COPY main.py .
|
|
| 30 |
ARG HF_TOKEN
|
| 31 |
ENV HF_TOKEN=${HF_TOKEN}
|
| 32 |
|
| 33 |
-
# Pre-download models
|
|
|
|
|
|
|
| 34 |
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
| 35 |
pipeline('sentiment-analysis', model='Ehrii/sentiment', use_auth_token='$HF_TOKEN')" || echo 'Failed to download multilingual model'
|
| 36 |
|
|
|
|
| 7 |
HF_HOME="/tmp/huggingface_cache" \
|
| 8 |
HUGGINGFACE_HUB_CACHE="/tmp/huggingface_cache"
|
| 9 |
|
| 10 |
+
# Create a non-root user
|
| 11 |
+
RUN useradd --create-home --shell /bin/bash appuser
|
| 12 |
+
|
| 13 |
# Set working directory
|
| 14 |
WORKDIR /app
|
| 15 |
|
| 16 |
# Copy requirements file
|
| 17 |
COPY requirements.txt .
|
| 18 |
|
| 19 |
+
# Install dependencies and create virtual environment
|
| 20 |
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
| 21 |
|
| 22 |
RUN python -m venv /app/venv && \
|
| 23 |
/app/venv/bin/pip install --no-cache-dir --upgrade pip && \
|
| 24 |
/app/venv/bin/pip install --no-cache-dir -r requirements.txt
|
| 25 |
|
| 26 |
+
# Ensure the Hugging Face cache directory exists and assign proper permissions
|
| 27 |
+
RUN mkdir -p $HF_HOME && \
|
| 28 |
+
chown -R appuser:appuser $HF_HOME && \
|
| 29 |
+
chmod -R 777 $HF_HOME
|
| 30 |
|
| 31 |
# Copy application files
|
| 32 |
COPY main.py .
|
|
|
|
| 35 |
ARG HF_TOKEN
|
| 36 |
ENV HF_TOKEN=${HF_TOKEN}
|
| 37 |
|
| 38 |
+
# Pre-download models as the new user
|
| 39 |
+
USER appuser
|
| 40 |
+
|
| 41 |
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
| 42 |
pipeline('sentiment-analysis', model='Ehrii/sentiment', use_auth_token='$HF_TOKEN')" || echo 'Failed to download multilingual model'
|
| 43 |
|