Sfoglia il codice sorgente

perf: Optimizing docker builds (#547)

Signed-off-by: 吴小白 <296015668@qq.com>
吴小白 1 anno fa
parent
commit
e413df7145
6 ha cambiato i file con 189 aggiunte e 17 eliminazioni
  1. 2 0
      .dockerignore
  2. 56 0
      .github/workflows/build-dev.yml
  3. 53 0
      .github/workflows/build-linux-image.yml
  4. 32 0
      Dockerfile-debug
  5. 36 17
      dockerfile
  6. 10 0
      entrypoint.sh

+ 2 - 0
.dockerignore

@@ -1,3 +1,5 @@
+.git
+.github
 results
 results
 data
 data
 *.filelist
 *.filelist

+ 56 - 0
.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

+ 53 - 0
.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

+ 32 - 0
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

+ 36 - 17
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 . .
 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"]

+ 10 - 0
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}