Skip to content

Commit

Permalink
优化Dockerfile分层,尽可能复用缓存;增加条件构建,可以用IMAGE_TYPE参数构建不包含额外模型的Docker镜像来减少镜像大…
Browse files Browse the repository at this point in the history
…小;增加批量构建Docker镜像脚本
  • Loading branch information
breakstring committed Feb 9, 2024
1 parent 028b78f commit 2bf5e00
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
docs
logs
output
reference
reference
SoVITS_weights
.git
39 changes: 24 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM cnstark/pytorch:2.0.1-py3.9.17-cuda11.8.0-ubuntu20.04

LABEL maintainer="breakstring@hotmail.com"
LABEL version="dev-20240127"
LABEL version="dev-20240209"
LABEL description="Docker image for GPT-SoVITS"


Expand All @@ -11,25 +11,34 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt-get update && \
apt-get install -y --no-install-recommends tzdata ffmpeg libsox-dev parallel aria2 git git-lfs && \
rm -rf /var/lib/apt/lists/* && \
git lfs install
git lfs install && \
rm -rf /var/lib/apt/lists/*

# Copy application
# Copy only requirements.txt initially to leverage Docker cache
WORKDIR /workspace
COPY . /workspace
COPY requirements.txt /workspace/
RUN pip install --no-cache-dir -r requirements.txt

# Define a build-time argument for image type
ARG IMAGE_TYPE=full

# install python packages
RUN pip install -r requirements.txt
# Conditional logic based on the IMAGE_TYPE argument
# Always copy the Docker directory, but only use it if IMAGE_TYPE is not "elite"
COPY ./Docker /workspace/Docker
# elite 类型的镜像里面不包含额外的模型
RUN if [ "$IMAGE_TYPE" != "elite" ]; then \
chmod +x /workspace/Docker/download.sh && \
/workspace/Docker/download.sh && \
python /workspace/Docker/download.py && \
python -m nltk.downloader averaged_perceptron_tagger cmudict; \
fi

# Download models
RUN chmod +x /workspace/Docker/download.sh && /workspace/Docker/download.sh

# Download moda ASR related
RUN python /workspace/Docker/download.py
# Copy the rest of the application
COPY . /workspace

# Download nltk realted
RUN python -m nltk.downloader averaged_perceptron_tagger
RUN python -m nltk.downloader cmudict
# Copy the rest of the application
COPY . /workspace


EXPOSE 9870
Expand All @@ -42,4 +51,4 @@ VOLUME /workspace/output
VOLUME /workspace/logs
VOLUME /workspace/SoVITS_weights

CMD ["python", "webui.py"]
CMD ["python", "webui.py"]
14 changes: 14 additions & 0 deletions dockerbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# 获取当前日期,格式为 YYYYMMDD
DATE=$(date +%Y%m%d)

# 构建 full 版本的镜像
docker build --build-arg IMAGE_TYPE=full -t breakstring/gpt-sovits:latest .
# 为同一个镜像添加带日期的标签
docker tag breakstring/gpt-sovits:latest breakstring/gpt-sovits:dev-$DATE

# 构建 elite 版本的镜像
docker build --build-arg IMAGE_TYPE=elite -t breakstring/gpt-sovits:latest-elite .
# 为同一个镜像添加带日期的标签
docker tag breakstring/gpt-sovits:latest-elite breakstring/gpt-sovits:dev-$DATE-elite

0 comments on commit 2bf5e00

Please sign in to comment.