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

entrypoint.sh内にスペースインデントが入ってしまう問題の対応と可読性の向上 #105

Merged
merged 3 commits into from
Sep 18, 2021
Merged
Changes from 2 commits
Commits
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
81 changes: 39 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,33 +163,15 @@ RUN <<EOF
libsndfile1 \
ca-certificates \
build-essential \
parallel
parallel \
gosu
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 python env
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
Expand All @@ -198,43 +180,58 @@ COPY --from=download-core-env /opt/voicevox_core /opt/voicevox_core
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

# Clone voicevox_core
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
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 local files
# Temporary override PATH for convenience during the image building
# ARG PATH=/opt/python/bin:$PATH
ADD ./requirements.txt /tmp/
ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine
ADD ./run.py ./check_tts.py ./VERSION.txt ./LICENSE ./LGPL_LICENSE /opt/voicevox_engine/

# Download openjtalk dictionary
RUN <<EOF
# FIXME: remove first execution delay
# try 5 times, delay 5 seconds before each execution.
# if all tries are failed, `docker build` will be failed.
parallel --retries 5 --delay 5 --ungroup <<EOT
gosu user /opt/python/bin/python3 -c "import pyopenjtalk; pyopenjtalk._lazy_init()"
EOT
# Create container start shell
COPY <<EOF /entrypoint.sh
#!/bin/bash
cat /opt/voicevox_core/README.txt > /dev/stderr
exec "\$@"
EOF

# Update ldconfig on container start
RUN <<EOF
cat <<EOT > /entrypoint.sh
#!/bin/bash
cat /opt/voicevox_core/README.txt > /dev/stderr
chmod +x /entrypoint.sh
# Create a general user
useradd --create-home user
# Update ld
rm -f /etc/ld.so.cache && ldconfig

rm -f /etc/ld.so.cache
ldconfig
# Const environment
export PATH="$PATH:/opt/python/bin/"
export LIBRARY_PATH="/opt/voicevox_core:$LIBRARY_PATH"

exec "\$@"
EOT
chmod +x /entrypoint.sh
# Install requirements
gosu user python3 -m pip install --upgrade pip setuptools wheel
gosu user pip3 install -r /tmp/requirements.txt

# Install voicevox_core
cd /opt/voicevox_core_example/example/python
gosu user pip3 install .

# FIXME: remove first execution delay
# try 5 times, delay 5 seconds before each execution.
# if all tries are failed, `docker build` will be failed.

# Download openjtalk dictionary
parallel --retries 5 --delay 5 --ungroup <<- EOT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでも<<-が用いられていそうです。(修正忘れ?)

gosu user python3 -c "import pyopenjtalk; pyopenjtalk._lazy_init()"
EOT
EOF

ENTRYPOINT [ "bash", "/entrypoint.sh" ]
ENTRYPOINT [ "/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
Expand Down