mirror of
https://github.com/remsky/Kokoro-FastAPI.git
synced 2025-08-05 16:48:53 +00:00
Smaller docker image:
CPU image 5.6Gb -> 4.9Gb GPU image 14.8Gb -> 9.9Gb Saved 4GBby using the cuda base image instead of cudnn-runtime. Saved 700MB by deleting the UV cache. Improved the speed of rebuilding the image by merging the RUN commands into one.
This commit is contained in:
parent
eac7ab4449
commit
4aad01ee36
2 changed files with 37 additions and 67 deletions
|
@ -1,26 +1,17 @@
|
||||||
FROM python:3.10-slim
|
FROM python:3.10-slim
|
||||||
|
|
||||||
# Install dependencies and check espeak location
|
# Install dependencies and check espeak location
|
||||||
RUN apt-get update && apt-get install -y \
|
# Rust is required to build sudachipy and pyopenjtalk-plus
|
||||||
espeak-ng \
|
RUN apt-get update -y && \
|
||||||
espeak-ng-data \
|
apt-get install -y espeak-ng espeak-ng-data git libsndfile1 curl ffmpeg g++ && \
|
||||||
git \
|
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
||||||
libsndfile1 \
|
mkdir -p /usr/share/espeak-ng-data && \
|
||||||
curl \
|
ln -s /usr/lib/*/espeak-ng-data/* /usr/share/espeak-ng-data/ && \
|
||||||
ffmpeg \
|
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
||||||
g++ \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
|
||||||
&& mkdir -p /usr/share/espeak-ng-data \
|
|
||||||
&& ln -s /usr/lib/*/espeak-ng-data/* /usr/share/espeak-ng-data/
|
|
||||||
|
|
||||||
# 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/uv /usr/local/bin/ && \
|
||||||
mv /root/.local/bin/uvx /usr/local/bin/
|
mv /root/.local/bin/uvx /usr/local/bin/ && \
|
||||||
|
curl https://sh.rustup.rs -sSf | sh -s -- -y && \
|
||||||
# Create non-root user and set up directories and permissions
|
useradd -m -u 1000 appuser && \
|
||||||
RUN useradd -m -u 1000 appuser && \
|
|
||||||
mkdir -p /app/api/src/models/v1_0 && \
|
mkdir -p /app/api/src/models/v1_0 && \
|
||||||
chown -R appuser:appuser /app
|
chown -R appuser:appuser /app
|
||||||
|
|
||||||
|
@ -30,14 +21,9 @@ WORKDIR /app
|
||||||
# Copy dependency files
|
# Copy dependency files
|
||||||
COPY --chown=appuser:appuser pyproject.toml ./pyproject.toml
|
COPY --chown=appuser:appuser pyproject.toml ./pyproject.toml
|
||||||
|
|
||||||
# Install Rust (required to build sudachipy and pyopenjtalk-plus)
|
# Install dependencies with CPU extras
|
||||||
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
RUN uv venv --python 3.10 && \
|
||||||
ENV PATH="/home/appuser/.cargo/bin:$PATH"
|
uv sync --extra cpu --no-cache
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
||||||
uv venv --python 3.10 && \
|
|
||||||
uv sync --extra cpu
|
|
||||||
|
|
||||||
# Copy project files including models
|
# Copy project files including models
|
||||||
COPY --chown=appuser:appuser api ./api
|
COPY --chown=appuser:appuser api ./api
|
||||||
|
@ -46,14 +32,15 @@ COPY --chown=appuser:appuser docker/scripts/ ./
|
||||||
RUN chmod +x ./entrypoint.sh
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PATH="/home/appuser/.cargo/bin:/app/.venv/bin:$PATH" \
|
||||||
|
PYTHONUNBUFFERED=1 \
|
||||||
PYTHONPATH=/app:/app/api \
|
PYTHONPATH=/app:/app/api \
|
||||||
PATH="/app/.venv/bin:$PATH" \
|
|
||||||
UV_LINK_MODE=copy \
|
UV_LINK_MODE=copy \
|
||||||
USE_GPU=false \
|
USE_GPU=false \
|
||||||
PHONEMIZER_ESPEAK_PATH=/usr/bin \
|
PHONEMIZER_ESPEAK_PATH=/usr/bin \
|
||||||
PHONEMIZER_ESPEAK_DATA=/usr/share/espeak-ng-data \
|
PHONEMIZER_ESPEAK_DATA=/usr/share/espeak-ng-data \
|
||||||
ESPEAK_DATA_PATH=/usr/share/espeak-ng-data
|
ESPEAK_DATA_PATH=/usr/share/espeak-ng-data \
|
||||||
|
DEVICE="cpu"
|
||||||
|
|
||||||
ENV DOWNLOAD_MODEL=true
|
ENV DOWNLOAD_MODEL=true
|
||||||
# Download model if enabled
|
# Download model if enabled
|
||||||
|
@ -61,6 +48,5 @@ RUN if [ "$DOWNLOAD_MODEL" = "true" ]; then \
|
||||||
python download_model.py --output api/src/models/v1_0; \
|
python download_model.py --output api/src/models/v1_0; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ENV DEVICE="cpu"
|
|
||||||
# Run FastAPI server through entrypoint.sh
|
# Run FastAPI server through entrypoint.sh
|
||||||
CMD ["./entrypoint.sh"]
|
CMD ["./entrypoint.sh"]
|
||||||
|
|
|
@ -1,29 +1,15 @@
|
||||||
FROM --platform=$BUILDPLATFORM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04
|
FROM --platform=$BUILDPLATFORM nvidia/cuda:12.8.1-base-ubuntu24.04
|
||||||
# Set non-interactive frontend
|
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
|
||||||
|
|
||||||
# Install Python and other dependencies
|
# Install Python and other dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update -y && \
|
||||||
python3.10 \
|
apt-get install -y python3.10 python3-venv espeak-ng espeak-ng-data git libsndfile1 curl ffmpeg g++ && \
|
||||||
python3-venv \
|
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
||||||
espeak-ng \
|
mkdir -p /usr/share/espeak-ng-data && \
|
||||||
espeak-ng-data \
|
ln -s /usr/lib/*/espeak-ng-data/* /usr/share/espeak-ng-data/ && \
|
||||||
git \
|
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
||||||
libsndfile1 \
|
|
||||||
curl \
|
|
||||||
ffmpeg \
|
|
||||||
g++ \
|
|
||||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
|
|
||||||
&& mkdir -p /usr/share/espeak-ng-data \
|
|
||||||
&& ln -s /usr/lib/*/espeak-ng-data/* /usr/share/espeak-ng-data/
|
|
||||||
|
|
||||||
# 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/uv /usr/local/bin/ && \
|
||||||
mv /root/.local/bin/uvx /usr/local/bin/
|
mv /root/.local/bin/uvx /usr/local/bin/ && \
|
||||||
|
useradd -m -u 1001 appuser && \
|
||||||
# Create non-root user and set up directories and permissions
|
|
||||||
RUN useradd -m -u 1001 appuser && \
|
|
||||||
mkdir -p /app/api/src/models/v1_0 && \
|
mkdir -p /app/api/src/models/v1_0 && \
|
||||||
chown -R appuser:appuser /app
|
chown -R appuser:appuser /app
|
||||||
|
|
||||||
|
@ -33,14 +19,9 @@ WORKDIR /app
|
||||||
# Copy dependency files
|
# Copy dependency files
|
||||||
COPY --chown=appuser:appuser pyproject.toml ./pyproject.toml
|
COPY --chown=appuser:appuser pyproject.toml ./pyproject.toml
|
||||||
|
|
||||||
ENV PHONEMIZER_ESPEAK_PATH=/usr/bin \
|
# Install dependencies with GPU extras
|
||||||
PHONEMIZER_ESPEAK_DATA=/usr/share/espeak-ng-data \
|
RUN uv venv --python 3.10 && \
|
||||||
ESPEAK_DATA_PATH=/usr/share/espeak-ng-data
|
uv sync --extra gpu --no-cache
|
||||||
|
|
||||||
# Install dependencies with GPU extras (using cache mounts)
|
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
||||||
uv venv --python 3.10 && \
|
|
||||||
uv sync --extra gpu
|
|
||||||
|
|
||||||
# Copy project files including models
|
# Copy project files including models
|
||||||
COPY --chown=appuser:appuser api ./api
|
COPY --chown=appuser:appuser api ./api
|
||||||
|
@ -50,11 +31,15 @@ RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
|
|
||||||
# Set all environment variables in one go
|
# Set all environment variables in one go
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PATH="/app/.venv/bin:$PATH" \
|
||||||
|
PYTHONUNBUFFERED=1 \
|
||||||
PYTHONPATH=/app:/app/api \
|
PYTHONPATH=/app:/app/api \
|
||||||
PATH="/app/.venv/bin:$PATH" \
|
|
||||||
UV_LINK_MODE=copy \
|
UV_LINK_MODE=copy \
|
||||||
USE_GPU=true
|
USE_GPU=true \
|
||||||
|
PHONEMIZER_ESPEAK_PATH=/usr/bin \
|
||||||
|
PHONEMIZER_ESPEAK_DATA=/usr/share/espeak-ng-data \
|
||||||
|
ESPEAK_DATA_PATH=/usr/share/espeak-ng-data \
|
||||||
|
DEVICE="gpu"
|
||||||
|
|
||||||
ENV DOWNLOAD_MODEL=true
|
ENV DOWNLOAD_MODEL=true
|
||||||
# Download model if enabled
|
# Download model if enabled
|
||||||
|
@ -62,6 +47,5 @@ RUN if [ "$DOWNLOAD_MODEL" = "true" ]; then \
|
||||||
python download_model.py --output api/src/models/v1_0; \
|
python download_model.py --output api/src/models/v1_0; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ENV DEVICE="gpu"
|
|
||||||
# Run FastAPI server through entrypoint.sh
|
# Run FastAPI server through entrypoint.sh
|
||||||
CMD ["./entrypoint.sh"]
|
CMD ["./entrypoint.sh"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue