-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
139 lines (114 loc) · 4.03 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# syntax=docker/dockerfile:1.4
# TODO: build-arg と target のドキュメントをこのファイルに書く
ARG BASE_IMAGE=ubuntu:22.04
ARG BASE_RUNTIME_IMAGE=$BASE_IMAGE
# Compile Python (version locked)
FROM ${BASE_IMAGE} AS compile-python-env
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -eux
apt-get update
apt-get install -y \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
curl \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
git
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF
ARG PYTHON_VERSION=3.11.9
ARG PYENV_VERSION=v2.4.11
ARG PYENV_ROOT=/tmp/.pyenv
ARG PYBUILD_ROOT=/tmp/python-build
RUN <<EOF
set -eux
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
# set -eux
# 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
# Set timezone to Asia/Tokyo
ENV TZ=Asia/Tokyo
WORKDIR /opt/aivisspeech-engine
# ca-certificates: pyopenjtalk dictionary download
# build-essential: pyopenjtalk local build
# libsndfile1: soundfile shared object for arm64
# ref: https://github.com/VOICEVOX/voicevox_engine/issues/770
RUN <<EOF
set -eux
apt-get update
apt-get install -y \
git \
curl \
cmake \
ca-certificates \
build-essential \
gosu \
libsndfile1
apt-get clean
rm -rf /var/lib/apt/lists/*
# Create a general user
useradd --create-home user
EOF
# Copy python env
COPY --from=compile-python-env /opt/python /opt/python
# Install Python dependencies
ADD ./poetry.toml ./poetry.lock ./pyproject.toml /opt/aivisspeech-engine/
RUN <<EOF
/opt/python/bin/pip3 install poetry
chown -R user /opt/aivisspeech-engine
# Install Rust (Sudachipy arm64 wheel build dependencies)
gosu user bash -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
gosu user bash -c "source /home/user/.cargo/env; /opt/python/bin/poetry install --only=main"
gosu user rm -rf /home/user/.cargo
EOF
# Add local files
ADD ./voicevox_engine /opt/aivisspeech-engine/voicevox_engine
ADD ./docs /opt/aivisspeech-engine/docs
ADD ./run.py ./engine_manifest.json /opt/aivisspeech-engine/
ADD ./resources /opt/aivisspeech-engine/resources
ADD ./tools/generate_licenses.py /opt/aivisspeech-engine/tools/
ADD ./tools/licenses /opt/aivisspeech-engine/tools/licenses
# Replace version
ARG AIVISSPEECH_ENGINE_VERSION=latest
RUN sed -i "s/__version__ = \"latest\"/__version__ = \"${AIVISSPEECH_ENGINE_VERSION}\"/" /opt/aivisspeech-engine/voicevox_engine/__init__.py
RUN sed -i "s/\"version\": \"999\\.999\\.999\"/\"version\": \"${AIVISSPEECH_ENGINE_VERSION}\"/" /opt/aivisspeech-engine/engine_manifest.json
# openjtalk-plus include dictionary in itself, download is not needed
# Create container start shell
COPY --chmod=775 <<EOF /entrypoint.sh
#!/bin/bash
set -eux
exec "\$@"
EOF
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "gosu", "user", "/opt/python/bin/poetry", "run", "python", "./run.py", "--host", "0.0.0.0" ]
# Enable use_gpu
FROM runtime-env AS runtime-nvidia-env
CMD [ "gosu", "user", "/opt/python/bin/poetry", "run", "python", "./run.py", "--use_gpu", "--host", "0.0.0.0" ]