news-whisper-api / Dockerfile
Devang1290
fix: pre-install spacy en_core_web_sm model at build time (root site-packages)
d50eed9
# Use a lightweight python image
FROM python:3.11-slim
# Install required system packages (as root)
RUN apt-get update && apt-get install -y \
ffmpeg \
espeak-ng \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install uv for blazing-fast pip installs
RUN pip install uv
# Copy requirements first for Docker layer caching
COPY requirements-ci-english.txt requirements-ci-hindi.txt ./
# ROOT CAUSE FIX: Install ALL dependencies in a SINGLE command
# so uv can resolve the full dependency graph at once.
#
# Previously, 3 separate `uv pip install` commands each resolved
# independently. The kokoro→misaki→spacy→typer→click chain needs
# click>=8.2.0 for Choice[T] generics, but a later install step
# was downgrading click, causing TypeError at import time.
#
# In GitHub Actions CI this works because everything is installed
# in one `uv pip install -r requirements.txt` call.
RUN uv pip install --system --no-cache \
fastapi uvicorn pydantic \
-r requirements-ci-english.txt \
-r requirements-ci-hindi.txt
# Pre-install the spacy model into system site-packages (as root).
# At runtime the app runs as non-root 'user', so pip downloads
# the model into user site-packages which spacy can't find.
RUN python -m spacy download en_core_web_sm
# Now create non-root user (HF Spaces requirement)
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
# Set working directory and copy project
WORKDIR /app
COPY --chown=user:user . /app
# Hugging Face Spaces routes traffic to port 7860
EXPOSE 7860
# Run the FastAPI app
CMD ["uvicorn", "hf_app:app", "--host", "0.0.0.0", "--port", "7860"]