File size: 1,424 Bytes
0eec92d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Dockerfile for Hugging Face Spaces
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create directories for ChromaDB and HuggingFace cache with proper permissions
RUN mkdir -p /app/chroma_db && \
    mkdir -p /app/.cache/huggingface && \
    chmod -R 777 /app/chroma_db && \
    chmod -R 777 /app/.cache

# Expose port (HF Spaces uses 7860 by default)
EXPOSE 7860

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV CHROMA_PERSIST_DIR=/app/chroma_db
ENV HF_HOME=/app/.cache/huggingface
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
ENV HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface
# ChromaDB/SQLite specific settings to prevent readonly errors
ENV SQLITE_TMPDIR=/app/chroma_db
ENV TMPDIR=/tmp

# Create startup script to handle permissions
RUN echo '#!/bin/bash\n\
umask 000\n\
# Ensure directories exist and are writable\n\
mkdir -p /tmp/chroma_db /app/.cache/huggingface\n\
# Start the server\n\
exec uvicorn api.server:app --host 0.0.0.0 --port 7860' > /app/start.sh && \
    chmod +x /app/start.sh

# Run the startup script
CMD ["/app/start.sh"]