File size: 1,021 Bytes
2393be4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use an official Python image
FROM python:3.12-slim

# Create a non-root user with UID 1000
RUN useradd -m -u 1000 user

# Create a data/cache directory with open permissions
RUN mkdir -p /data/.cache/huggingface && \
    chown -R user:user /data && \
    chmod -R 777 /data

# Set environment variables for Hugging Face cache
ENV HF_HOME=/data/.cache/huggingface \
    TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers \
    HF_DATASETS_CACHE=/data/.cache/huggingface/datasets

# Switch to the non-root user
USER user

# Set working directory for the user
WORKDIR /home/user/app

# Ensure pip packages go to user space
ENV PATH=/home/user/.local/bin:$PATH

# Upgrade pip (runs as user)
RUN pip install --no-cache-dir --upgrade pip

# Copy code into the container, set ownership
COPY --chown=user . .

# Install dependencies (will go to ~/.local)
RUN pip install --no-cache-dir -r requirements.txt

# Expose port
EXPOSE 7860

# Run the FastAPI app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]