Spaces:
Sleeping
Sleeping
Joash
commited on
Commit
·
7804990
1
Parent(s):
087ce88
Update Dockerfile with proper user permissions
Browse files- Dockerfile +17 -10
Dockerfile
CHANGED
|
@@ -10,30 +10,37 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
curl \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
# Create necessary directories
|
| 14 |
-
RUN mkdir -p logs src/static
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Upgrade pip and install numpy first
|
| 17 |
-
RUN pip install --upgrade pip
|
| 18 |
-
RUN pip install --no-cache-dir "numpy<2.0.0"
|
| 19 |
|
| 20 |
# Copy requirements first to leverage Docker cache
|
| 21 |
-
COPY requirements.txt .
|
| 22 |
|
| 23 |
# Install Python dependencies
|
| 24 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
|
| 26 |
# Copy application code
|
| 27 |
-
COPY . .
|
| 28 |
-
|
| 29 |
-
# Ensure proper permissions for logs directory
|
| 30 |
-
RUN chmod 777 logs
|
| 31 |
|
| 32 |
# Set environment variables
|
| 33 |
ENV PYTHONPATH=/app
|
| 34 |
ENV PYTHONUNBUFFERED=1
|
| 35 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 36 |
ENV PORT=7860
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Expose port for Hugging Face Spaces
|
| 39 |
EXPOSE 7860
|
|
|
|
| 10 |
curl \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# Create necessary directories with proper permissions
|
| 14 |
+
RUN mkdir -p /app/logs /app/src/static /home/user/.cache/huggingface /home/user/.local \
|
| 15 |
+
&& chmod -R 777 /app/logs /home/user/.cache/huggingface /home/user/.local
|
| 16 |
+
|
| 17 |
+
# Create non-root user
|
| 18 |
+
RUN useradd -m -u 1000 user \
|
| 19 |
+
&& chown -R user:user /app /home/user/.cache /home/user/.local
|
| 20 |
+
|
| 21 |
+
# Switch to non-root user
|
| 22 |
+
USER user
|
| 23 |
|
| 24 |
# Upgrade pip and install numpy first
|
| 25 |
+
RUN pip install --user --no-cache-dir --upgrade pip
|
| 26 |
+
RUN pip install --user --no-cache-dir "numpy<2.0.0"
|
| 27 |
|
| 28 |
# Copy requirements first to leverage Docker cache
|
| 29 |
+
COPY --chown=user:user requirements.txt .
|
| 30 |
|
| 31 |
# Install Python dependencies
|
| 32 |
+
RUN pip install --user --no-cache-dir -r requirements.txt
|
| 33 |
|
| 34 |
# Copy application code
|
| 35 |
+
COPY --chown=user:user . .
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Set environment variables
|
| 38 |
ENV PYTHONPATH=/app
|
| 39 |
ENV PYTHONUNBUFFERED=1
|
| 40 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 41 |
ENV PORT=7860
|
| 42 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 43 |
+
ENV HF_HOME=/home/user/.cache/huggingface
|
| 44 |
|
| 45 |
# Expose port for Hugging Face Spaces
|
| 46 |
EXPOSE 7860
|