# 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"]