-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile.dinkum
305 lines (248 loc) · 12.3 KB
/
Dockerfile.dinkum
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Copyright 2022 Mycroft AI Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# -----------------------------------------------------------------------------
#
# Docker build script for Mark II
#
# Requires buildkit: https://docs.docker.com/develop/develop-images/build_enhancements/
# -----------------------------------------------------------------------------
FROM scratch as base
ADD raspberry-pi-os/p2.tar /
# -----------------------------------------------------------------------------
# Base image with locale set
FROM base as base-with-locale
ARG TARGETARCH
ARG TARGETVARIANT
ENV DEBIAN_FRONTEND=noninteractive
# Set the locale
RUN --mount=type=cache,id=apt-base-with-local,target=/var/cache/apt \
apt-get update && apt-get install -y locales \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# -----------------------------------------------------------------------------
# Base image for building tools and virtual environments
FROM base-with-locale as base-build
WORKDIR /build
COPY docker/packages-build.txt docker/packages-venv.txt ./
RUN --mount=type=cache,id=apt-base-build,target=/var/cache/apt \
apt-get update && \
cat packages-*.txt | xargs apt-get install --yes --no-install-recommends
# -----------------------------------------------------------------------------
# Build
# -----------------------------------------------------------------------------
# Image where Mycroft GUI is built
FROM base-build as build-gui
COPY mycroft-dinkum/services/gui/mycroft-gui/ ./mycroft-gui/
COPY docker/build/gui/build-mycroft-gui.sh ./
RUN ./build-mycroft-gui.sh
COPY mycroft-dinkum/services/gui/lottie-qml/ ./lottie-qml/
COPY docker/build/gui/build-lottie-qml.sh ./
RUN ./build-lottie-qml.sh
COPY mycroft-dinkum/services/gui/mycroft-gui-mark-2/ ./mycroft-gui-mark-2/
COPY docker/build/gui/build-mycroft-gui-mark-2.sh ./
RUN ./build-mycroft-gui-mark-2.sh
# -----------------------------------------------------------------------------
# Image where Mimic C++ executable is built
FROM base-build as build-mimic3
WORKDIR /opt/mycroft/mimic3-cpp
COPY mimic3-cpp/ ./
COPY files/usr/local/include/onnxruntime/ /usr/local/include/onnxruntime/
RUN ln -s /usr/local/include/onnxruntime/lib/libonnxruntime.so.1.12.1 /usr/lib/libonnxruntime.so
RUN make release
# -----------------------------------------------------------------------------
FROM base-build as build-dinkum
# Create dinkum (shared) virtual environment
WORKDIR /opt/mycroft-dinkum
ENV DINKUM_VENV=/opt/mycroft-dinkum/.venv
# Just copy requirements and scripts so we don't have to rebuild this every time
# a code file changes.
COPY mycroft-dinkum/services/audio/requirements/ ./services/audio/requirements/
COPY mycroft-dinkum/services/enclosure/requirements/ ./services/enclosure/requirements/
COPY mycroft-dinkum/services/gui/requirements/ ./services/gui/requirements/
COPY mycroft-dinkum/services/hal/requirements/ ./services/hal/requirements/
COPY mycroft-dinkum/services/intent/requirements/ ./services/intent/requirements/
COPY mycroft-dinkum/services/messagebus/requirements/ ./services/messagebus/requirements/
COPY mycroft-dinkum/services/voice/requirements/ ./services/voice/requirements/
# Skill requirements
COPY mycroft-dinkum/skills/alarm.mark2/requirements.txt ./skills/alarm.mark2/
# COPY mycroft-dinkum/skills/date.mark2/requirements.txt ./skills/date.mark2/
# COPY mycroft-dinkum/skills/fallback-query.mark2/requirements.txt ./skills/fallback-query.mark2/
# COPY mycroft-dinkum/skills/fallback-unknown.mark2/requirements.txt ./skills/fallback-unknown.mark2/
COPY mycroft-dinkum/skills/homeassistant.mark2/requirements.txt ./skills/homeassistant.mark2/
COPY mycroft-dinkum/skills/homescreen.mark2/requirements.txt ./skills/homescreen.mark2/
COPY mycroft-dinkum/skills/ip.mark2/requirements.txt ./skills/ip.mark2/
# COPY mycroft-dinkum/skills/microphone.mark2/requirements.txt ./skills/microphone.mark2/
COPY mycroft-dinkum/skills/news.mark2/requirements.txt ./skills/news.mark2/
# COPY mycroft-dinkum/skills/play.mark2/requirements.txt ./skills/play.mark2/
# COPY mycroft-dinkum/skills/play-music.mark2/requirements.txt ./skills/play-music.mark2/
COPY mycroft-dinkum/skills/play-radio.mark2/requirements.txt ./skills/play-radio.mark2/
# COPY mycroft-dinkum/skills/privacy/requirements.txt ./skills/privacy.mark2/
COPY mycroft-dinkum/skills/query-duck-duck-go.mark2/requirements.txt ./skills/query-duck-duck-go.mark2/
COPY mycroft-dinkum/skills/query-wiki.mark2/requirements.txt ./skills/query-wiki.mark2/
COPY mycroft-dinkum/skills/query-wolfram-alpha.mark2/requirements.txt ./skills/query-wolfram-alpha.mark2/
# COPY mycroft-dinkum/skills/stop.mark2/requirements.txt ./skills/stop.mark2/
COPY mycroft-dinkum/skills/time.mark2/requirements.txt ./skills/time.mark2/
COPY mycroft-dinkum/skills/timer.mark2/requirements.txt ./skills/timer.mark2/
# COPY mycroft-dinkum/skills/volume.mark2/requirements.txt ./skills/volume.mark2/
COPY mycroft-dinkum/skills/weather.mark2/requirements.txt ./skills/weather.mark2/
# Create shared virtual environment with upgraded pip/setuptools
#
# NOTE: It's crucial that system site packages are available so the HAL service
# can access RPi.GPIO.
#
RUN --mount=type=cache,id=pip-build-dinkum,target=/root/.cache/pip \
python3 -m venv --system-site-packages "${DINKUM_VENV}" && \
"${DINKUM_VENV}/bin/pip3" install --upgrade pip && \
"${DINKUM_VENV}/bin/pip3" install --upgrade wheel setuptools
# Install dinkum service/skill requirements
RUN --mount=type=cache,id=pip-build-dinkum,target=/root/.cache/pip \
find ./ -name 'requirements.txt' -type f -print0 | \
xargs -0 printf -- '-r %s ' | xargs "${DINKUM_VENV}/bin/pip3" install
# Install plugins
COPY mycroft-dinkum/plugins/ ./plugins/
COPY mimic3/ ./mimic3/
COPY docker/build/mycroft/wheels/ ./wheels/
RUN --mount=type=cache,id=pip-build-dinkum,target=/root/.cache/pip \
"${DINKUM_VENV}/bin/pip3" install ./plugins/hotword_precise/ && \
"${DINKUM_VENV}/bin/pip3" install -f ./wheels/ ./plugins/stt_coqui/ && \
"${DINKUM_VENV}/bin/pip3" install ./plugins/stt_vosk/ && \
"${DINKUM_VENV}/bin/pip3" install ./mimic3 && \
"${DINKUM_VENV}/bin/pip3" install mycroft-plugin-tts-mimic3
# Install shared dinkum library
COPY mycroft-dinkum/shared/setup.py \
shared/
COPY mycroft-dinkum/shared/requirements/requirements.txt \
shared/requirements/
COPY mycroft-dinkum/shared/mycroft/py.typed \
mycroft-dinkum/shared/mycroft/__init__.py \
shared/mycroft/
RUN --mount=type=cache,id=pip-build-dinkum,target=/root/.cache/pip \
"${DINKUM_VENV}/bin/pip3" install -e ./shared/
# Create dinkum.target and services
COPY mycroft-dinkum/scripts/generate-systemd-units.py ./scripts/
RUN scripts/generate-systemd-units.py \
--user pi \
--venv-dir "${DINKUM_VENV}" \
--service 0 services/messagebus \
--service 1 services/hal \
--service 1 services/audio \
--service 1 services/gui \
--service 1 services/intent \
--service 1 services/voice \
--service 2 services/skills \
--service 3 services/enclosure \
--skill skills/alarm.mark2 \
--skill skills/date.mark2 \
--skill skills/fallback-query.mark2 \
--skill skills/fallback-unknown.mark2 \
--skill skills/homeassistant.mark2 \
--skill skills/homescreen.mark2 \
--skill skills/ip.mark2 \
--skill skills/microphone.mark2 \
--skill skills/news.mark2 \
--skill skills/play.mark2 \
--skill skills/play-music.mark2 \
--skill skills/play-radio.mark2 \
--skill skills/privacy.mark2 \
--skill skills/query-duck-duck-go.mark2 \
--skill skills/query-wiki.mark2 \
--skill skills/query-wolfram-alpha.mark2 \
--skill skills/settings.mark2 \
--skill skills/stop.mark2 \
--skill skills/time.mark2 \
--skill skills/timer.mark2 \
--skill skills/volume.mark2 \
--skill skills/weather.mark2
# -----------------------------------------------------------------------------
# Image where XMOS/HAL services are built
FROM base-build as build-hal
COPY dbus-hal /usr/local/mycroft/mark-2/dbus-hal/
RUN --mount=type=cache,id=pip-build-hal,target=/root/.cache/pip \
cd /usr/local/mycroft/mark-2/dbus-hal/ && \
./install.sh
# -----------------------------------------------------------------------------
# Run
# -----------------------------------------------------------------------------
FROM base-with-locale as run
ARG TARGETARCH
ARG TARGETVARIANT
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "Dir::Cache var/cache/apt/${TARGETARCH}${TARGETVARIANT};" > /etc/apt/apt.conf.d/01cache
COPY docker/packages-run.txt ./
RUN --mount=type=cache,id=apt-build,target=/var/cache/apt \
mkdir -p /var/cache/apt/${TARGETARCH}${TARGETVARIANT}/archives/partial && \
apt-get update && \
cat packages-*.txt | xargs apt-get install --yes --no-install-recommends
# Kernel module and setup scripts
COPY vocalfusion/app_xvf3510_int_spi_boot_v4_2_0.bin \
vocalfusion/run.sh \
vocalfusion/setup_microphone.py \
vocalfusion/setup_speakers.py \
vocalfusion/vocalfusion-rpi-setup-5.2.0/loader/i2s_master/i2s_master_loader.ko \
vocalfusion/vocalfusion-rpi-setup-5.2.0/resources/clk_dac_setup/setup_mclk \
vocalfusion/vocalfusion-rpi-setup-5.2.0/resources/clk_dac_setup/setup_bclk \
/usr/local/mycroft/mark-2/
# ALSA config
COPY vocalfusion/vocalfusion-rpi-setup-5.2.0/resources/asoundrc_vf_xvf3510_int \
/etc/alsa/conf.d/20-xmos.conf
# systemd service
COPY vocalfusion/etc/mark2-microphone.service \
/etc/systemd/system/
# Enable i2c
RUN echo 'i2c-dev' >> /etc/modules
# Copy HAL tools
COPY --from=build-hal --chown=pi:pi /usr/local/mycroft/ /usr/local/mycroft/
# Copy pre-built GUI files
COPY --from=build-gui /usr/local/ /usr/
COPY --from=build-gui /usr/lib/aarch64-linux-gnu/qt5/qml/ /usr/lib/aarch64-linux-gnu/qt5/qml/
# Copy Mimic3 C++ executable
COPY --from=build-mimic3 --chown=pi:pi /opt/mycroft/mimic3-cpp/build/mimic3/mimic3 /opt/mycroft/bin/
# Copy dinkum code and virtual environment
COPY --from=build-dinkum --chown=pi:pi /opt/mycroft-dinkum/.venv/ /opt/mycroft-dinkum/.venv/
COPY --chown=pi:pi mycroft-dinkum/ /opt/mycroft-dinkum/
RUN rm -f /opt/mycroft-dinkum/.git
COPY --chown=pi:pi .git/modules/mycroft-dinkum/ /opt/mycroft-dinkum/.git/
RUN sed -i 's|worktree\s\+=.*|worktree = ../|' /opt/mycroft-dinkum/.git/config
# Need to unzip model
RUN gunzip --keep /opt/mycroft-dinkum/.venv/lib/python3.9/site-packages/mycroft_coqui/models/english_v1.0.0-large-vocab/large_vocabulary.scorer.gz
# Copy system files
COPY files/ /
# Install the Noto Sans font family using config from /etc
ADD docker/build/mycroft/Font_NotoSans-hinted.tar.gz /usr/share/fonts/truetype/noto-sans/
COPY docker/build/mycroft/install-fonts.sh ./
RUN ./install-fonts.sh
# Fix permissions
RUN chown -R pi:pi /home/pi/
# Enable services
COPY --from=build-dinkum /etc/systemd/system/dinkum* /etc/systemd/system/
RUN systemctl enable /etc/systemd/system/mark2-microphone.service && \
systemctl enable /etc/systemd/system/mark2-hal.service && \
systemctl enable /etc/systemd/system/mark2-boot.service && \
systemctl enable /etc/systemd/system/mark2-plasma.service && \
systemctl enable /etc/systemd/system/mark2-automount.service && \
systemctl enable /etc/systemd/system/dinkum.target && \
systemctl set-default graphical
# Service aliases
RUN ln -s /etc/systemd/system/mark2-microphone.service /etc/systemd/system/mycroft-xmos.service && \
ln -s /etc/systemd/system/mark2-plasma.service /etc/systemd/system/mycroft-plasma.service
# Clean up
RUN --mount=type=cache,id=apt-build,target=/var/cache/apt \
apt-get clean && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt/ && \
rm -f /etc/apt/apt.conf.d/01cache