perf: Optimizing docker builds (#547)

Signed-off-by: 吴小白 <296015668@qq.com>
This commit is contained in:
吴小白 2024-09-15 09:09:51 +08:00 committed by GitHub
parent c7c8c943c9
commit e413df7145
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 189 additions and 17 deletions

View File

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

56
.github/workflows/build-dev.yml vendored Normal file
View File

@ -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
.github/workflows/build-linux-image.yml vendored Normal file
View File

@ -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
Dockerfile-debug Normal file
View File

@ -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

View File

@ -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"]

10
entrypoint.sh Executable file
View File

@ -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}