Spaces:
Sleeping
Sleeping
| FROM python:3.9-slim | |
| WORKDIR /app | |
| # Create a non-root user to run the application | |
| RUN useradd -m -u 1000 appuser | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| curl \ | |
| software-properties-common \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements first for better caching | |
| COPY requirements.txt ./ | |
| # Install Python dependencies | |
| RUN pip3 install --no-cache-dir -r requirements.txt | |
| # Copy the rest of the application | |
| COPY . . | |
| # Create and set permissions for cache directories | |
| RUN mkdir -p /app/.cache/huggingface /app/.streamlit /app/.config/matplotlib \ | |
| && chown -R appuser:appuser /app | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| TRANSFORMERS_CACHE=/app/.cache/huggingface \ | |
| MPLCONFIGDIR=/app/.config/matplotlib \ | |
| HOME=/app | |
| # Expose the Streamlit port | |
| EXPOSE 8501 | |
| # Switch to non-root user | |
| USER appuser | |
| # Add health check | |
| HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1 | |
| # Run the Streamlit application | |
| ENTRYPOINT ["streamlit", "run", "src/app.py", "--server.port=8501", "--server.address=0.0.0.0"] |