-
Notifications
You must be signed in to change notification settings - Fork 135
/
Dockerfile
136 lines (105 loc) · 4.71 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
# -----------------------------------------------------------------------------
# Dockerfile for OpenTTS (https://github.com/synesthesiam/opentts)
#
# Requires Docker buildx: https://docs.docker.com/buildx/working-with-buildx/
# -----------------------------------------------------------------------------
FROM debian:bullseye as build
ARG TARGETARCH
ARG TARGETVARIANT
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "Dir::Cache var/cache/apt/${TARGETARCH}${TARGETVARIANT};" > /etc/apt/apt.conf.d/01cache
RUN --mount=type=cache,id=apt-build,target=/var/cache/apt \
mkdir -p /var/cache/apt/${TARGETARCH}${TARGETVARIANT}/archives/partial && \
apt-get update && \
apt-get install --yes --no-install-recommends \
build-essential python3 python3-venv python3-dev wget
# Install extra Debian build packages added from ./configure
COPY build_packages /build_packages
RUN --mount=type=cache,id=apt-build,target=/var/cache/apt \
if [ -s /build_packages ]; then \
cat /build_packages | xargs apt-get install --yes --no-install-recommends; \
fi
RUN mkdir -p /home/opentts/app
WORKDIR /home/opentts/app
# Create virtual environment
RUN --mount=type=cache,id=pip-venv,target=/root/.cache/pip \
python3 -m venv .venv && \
.venv/bin/pip3 install --upgrade pip && \
.venv/bin/pip3 install --upgrade wheel setuptools
# Put cached Python wheels here
COPY download/ /download/
COPY requirements.txt requirements.txt
# Install base Python requirements
RUN --mount=type=cache,id=pip-requirements,target=/root/.cache/pip \
grep -v '^torch' requirements.txt | \
xargs .venv/bin/pip3 install -f /download
RUN --mount=type=cache,id=apt-build,target=/var/cache/apt \
if [ "${TARGETARCH}${TARGETVARIANT}" = 'armv7' ]; then \
apt-get install --yes --no-install-recommends llvm-dev ; \
fi
COPY python_packages /python_packages
# Use CPU-only PyTorch to save space.
RUN if [ "${TARGETARCH}${TARGETVARIANT}" = 'amd64' ]; then \
sed -i 's/^torch[~=]\+\(.\+\)$/torch==\1+cpu/' /python_packages ; \
fi
# Install extra Python packages added from ./configure
RUN --mount=type=cache,id=pip-extras,target=/root/.cache/pip \
if [ -s /python_packages ]; then \
cat /python_packages | xargs .venv/bin/pip3 install \
-f /download \
-f 'https://synesthesiam.github.io/prebuilt-apps/' \
-f 'https://download.pytorch.org/whl/cpu/torch_stable.html' ; \
fi
# Install prebuilt nanoTTS
RUN mkdir -p /nanotts && \
wget -O - --no-check-certificate \
"https://github.com/synesthesiam/prebuilt-apps/releases/download/v1.0/nanotts-20200520_${TARGETARCH}${TARGETVARIANT}.tar.gz" | \
tar -C /nanotts -xzf -
# -----------------------------------------------------------------------------
FROM debian:bullseye as run
ARG TARGETARCH
ARG TARGETVARIANT
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
COPY packages /packages
RUN echo 'deb http://deb.debian.org/debian bullseye contrib non-free' > /etc/apt/sources.list.d/contrib.list
# Install extra Debian packages added from ./configure
RUN echo "Dir::Cache var/cache/apt/${TARGETARCH}${TARGETVARIANT};" > /etc/apt/apt.conf.d/01cache
RUN --mount=type=cache,id=apt-run,target=/var/cache/apt \
mkdir -p /var/cache/apt/${TARGETARCH}${TARGETVARIANT}/archives/partial && \
apt-get update && \
cat /packages | xargs apt-get install --yes --no-install-recommends
# Copy nanotts
COPY --from=build /nanotts/ /usr/
# Clean up
RUN rm -f /etc/apt/apt.conf.d/01cache
# Add a user to run the application (non-root)
RUN useradd -ms /bin/bash opentts
# Copy virtual environment and files
COPY voices/ /home/opentts/app/voices/
COPY --from=build /home/opentts/app/.venv /home/opentts/app/.venv
COPY css/ /home/opentts/app/css/
COPY img/ /home/opentts/app/img/
COPY js/ /home/opentts/app/js/
COPY templates/ /home/opentts/app/templates/
COPY glow_speak/ /home/opentts/app/glow_speak/
COPY larynx/ /home/opentts/app/larynx/
COPY TTS/ /home/opentts/app/TTS/
COPY app.py tts.py VERSION swagger.yaml /home/opentts/app/
ARG DEFAULT_LANGUAGE='en'
RUN echo "${DEFAULT_LANGUAGE}" > /home/opentts/app/LANGUAGE
# Post-installation
RUN if [ -d '/usr/share/festival' ] && [ -d '/home/opentts/app/voices/festival/ar' ]; then \
cp "/home/opentts/app/voices/festival/ar/languages/language_arabic.scm" \
"/usr/share/festival/languages/" && \
mkdir -p "/usr/share/festival/voices/arabic" && \
cp -r "/home/opentts/app/voices/festival/ar/voices/ara_norm_ziad_hts" "/usr/share/festival/voices/arabic/"; \
fi
USER opentts
WORKDIR /home/opentts/app
# Sanity check
RUN .venv/bin/python3 app.py --version
EXPOSE 5500
ENTRYPOINT [".venv/bin/python3", "app.py"]
# -----------------------------------------------------------------------------