File size: 1,022 Bytes
9635c7e
005eafc
9635c7e
005eafc
9635c7e
 
 
4f5f5ef
9635c7e
005eafc
40b7380
 
 
 
e2770d0
 
40b7380
 
e2770d0
40b7380
 
 
 
e2770d0
 
40b7380
005eafc
e2770d0
40b7380
9635c7e
 
40b7380
 
 
 
005eafc
9635c7e
 
005eafc
40b7380
e2770d0
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
FROM python:3.9-slim

WORKDIR /code

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

# Create a non-root user
RUN useradd -m -u 1000 user && \
    chown -R user:user /code

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV TORCH_HOME=/tmp/torch_cache

# Create cache directories with proper permissions
RUN mkdir -p /tmp/transformers_cache /tmp/torch_cache && \
    chown -R user:user /tmp/transformers_cache /tmp/torch_cache && \
    chmod 777 /tmp/transformers_cache /tmp/torch_cache

# Copy requirements first
COPY --chown=user:user requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY --chown=user:user . .

# Switch to non-root user
USER user

# Expose the port
EXPOSE 7860

# Run with single worker
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]