Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile (Linux)・GitHub Actionsによる自動pushの追加 #84 #88

Merged
merged 37 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b08d449
linux docker
aoirint Sep 12, 2021
8bbb48e
add workflow to build linux docker
aoirint Sep 12, 2021
492fa27
update dockerhub description automatically
aoirint Sep 12, 2021
e17b91c
fix ld.so.conf.d directory name
aoirint Sep 12, 2021
09e2b25
use python3 instead python
aoirint Sep 12, 2021
226f50b
call ldconfig
aoirint Sep 12, 2021
0f7cf03
remove hub desc update because token cannot be used
aoirint Sep 12, 2021
79a9ae7
install core package
aoirint Sep 12, 2021
de20f62
install libtorch
aoirint Sep 12, 2021
17e5267
add doc: github secrets
aoirint Sep 12, 2021
4f8cec7
force update ldconfig cache
aoirint Sep 12, 2021
65ffb4f
docker cpu execute command in Makefile
aoirint Sep 12, 2021
3b073ca
lock python version 3.7.12 (self compile)
aoirint Sep 12, 2021
a6d0d1a
remove dev requirements install
aoirint Sep 12, 2021
219d592
general user execution with gosu
aoirint Sep 12, 2021
18a0d1b
add .PHONY to Makefile
aoirint Sep 12, 2021
35eead1
versioned image deploy
aoirint Sep 12, 2021
4b09a23
fix workflow: image tag
aoirint Sep 12, 2021
4a00422
fix workflow: image tag
aoirint Sep 12, 2021
bb96818
fix cache step
aoirint Sep 12, 2021
8f1f805
on.push.branches
aoirint Sep 12, 2021
d87fe29
fix cache
aoirint Sep 12, 2021
d33611c
fix docker tag version order
aoirint Sep 12, 2021
2f84702
revert image tag version order
aoirint Sep 12, 2021
c1f51c0
simple tag formatting
aoirint Sep 12, 2021
b4b8617
fix head hyphen tag name
aoirint Sep 12, 2021
d6f7a40
fix head hyphen tag name
aoirint Sep 12, 2021
445d334
fix head hyphen tag name
aoirint Sep 12, 2021
4a6fa87
cache per base image
aoirint Sep 12, 2021
6ed55bd
one step multi tags (cache overflow)
aoirint Sep 12, 2021
a6229a3
registry cache
aoirint Sep 12, 2021
dbdfa31
run build-docker on push master
aoirint Sep 12, 2021
f6841ec
fix doc: -latest
aoirint Sep 12, 2021
cf41993
fix doc: whitespace
aoirint Sep 12, 2021
b3b5aae
update ldconfig on container start
aoirint Sep 12, 2021
eb6836f
cat voicevox core README on container start
aoirint Sep 12, 2021
2bb5d0f
cat README to stderr
aoirint Sep 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: build-docker
on:
push:
branches:
- master
release:
types:
- created

jobs:
build-docker:
runs-on: ${{ matrix.os }}

env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/voicevox_engine
# IMAGE_NAME: voicevox/voicevox_engine

strategy:
matrix:
include:
- os: ubuntu-latest
tag: ''
target: runtime-env
base_runtime_image: ubuntu:focal
- os: ubuntu-latest
tag: cpu
target: runtime-env
base_runtime_image: ubuntu:focal
- os: ubuntu-latest
tag: cpu-ubuntu20.04
target: runtime-env
base_runtime_image: ubuntu:focal
- os: ubuntu-latest
tag: nvidia
target: runtime-nvidia-env
base_runtime_image: nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04
- os: ubuntu-latest
tag: nvidia-ubuntu20.04
target: runtime-nvidia-env
base_runtime_image: nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04

steps:
- uses: actions/checkout@v2

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Deploy Docker image
uses: docker/build-push-action@v2
env:
IMAGE_TAG: ${{ env.IMAGE_NAME }}:${{ matrix.tag }}${{ (matrix.tag != '' && '-') || '' }}latest
VERSIONED_IMAGE_TAG: |
${{ (
github.event.release.tag_name != '' && (
matrix.tag != '' && (
format('{0}:{1}-{2}', env.IMAGE_NAME, matrix.tag, github.event.release.tag_name)
) || format('{0}:{1}', env.IMAGE_NAME, github.event.release.tag_name)
)
) || '' }}
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: ./Dockerfile
build-args: |
BASE_RUNTIME_IMAGE=${{ matrix.base_runtime_image }}
target: ${{ matrix.target }}
push: true
tags: |
${{ env.IMAGE_TAG }}
${{ env.VERSIONED_IMAGE_TAG }}
cache-from: type=registry,ref=${{ env.IMAGE_TAG }}-buildcache
cache-to: type=registry,ref=${{ env.IMAGE_TAG }}-buildcache,mode=max
208 changes: 208 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# syntax=docker/dockerfile:1.3-labs

ARG BASE_RUNTIME_IMAGE=ubuntu:focal

# Download VOICEVOX Core shared object
FROM ubuntu:focal AS download-core-env
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /work

RUN <<EOF
apt-get update
apt-get install -y \
wget \
unzip
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF

ARG VOICEVOX_CORE_VERSION=0.5.2
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
RUN <<EOF
wget -nv --show-progress -c -O "./core.zip" "https://github.com/Hiroshiba/voicevox_core/releases/download/${VOICEVOX_CORE_VERSION}/core.zip"
unzip "./core.zip"
mv ./core /opt/voicevox_core
rm ./core.zip
EOF

RUN <<EOF
echo "/opt/voicevox_core" > /etc/ld.so.conf.d/voicevox_core.conf
rm -f /etc/ld.so.cache
ldconfig
EOF


# Download LibTorch
FROM ubuntu:focal AS download-libtorch-env
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /work

RUN <<EOF
apt-get update
apt-get install -y \
wget \
unzip
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF

ARG LIBTORCH_URL=https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip
RUN <<EOF
wget -nv --show-progress -c -O "./libtorch.zip" "${LIBTORCH_URL}"
unzip "./libtorch.zip"
mv ./libtorch /opt/libtorch
rm ./libtorch.zip
EOF

RUN <<EOF
echo "/opt/libtorch/lib" > /etc/ld.so.conf.d/libtorch.conf
rm -f /etc/ld.so.cache
ldconfig
EOF


# Compile Python (version locked)
FROM ubuntu:focal AS compile-python-env

ARG DEBIAN_FRONTEND=noninteractive

RUN <<EOF
apt-get update
apt-get install -y \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libffi-dev \
liblzma-dev \
python-openssl \
git
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF

ARG PYTHON_VERSION=3.7.12
# FIXME: Lock pyenv version with git tag
# 90d0d20508a91e7ea1e609e8aa9f9d1a28bb563e (including 3.7.12) not released yet (2021-09-12)
ARG PYENV_VERSION=master
ARG PYENV_ROOT=/tmp/.pyenv
ARG PYBUILD_ROOT=/tmp/python-build
RUN <<EOF
set -e
git clone -b "${PYENV_VERSION}" https://github.com/pyenv/pyenv.git "$PYENV_ROOT"
PREFIX="$PYBUILD_ROOT" "$PYENV_ROOT"/plugins/python-build/install.sh
"$PYBUILD_ROOT/bin/python-build" -v "$PYTHON_VERSION" /opt/python
rm -rf "$PYBUILD_ROOT" "$PYENV_ROOT"
EOF

# FIXME: add /opt/python to PATH
# not working: /etc/profile read only on login shell
# not working: /etc/environment is the same
# not suitable: `ENV` is ignored by docker-compose
# RUN <<EOF
# echo "export PATH=/opt/python/bin:\$PATH" > /etc/profile.d/python-path.sh
# echo "export LD_LIBRARY_PATH=/opt/python/lib:\$LD_LIBRARY_PATH" >> /etc/profile.d/python-path.sh
# echo "export C_INCLUDE_PATH=/opt/python/include:\$C_INCLUDE_PATH" >> /etc/profile.d/python-path.sh
#
# rm -f /etc/ld.so.cache
# ldconfig
# EOF


# Runtime
FROM ${BASE_RUNTIME_IMAGE} AS runtime-env
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /opt/voicevox_engine

# libsndfile1: soundfile shared object
# ca-certificates: pyopenjtalk dictionary download
# build-essential: pyopenjtalk local build
RUN <<EOF
apt-get update
apt-get install -y \
git \
cmake \
libsndfile1 \
ca-certificates \
build-essential
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF

# gosu: general user execution
ARG GOSU_VERSION=1.14
ADD "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" /usr/local/bin/gosu
RUN <<EOF
chmod +x /usr/local/bin/gosu
EOF

# Create a general user
RUN <<EOF
useradd --create-home user
EOF

COPY --from=compile-python-env /opt/python /opt/python

# Temporary override PATH for convenience during the image building
# ARG PATH=/opt/python/bin:$PATH
ADD ./requirements.txt /tmp/
RUN <<EOF
gosu user /opt/python/bin/python3 -m pip install --upgrade pip setuptools wheel
gosu user /opt/python/bin/pip3 install -r /tmp/requirements.txt
EOF

# Copy VOICEVOX Core shared object
COPY --from=download-core-env /etc/ld.so.conf.d/voicevox_core.conf /etc/ld.so.conf.d/voicevox_core.conf
COPY --from=download-core-env /opt/voicevox_core /opt/voicevox_core

# Copy LibTorch
COPY --from=download-libtorch-env /etc/ld.so.conf.d/libtorch.conf /etc/ld.so.conf.d/libtorch.conf
COPY --from=download-libtorch-env /opt/libtorch /opt/libtorch

ARG VOICEVOX_CORE_EXAMPLE_VERSION=0.5.2
RUN <<EOF
git clone -b "${VOICEVOX_CORE_EXAMPLE_VERSION}" --depth 1 https://github.com/Hiroshiba/voicevox_core.git /opt/voicevox_core_example
cd /opt/voicevox_core_example
cp ./core.h ./example/python/
cd example/python
LIBRARY_PATH="/opt/voicevox_core:$LIBRARY_PATH" gosu user /opt/python/bin/pip3 install .
EOF

ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine
ADD ./run.py ./check_tts.py ./VERSION.txt ./speakers.json ./LICENSE ./LGPL_LICENSE /opt/voicevox_engine/

# Download openjtalk dictionary
RUN <<EOF
gosu user /opt/python/bin/python3 -c "import pyopenjtalk; pyopenjtalk._lazy_init()"
EOF

# Update ldconfig on container start
RUN <<EOF
cat <<EOT > /entrypoint.sh
rm -f /etc/ld.so.cache
ldconfig

Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
cat /opt/voicevox_core/README.txt > /dev/stderr

exec "\$@"
EOT
chmod +x /entrypoint.sh
EOF

ENTRYPOINT [ "bash", "/entrypoint.sh" ]
CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--voicevox_dir", "/opt/voicevox_core/", "--voicelib_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]

# Enable use_gpu
FROM runtime-env AS runtime-nvidia-env
CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--use_gpu", "--voicevox_dir", "/opt/voicevox_core/", "--voicelib_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CMD=

.PHONY: build-linux-docker-ubuntu
build-linux-docker-ubuntu:
docker buildx build . \
-t aoirint/voicevox_engine:cpu-ubuntu20.04-latest \
--target runtime-env \
--progress plain \
--build-arg BASE_RUNTIME_IMAGE=ubuntu:focal

.PHONY: run-linux-docker-ubuntu
run-linux-docker-ubuntu:
docker run --rm -it \
-p '127.0.0.1:50021:50021' \
aoirint/voicevox_engine:cpu-ubuntu20.04-latest $(CMD)

.PHONY: build-linux-docker-nvidia
build-linux-docker-nvidia:
docker buildx build . \
-t aoirint/voicevox_engine:nvidia-ubuntu20.04-latest \
--target runtime-nvidia-env \
--progress plain \
--build-arg BASE_RUNTIME_IMAGE=nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04

.PHONY: run-linux-docker-nvidia
run-linux-docker-nvidia:
docker run --rm -it \
--gpus all \
-p '127.0.0.1:50021:50021' \
aoirint/voicevox_engine:nvidia-ubuntu20.04-latest $(CMD)

.PHONY: build-linux-docker-compile-python-env
build-linux-docker-compile-python-env:
docker buildx build . \
-t aoirint/voicevox_engine:compile-python-env \
--target compile-python-env \
--progress plain \
--build-arg BASE_RUNTIME_IMAGE=ubuntu:focal

.PHONY: run-linux-docker-compile-python-env
run-linux-docker-compile-python-env:
docker run --rm -it \
aoirint/voicevox_engine:compile-python-env $(CMD)
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ curl -s \
> audio.wav
```

## Docker イメージ

### CPU
```bash
docker pull aoirint/voicevox_engine:cpu-ubuntu20.04-latest
docker run --rm -it -p '127.0.0.1:50021:50021' aoirint/voicevox_engine:cpu-ubuntu20.04-latest
```

### GPU
```bash
docker pull aoirint/voicevox_engine:nvidia-ubuntu20.04-latest
docker run --rm --gpus all -p '127.0.0.1:50021:50021' aoirint/voicevox_engine:nvidia-ubuntu20.04-latest
```

## 貢献者の方へ

Issue を解決するプルリクエストを作成される際は、別の方と同じ Issue に取り組むことを避けるため、
Expand Down Expand Up @@ -95,6 +109,14 @@ python -m nuitka \
run.py
```

## GitHub Actions

### Secrets
|name|description|
|:--|:--|
|DOCKERHUB_USERNAME|Docker Hub ユーザ名|
|DOCKERHUB_TOKEN|[Docker Hub アクセストークン](https://hub.docker.com/settings/security)|

## ライセンス

LGPL v3 と、ソースコードの公開が不要な別ライセンスのデュアルライセンスです。
Expand Down