Spaces:
Runtime error
Runtime error
Fix v1.3.7: Git config permissions - use non-root user for git operations
Browse files- Dockerfile +27 -2
Dockerfile
CHANGED
|
@@ -10,15 +10,40 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
tar \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Copy requirements and install Python dependencies
|
| 14 |
COPY requirements.txt .
|
| 15 |
|
| 16 |
-
# Install
|
| 17 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
|
| 19 |
# Copy application
|
| 20 |
COPY app.py .
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Expose port
|
| 23 |
EXPOSE 7860
|
| 24 |
|
|
@@ -26,5 +51,5 @@ EXPOSE 7860
|
|
| 26 |
HEALTHCHECK --interval=30s --timeout=30s --start-period=180s --retries=3 \
|
| 27 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 28 |
|
| 29 |
-
# Run application
|
| 30 |
CMD ["python", "app.py"]
|
|
|
|
| 10 |
tar \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# Create a non-root user and set up git config for that user
|
| 14 |
+
RUN useradd -m -u 1000 appuser && \
|
| 15 |
+
mkdir -p /home/appuser && \
|
| 16 |
+
chown -R appuser:appuser /home/appuser
|
| 17 |
+
|
| 18 |
+
# Switch to non-root user for git operations
|
| 19 |
+
USER appuser
|
| 20 |
+
|
| 21 |
+
# Set git config for the non-root user (avoids permission issues)
|
| 22 |
+
RUN git config --global user.email "appuser@docker.local" && \
|
| 23 |
+
git config --global user.name "Docker App User"
|
| 24 |
+
|
| 25 |
+
# Create app directory with proper ownership
|
| 26 |
+
RUN mkdir -p /app && \
|
| 27 |
+
mkdir -p /app/hf_cache
|
| 28 |
+
|
| 29 |
+
# Switch back to root to install system packages
|
| 30 |
+
USER root
|
| 31 |
+
|
| 32 |
# Copy requirements and install Python dependencies
|
| 33 |
COPY requirements.txt .
|
| 34 |
|
| 35 |
+
# Install Python dependencies as root but make accessible to appuser
|
| 36 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 37 |
|
| 38 |
# Copy application
|
| 39 |
COPY app.py .
|
| 40 |
|
| 41 |
+
# Set ownership to appuser
|
| 42 |
+
RUN chown -R appuser:appuser /app
|
| 43 |
+
|
| 44 |
+
# Switch back to non-root user for running the app
|
| 45 |
+
USER appuser
|
| 46 |
+
|
| 47 |
# Expose port
|
| 48 |
EXPOSE 7860
|
| 49 |
|
|
|
|
| 51 |
HEALTHCHECK --interval=30s --timeout=30s --start-period=180s --retries=3 \
|
| 52 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 53 |
|
| 54 |
+
# Run application as non-root user
|
| 55 |
CMD ["python", "app.py"]
|