File size: 1,188 Bytes
60a920b
4139bf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60a920b
 
 
 
 
 
 
4139bf5
 
 
 
 
 
 
 
 
 
 
157a15c
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
# Use Python 3.11.7 slim image as base
FROM python:3.11.7-slim

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Set home to the user's home directory
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set the working directory
WORKDIR $HOME/app

# Install system dependencies required for soundfile (as root)
RUN apt-get update && apt-get install -y \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY --chown=user:user requirements.txt .

# Install Python dependencies and spaCy model as root
RUN pip install --no-cache-dir -r requirements.txt && \
    python -m spacy download en_core_web_sm && \
    # Verify the model installation
    python -c "import spacy; spacy.load('en_core_web_sm')" && \
    # Ensure proper permissions for the spaCy model directory
    chown -R user:user /usr/local/lib/python3.11/site-packages/en_core_web_sm

# Copy the application code
COPY --chown=user:user . .

# Switch to the non-root user
USER user

# Expose the port the app runs on
EXPOSE 8000

# Command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]