Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,830 Bytes
a869c07 04bcd5a 0e36f33 a869c07 0e36f33 142becd 0e36f33 142becd a869c07 04bcd5a 142becd a869c07 04bcd5a 142becd 0e36f33 142becd 0e36f33 5952d16 0e36f33 142becd 0e36f33 142becd 0e36f33 55b8190 0e36f33 142becd 3fa64bd f47cbd4 142becd 3fa64bd f47cbd4 142becd 0e36f33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
FROM python:3.13.4-slim
# Set environment variables for Hugging Face and app
ENV HF_HOME=/app/.cache/huggingface \
TRANSFORMERS_CACHE=/app/.cache/transformers \
HF_DATASETS_CACHE=/app/.cache/datasets \
HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface \
PYTHONUNBUFFERED=1 \
HOME=/app \
TMPDIR=/tmp \
USER=appuser \
UID=1000 \
GID=1000
# Set working directory
WORKDIR /app
# Install basic OS packages
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user with proper permissions
RUN groupadd -g $GID $USER && \
useradd -u $UID -g $GID -d /app -s /bin/bash $USER
# Create all necessary directories with proper permissions
RUN mkdir -p /app/.cache/huggingface/hub \
&& mkdir -p /app/.cache/huggingface/transformers \
&& mkdir -p /app/.cache/transformers \
&& mkdir -p /app/.cache/datasets \
&& mkdir -p /app/.streamlit \
&& mkdir -p /tmp/huggingface \
&& mkdir -p /tmp/transformers \
&& mkdir -p /tmp/datasets \
&& mkdir -p /app/models
# Set comprehensive permissions
RUN chmod -R 777 /app/.cache \
&& chmod -R 777 /tmp \
&& chmod -R 755 /app \
&& chown -R $USER:$USER /app \
&& chown -R $USER:$USER /tmp/huggingface \
&& chown -R $USER:$USER /tmp/transformers \
&& chown -R $USER:$USER /tmp/datasets
# Copy files and set ownership
COPY --chown=$USER:$USER requirements.txt ./
COPY --chown=$USER:$USER src/ ./src/
# Fix permissions for the qdrant database folder
RUN if [ -d "/app/src/qdrant_data_tesla" ]; then \
chmod -R 777 /app/src/qdrant_data_tesla && \
chown -R $USER:$USER /app/src/qdrant_data_tesla; \
fi
# Switch to non-root user for package installation
USER $USER
# Install Python dependencies
RUN pip install --no-cache-dir --user -r requirements.txt
# Ensure pip user installation directory is in PATH
ENV PATH="/app/.local/bin:$PATH"
# Create a script to handle model downloads with proper error handling
RUN echo '#!/bin/bash\n\
# Clean up any existing lock files\n\
find /app/.cache/huggingface -name "*.lock" -type f -delete 2>/dev/null || true\n\
find /tmp/huggingface -name "*.lock" -type f -delete 2>/dev/null || true\n\
\n\
# Set additional permissions at runtime\n\
chmod -R 777 /app/.cache 2>/dev/null || true\n\
chmod -R 777 /tmp 2>/dev/null || true\n\
\n\
# Start the application\n\
exec streamlit run src/streamlit_app.py --server.enableXsrfProtection=false --server.port=8501 --server.address=0.0.0.0\n\
' > /app/start.sh && chmod +x /app/start.sh
# Expose Streamlit's default port
EXPOSE 8501
# Healthcheck for container status
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
# Use the startup script instead of direct entrypoint
ENTRYPOINT ["/app/start.sh"] |