Skip to content

SOTA Open Source TTS

perf: Optimizing docker builds (#547)

吴小白e413df7145bf
diff --git a/.dockerignore b/.dockerignore
index efcfce8..e464d50 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,3 +1,5 @@
+.git
+.github
results
data
*.filelist
diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml
new file mode 100644
index 0000000..27e05a6
--- /dev/null
+++ b/.github/workflows/build-dev.yml
@@ -0,0 +1,56 @@
+name: Build Image
+
+on:
+ push:
+ branches:
+ - main
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: docker/setup-qemu-action@v3
+ - uses: docker/setup-buildx-action@v3
+ - name: Get Version
+ run: |
+ version=dev
+ full_version=${version}-$(date "+%Y%m%d")
+ echo "version=${version}" >> $GITHUB_ENV
+ echo "full_version=${full_version}" >> $GITHUB_ENV
+
+ - name: Login to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.repository_owner }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Build and Push Image
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ file: Dockerfile
+ platforms: linux/amd64,linux/arm64
+ push: true
+ tags: |
+ ghcr.io/${{ github.repository_owner }}/fish-speech:${{ env.version }}
+ outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+
+ - name: Build and Push Debug Image
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ file: Dockerfile-debug
+ platforms: linux/amd64,linux/arm64
+ push: true
+ build-args: |
+ VERSION=${{ env.version }}
+ tags: |
+ ghcr.io/${{ github.repository_owner }}/fish-speech:${{ env.version }}-debug
+ ghcr.io/${{ github.repository_owner }}/fish-speech:${{ env.full_version }}
+ outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
diff --git a/.github/workflows/build-linux-image.yml b/.github/workflows/build-linux-image.yml
new file mode 100644
index 0000000..122241d
--- /dev/null
+++ b/.github/workflows/build-linux-image.yml
@@ -0,0 +1,53 @@
+name: Build Image
+
+on:
+ push:
+ tags:
+ - 'v*'
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: docker/setup-qemu-action@v3
+ - uses: docker/setup-buildx-action@v3
+ - name: Get Version
+ run: |
+ echo "version=$(basename ${GITHUB_REF})" >> $GITHUB_ENV
+
+ - name: Login to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.repository_owner }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Build and Push Image
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ file: Dockerfile
+ platforms: linux/amd64,linux/arm64
+ push: true
+ tags: |
+ ghcr.io/${{ github.repository_owner }}/fish-speech:${{ env.version }}
+ ghcr.io/${{ github.repository_owner }}/fish-speech:latest
+ outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+
+ - name: Build and Push Debug Image
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ file: Dockerfile-debug
+ platforms: linux/amd64,linux/arm64
+ push: true
+ build-args: |
+ VERSION=${{ env.version }}
+ tags: |
+ ghcr.io/${{ github.repository_owner }}/fish-speech:${{ env.version }}-debug
+ outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
diff --git a/Dockerfile-debug b/Dockerfile-debug
new file mode 100644
index 0000000..61035c6
--- /dev/null
+++ b/Dockerfile-debug
@@ -0,0 +1,32 @@
+ARG VERSION
+
+FROM ghcr.io/fishaudio/fish-speech:${VERSION}
+
+ARG TOOLS=" \
+ git \
+ curl \
+ build-essential \
+ ffmpeg \
+ libsm6 \
+ libxext6 \
+ libjpeg-dev \
+ zlib1g-dev \
+ aria2 \
+ zsh \
+ openssh-server \
+ sudo \
+ protobuf-compiler \
+ cmake"
+
+RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
+ --mount=type=cache,target=/var/lib/apt,sharing=locked \
+ set -ex \
+ && apt-get update \
+ && apt-get -y install --no-install-recommends ${TOOLS}
+
+# Install oh-my-zsh so your terminal looks nice
+RUN sh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" "" --unattended
+
+# Set zsh as default shell
+RUN chsh -s /usr/bin/zsh
+ENV SHELL=/usr/bin/zsh
diff --git a/dockerfile b/dockerfile
index 8e15351..9154179 100644
--- a/dockerfile
+++ b/dockerfile
@@ -1,24 +1,43 @@
-FROM python:3.10-slim-bookworm
+FROM python:3.12-slim-bookworm AS stage-1
+ARG TARGETARCH
-# Install system dependencies
-ENV DEBIAN_FRONTEND=noninteractive
-RUN apt-get update && apt-get install -y git curl build-essential ffmpeg libsm6 libxext6 libjpeg-dev \
- zlib1g-dev aria2 zsh openssh-server sudo protobuf-compiler cmake libsox-dev && \
- apt-get clean && rm -rf /var/lib/apt/lists/*
+ARG HUGGINGFACE_MODEL=fish-speech-1.4
+ARG HF_ENDPOINT=https://huggingface.co
-# Install oh-my-zsh so your terminal looks nice
-RUN sh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" "" --unattended
+WORKDIR /opt/fish-speech
-# Set zsh as default shell
-RUN chsh -s /usr/bin/zsh
-ENV SHELL=/usr/bin/zsh
+RUN set -ex \
+ && pip install huggingface_hub \
+ && HF_ENDPOINT=${HF_ENDPOINT} huggingface-cli download --resume-download fishaudio/${HUGGINGFACE_MODEL} --local-dir checkpoints/${HUGGINGFACE_MODEL}
-# Setup torchaudio
-RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
+FROM python:3.12-slim-bookworm
+ARG TARGETARCH
+
+ARG DEPENDENCIES=" \
+ ca-certificates \
+ libsox-dev"
+
+RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
+ --mount=type=cache,target=/var/lib/apt,sharing=locked \
+ set -ex \
+ && rm -f /etc/apt/apt.conf.d/docker-clean \
+ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache \
+ && apt-get update \
+ && apt-get -y install --no-install-recommends ${DEPENDENCIES} \
+ && echo "no" | dpkg-reconfigure dash
+
+WORKDIR /opt/fish-speech
-# Project Env
-WORKDIR /exp
COPY . .
-RUN pip3 install -e .
-CMD /bin/zsh
+RUN --mount=type=cache,target=/root/.cache,sharing=locked \
+ set -ex \
+ && pip install -e .[stable]
+
+COPY --from=stage-1 /opt/fish-speech/checkpoints /opt/fish-speech/checkpoints
+
+ENV GRADIO_SERVER_NAME="0.0.0.0"
+
+EXPOSE 7860
+
+CMD ["./entrypoint.sh"]
diff --git a/entrypoint.sh b/entrypoint.sh
new file mode 100755
index 0000000..d9e9314
--- /dev/null
+++ b/entrypoint.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+CUDA_ENABLED=${CUDA_ENABLED:-true}
+DEVICE=""
+
+if [ "${CUDA_ENABLED}" != "true" ]; then
+ DEVICE="--device cpu"
+fi
+
+exec python tools/webui.py ${DEVICE}