Kokoro-FastAPI/docker/cpu/Dockerfile

61 lines
1.6 KiB
Text
Raw Normal View History

2025-01-23 14:39:06 -07:00
FROM --platform=$BUILDPLATFORM python:3.10-slim
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
espeak-ng \
git \
libsndfile1 \
curl \
2025-01-17 21:43:10 -07:00
ffmpeg \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install UV using the installer script
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
mv /root/.local/bin/uv /usr/local/bin/ && \
mv /root/.local/bin/uvx /usr/local/bin/
# Create non-root user
RUN useradd -m -u 1000 appuser
# Create directories and set ownership
RUN mkdir -p /app/api/src/models/v1_0 && \
chown -R appuser:appuser /app
USER appuser
WORKDIR /app
# Copy dependency files
COPY --chown=appuser:appuser pyproject.toml ./pyproject.toml
# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
uv venv && \
uv sync --extra cpu --no-install-project
# Copy project files including models
COPY --chown=appuser:appuser api ./api
COPY --chown=appuser:appuser web ./web
2025-01-28 13:52:57 -07:00
COPY --chown=appuser:appuser docker/scripts/download_model.* ./
# Install project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --extra cpu
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONPATH=/app:/app/api \
PATH="/app/.venv/bin:$PATH" \
UV_LINK_MODE=copy \
USE_GPU=false
# Core settings that differ from config.py defaults
ENV DOWNLOAD_MODEL=true
# Download model if enabled
RUN if [ "$DOWNLOAD_MODEL" = "true" ]; then \
python download_model.py --output api/src/models/v1_0; \
2025-01-28 13:52:57 -07:00
fi
# Run FastAPI server
CMD ["uv", "run", "python", "-m", "uvicorn", "api.src.main:app", "--host", "0.0.0.0", "--port", "8880", "--log-level", "debug"]