-
Notifications
You must be signed in to change notification settings - Fork 54
/
Dockerfile.agnos
265 lines (215 loc) · 9.38 KB
/
Dockerfile.agnos
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
# check=error=true
# ################## #
# ### Package ##### #
# ### Compilation ## #
# ################## #
FROM ubuntu:24.04 AS agnos-compiler
# Common packages
RUN apt-get update && apt-get install -yq --no-install-recommends \
build-essential \
ca-certificates \
ccache \
clang \
curl \
checkinstall \
git \
pkg-config \
wget
# Enable ccache
ENV PATH="/usr/lib/ccache:$PATH"
# capnproto
FROM agnos-compiler AS agnos-compiler-capnp
COPY ./userspace/compile-capnp.sh /tmp/agnos/
RUN --mount=type=cache,target=/root/.ccache,id=capnp,sharing=shared \
/tmp/agnos/compile-capnp.sh
# ffmpeg
FROM agnos-compiler AS agnos-compiler-ffmpeg
COPY ./userspace/compile-ffmpeg.sh /tmp/agnos/
RUN --mount=type=cache,target=/root/.ccache,id=ffmpeg,sharing=shared \
/tmp/agnos/compile-ffmpeg.sh
# ModemManager
FROM agnos-compiler AS agnos-compiler-modemmanager
COPY ./userspace/compile-modemmanager.sh /tmp/agnos/
RUN --mount=type=cache,target=/root/.ccache,id=modemmanager,sharing=shared \
/tmp/agnos/compile-modemmanager.sh
# qtwayland5
FROM agnos-compiler AS agnos-compiler-qtwayland5
COPY ./userspace/qtwayland/*.deb /tmp/agnos/
COPY ./userspace/compile-qtwayland5.sh /tmp/agnos/
COPY ./userspace/qtwayland/patch* /tmp/agnos/
RUN --mount=type=cache,target=/root/.ccache,id=qtwayland5,sharing=shared \
/tmp/agnos/compile-qtwayland5.sh
# ################## #
# ###### Base ###### #
# ################## #
FROM scratch AS agnos-base
# Add Ubuntu Base image files
ARG UBUNTU_BASE_IMAGE
ADD ${UBUNTU_BASE_IMAGE} /
# Build folder
RUN mkdir -p /tmp/agnos
# Stop on error
RUN set -xe
ARG USERNAME=comma
# Base system setup
RUN echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections
COPY ./userspace/base_setup.sh /tmp/agnos
RUN /tmp/agnos/base_setup.sh
# Install openpilot dependencies
COPY ./userspace/openpilot_dependencies.sh /tmp/agnos/
RUN /tmp/agnos/openpilot_dependencies.sh
COPY ./userspace/openpilot_python_dependencies.sh /tmp/agnos/
RUN /tmp/agnos/openpilot_python_dependencies.sh
# Install old Qt 5.12.8, libwayland 1.9.0-1 and deps
COPY ./userspace/qtwayland/*.deb /tmp/agnos/
RUN apt-get -o Dpkg::Options::="--force-overwrite" install -yq \
/tmp/agnos/qt-5.12.8.deb \
/tmp/agnos/libwayland-1.9.0-1.deb \
/tmp/agnos/libicu66_66.1-2ubuntu2.1_arm64.deb \
/tmp/agnos/libssl1.1_1.1.1f-1ubuntu2.22_arm64.deb \
/tmp/agnos/libffi6_3.2.1-8_arm64.deb
# ################### #
# ###### AGNOS ###### #
# ################### #
FROM agnos-base
# Hardware setup
RUN mkdir -p /tmp/agnos/debs
COPY ./userspace/debs /tmp/agnos/debs
COPY ./userspace/hardware_setup.sh /tmp/agnos
RUN /tmp/agnos/hardware_setup.sh
RUN mv /data/persist /system/ && rm -rf /data/*
# Pre-compiled libqmi and modemmanager
COPY --from=agnos-compiler-modemmanager /tmp/libqmi.deb /tmp/modemmanager.deb /tmp/
RUN cd /tmp && \
apt-get update && \
apt-get install -yq --no-install-recommends \
gir1.2-qmi-1.0 \
libglib2.0-dev \
libqmi-glib5 \
libc6 \
libglib2.0-0t64 \
libgudev-1.0-0 \
libmm-glib0 \
libpolkit-gobject-1-0 \
libsystemd0 \
polkitd \
polkitd-pkla \
mobile-broadband-provider-info && \
apt-get -o Dpkg::Options::="--force-overwrite" install -yq ./libqmi.deb && \
apt-get -o Dpkg::Options::="--force-overwrite" install -yq ./modemmanager.deb
# Pre-compiled capnp (must be before python install)
COPY --from=agnos-compiler-capnp /tmp/capnproto.deb /tmp/capnproto.deb
RUN cd /tmp && apt-get -o Dpkg::Options::="--force-overwrite" install -yq ./capnproto.deb
# Use other pre-compiled packages
COPY --from=agnos-compiler-ffmpeg /tmp/ffmpeg.deb /tmp/ffmpeg.deb
RUN cd /tmp && apt-get -o Dpkg::Options::="--force-overwrite" install -yq ./ffmpeg.deb
ARG XDG_DATA_HOME="/usr/local"
ARG PATH="$XDG_DATA_HOME/.cargo/bin:$PATH"
# Install openpilot python packages
COPY ./userspace/uv /tmp/agnos/uv
RUN source $XDG_DATA_HOME/venv/bin/activate && \
cd /tmp/agnos/uv && \
export PYOPENCL_CL_PRETEND_VERSION="2.0" && \
pc="$(python -c "import sysconfig;print(sysconfig.get_config_vars('installed_base')[0])")" && \
pcpath=$pc"/lib/pkgconfig" && \
export PKG_CONFIG_PATH="$pcpath:$PKG_CONFIG_PATH" && \
pypcpath=$pcpath"/python-3.12.pc" && \
sed -i 's|prefix=/install|prefix='$pc'|' $pypcpath && \
pypcpathembed=$pcpath"/python-3.12-embed.pc" && \
sed -i 's|prefix=/install|prefix='$pc'|' $pypcpathembed && \
MAKEFLAGS="-j$(nproc)" UV_NO_CACHE=1 UV_PROJECT_ENVIRONMENT=$XDG_DATA_HOME/venv uv sync --frozen --inexact --compile-bytecode
# Install nice to haves
COPY ./userspace/install_extras.sh /tmp/agnos/
RUN /tmp/agnos/install_extras.sh
COPY --from=agnos-compiler-qtwayland5 /tmp/qtwayland5.deb /tmp/qtwayland5.deb
RUN cd /tmp && apt-get -o Dpkg::Options::="--force-overwrite" install -yq --allow-downgrades ./qtwayland5.deb
# Patched libeglSubDriverWayland with fixed nullptr deref in CommitBuffer
COPY ./userspace/files/libeglSubDriverWayland.so.patched /lib/aarch64-linux-gnu/libeglSubDriverWayland.so
COPY ./userspace/home/ /home/$USERNAME/
COPY ./userspace/home/.config/ /root/.config
RUN chown -R $USERNAME: /home/$USERNAME/.config
# populate /lib
COPY ./userspace/files/*.path /lib/systemd/system/
COPY ./userspace/files/*.mount /lib/systemd/system/
COPY ./userspace/files/*.service /lib/systemd/system/
COPY ./userspace/files/*.timer /lib/systemd/system/
COPY ./userspace/files/serial-getty@ttyMSM0_override.conf /lib/systemd/system/serial-getty@ttyMSM0.service.d/serial-getty@ttyMSM0_override.conf
COPY ./userspace/files/ssh_override.conf /lib/systemd/system/ssh.service.d/override.conf
COPY ./userspace/firmware/* /lib/firmware/
# populate /etc
COPY ./userspace/files/fstab /etc
COPY ./userspace/files/profile /etc/profile
COPY ./userspace/files/01-network-manager-all.yaml /etc/netplan/
COPY ./userspace/files/allow-network-control.pkla /etc/polkit-1/localauthority/50-local.d/allow-network-control.pkla
COPY ./userspace/files/allow-modem-control.pkla /etc/polkit-1/localauthority/50-local.d/allow-modem-control.pkla
COPY ./userspace/files/*.rules /etc/udev/rules.d/
COPY ./userspace/files/ssh*_config /etc/ssh/
COPY ./userspace/files/logrotate.conf /etc/
RUN chmod 644 /etc/logrotate.conf
RUN touch -r /lib/systemd/systemd /etc/fstab
# populate /usr
COPY ./userspace/usr/comma/ /usr/$USERNAME/
COPY ./userspace/usr/share/fonts/* /usr/share/fonts/
COPY ./userspace/libs/* /usr/lib/aarch64-linux-gnu/
COPY ./userspace/libs32/* /usr/lib/arm-linux-gnueabihf/
# kernel headers for the AGNOS kernel (built on device)
COPY ./userspace/files/linux-headers-4.9.103+_4.9.103+-1_arm64.deb /tmp/
RUN dpkg -i /tmp/linux-headers-4.9.103+_4.9.103+-1_arm64.deb
# Weston with hacked touch rotate and color correction
COPY ./userspace/files/weston /usr/bin/weston
COPY ./userspace/files/gl-renderer.so /usr/lib/arm-linux-gnueabihf/weston
# Setup systemd services
COPY ./userspace/services.sh /tmp/agnos
RUN /tmp/agnos/services.sh
# MOTD
RUN rm -r /etc/update-motd.d/*
COPY --chown=root:root ./userspace/motd/* /etc/update-motd.d/
# Let NetworkManager manage eth0
COPY ./userspace/files/10-globally-managed-devices.conf /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
COPY ./userspace/files/NetworkManager.conf /etc/NetworkManager/NetworkManager.conf
# Add cellular connections
COPY ./userspace/files/*.nmconnection /usr/lib/NetworkManager/system-connections/
RUN chmod 600 /usr/lib/NetworkManager/system-connections/*.nmconnection
# Prefer ipv4 over ipv6
RUN echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf
# Don't let logind delete /dev/shm
COPY ./userspace/files/logind.conf /etc/systemd/logind.conf
# Remove qt network bearer plugins
RUN rm -rf /usr/lib/aarch64-linux-gnu/qt5/plugins/bearer
# Add iptable rules to block incoming traffic on wwan0
COPY ./userspace/etc/iptables/rules.v4 /etc/iptables/rules.v4
# Run ModemManager in debug mode to allow AT commands
COPY ./userspace/files/ModemManager.service /lib/systemd/system/
RUN systemctl enable ModemManager
# Add more T-Mobile networks to mobile-broadband-provider-info (do we still need the package?)
COPY ./userspace/files/serviceproviders.xml /usr/share/mobile-broadband-provider-info/serviceproviders.xml
# Copy extra FW, rest comes from debs
COPY ./userspace/files/CAMERA_ICP.elf /usr/lib/firmware
# Setup hostname resolution for our custom hostname
RUN sed -i 's/hosts: files dns myhostname/hosts: files myhostname dns/g' /etc/nsswitch.conf
# TODO: move this to base_setup.sh or build gcc from source
# Remove unused architectures & bins from arm-none-eabi
RUN cd /usr/lib/gcc/arm-none-eabi/* && \
rm -rf arm/ && \
find thumb/ -maxdepth 1 -type d ! \( -name 'thumb' -o -name 'v7e-m+fp' -o -name 'v7e-m+dp' \) -exec rm -rf {} + && \
rm cc1plus g++-mapper-server && \
find /usr/bin -maxdepth 1 -type f -name 'arm-none-eabi-*' ! \( -name 'arm-none-eabi-gcc' -o -name 'arm-none-eabi-objcopy' -o -name 'arm-none-eabi-objdump' \) -delete
# keep this last
RUN ldconfig
# Setup RO rootfs
RUN mkdir -p /tmprw
RUN mkdir -p /tmptmp
COPY ./userspace/readonly_setup.sh /tmptmp/readonly_setup.sh
RUN /tmptmp/readonly_setup.sh && rm -rf /tmptmp
# copy at the end, after all apt usage
COPY ./userspace/files/apt.conf /etc/apt/apt.conf
# copy version file
COPY VERSION /VERSION
# ################## #
# #### Cleaunup #### #
# ################## #
RUN rm -rf /usr/share/icons/* && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /home/$USERNAME/.cache && \
rm -rf /root/.cache && \
apt-get clean