mirror of
https://github.com/commaai/agnos-builder.git
synced 2026-10-27 00:23:47 +08:00
231 lines
8.8 KiB
Docker
231 lines
8.8 KiB
Docker
# check=error=true
|
|
|
|
# ################## #
|
|
# ### Package ##### #
|
|
# ### Compilation ## #
|
|
# ################## #
|
|
FROM ubuntu:24.04 AS agnos-compiler
|
|
|
|
RUN apt-get update && apt-get install -yq --no-install-recommends build-essential
|
|
|
|
# ADB daemon using the Android libraries already installed for Ubuntu's adb client.
|
|
FROM agnos-compiler AS agnos-compiler-adbd
|
|
RUN apt-get update && apt-get install -yq --no-install-recommends \
|
|
ca-certificates curl clang android-libbase-dev android-libcutils-dev android-liblog-dev \
|
|
android-libboringssl-dev libbrotli-dev libcap-dev liblz4-dev libprotobuf-dev protobuf-compiler \
|
|
libsystemd-dev libzstd-dev
|
|
COPY ./userspace/build_adbd.sh ./userspace/adbd-linux.patch /tmp/agnos/
|
|
RUN /tmp/agnos/build_adbd.sh
|
|
|
|
# Qualcomm graphics without Wayland or OpenCL runtime dependencies
|
|
FROM agnos-compiler AS agnos-compiler-graphics
|
|
RUN apt-get update && apt-get install -yq --no-install-recommends patchelf
|
|
COPY ./userspace/graphics/ /tmp/agnos/graphics-src/
|
|
RUN mkdir -p /tmp/agnos/graphics && \
|
|
cp /tmp/agnos/graphics-src/libgbm.so /tmp/agnos/graphics/ && \
|
|
cp /tmp/agnos/graphics-src/libeglSubDriverWayland.so.patched /tmp/agnos/graphics/libeglSubDriverWayland.so && \
|
|
cd /tmp/agnos/graphics && \
|
|
gcc -shared -fPIC -Os -s -Wall -Wextra -Werror -Wl,-z,defs -Wl,-z,relro,-z,now \
|
|
-Wl,-soname,libagnos-wayland-stubs.so -o libagnos-wayland-stubs.so /tmp/agnos/graphics-src/stubs.c && \
|
|
gcc -shared -fPIC -Os -s -Wall -Wextra -Werror -Wl,-z,defs -Wl,-z,relro,-z,now \
|
|
-Wl,-soname,libCB.so -o libCB.so /tmp/agnos/graphics-src/opencl_stubs.c && \
|
|
nm -D --defined-only libagnos-wayland-stubs.so | \
|
|
awk '$3 ~ /^agnos_/ { name = $3; sub(/^agnos_/, "", name); print name, $3 }' > /tmp/agnos/graphics-symbols.map && \
|
|
for lib in libgbm.so libeglSubDriverWayland.so; do \
|
|
patchelf --rename-dynamic-symbols /tmp/agnos/graphics-symbols.map \
|
|
--remove-needed libwayland-client.so.0 --remove-needed libwayland-server.so.0 \
|
|
--remove-needed libwayland-egl.so.1 --remove-needed libffi.so.6 \
|
|
--remove-needed libpcre.so.1 \
|
|
--add-needed libagnos-wayland-stubs.so "$lib" || exit 1; \
|
|
done
|
|
|
|
# ################## #
|
|
# ###### Base ###### #
|
|
# ################## #
|
|
FROM scratch AS agnos-base
|
|
|
|
ENV CC=clang CXX=clang++
|
|
|
|
# Add Ubuntu Base image files
|
|
ARG UBUNTU_BASE_IMAGE
|
|
ADD ${UBUNTU_BASE_IMAGE} /
|
|
|
|
# Build folder
|
|
RUN mkdir -p /tmp/agnos
|
|
|
|
ARG USERNAME=comma
|
|
|
|
# Base system setup
|
|
RUN echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections
|
|
COPY ./userspace/base_setup.sh ./userspace/openpilot_dependencies.sh /tmp/agnos/
|
|
RUN /tmp/agnos/base_setup.sh
|
|
|
|
# Install openpilot Python dependencies
|
|
COPY ./userspace/openpilot_python_dependencies.sh /tmp/agnos/
|
|
RUN /tmp/agnos/openpilot_python_dependencies.sh
|
|
|
|
# ################### #
|
|
# ###### AGNOS ###### #
|
|
# ################### #
|
|
FROM agnos-base AS agnos
|
|
|
|
COPY --from=agnos-compiler-adbd /tmp/agnos/adbd /usr/comma/adbd
|
|
COPY --from=agnos-compiler-adbd /tmp/adbd-build/packages/modules/adb/NOTICE /usr/share/doc/adbd/NOTICE
|
|
COPY --from=agnos-compiler-graphics /tmp/agnos/graphics/ /usr/lib/aarch64-linux-gnu/
|
|
|
|
# modem.service runs the packaged modem.py (AT + IPv4 PPP).
|
|
# NetworkManager still requires libmm-glib0 for Wi-Fi/Ethernet operation.
|
|
RUN apt-get update && \
|
|
apt-get install -yq --no-install-recommends \
|
|
python3 \
|
|
python3-dev \
|
|
libglib2.0-dev \
|
|
libc6 \
|
|
libglib2.0-0t64 \
|
|
libgudev-1.0-0 \
|
|
libmm-glib0 \
|
|
libpolkit-gobject-1-0 \
|
|
libsystemd0 \
|
|
android-liblog \
|
|
libjson-c5 \
|
|
patchelf \
|
|
polkitd && \
|
|
test ! -e /lib/systemd/system/ModemManager.service
|
|
|
|
ARG XDG_DATA_HOME="/usr/local"
|
|
|
|
# Install openpilot python packages
|
|
COPY ./userspace/uv /tmp/agnos/uv
|
|
RUN source $XDG_DATA_HOME/venv/bin/activate && \
|
|
cd /tmp/agnos/uv && \
|
|
MAKEFLAGS="-j$(nproc)" UV_NO_CACHE=1 UV_PROJECT_ENVIRONMENT=$XDG_DATA_HOME/venv uv sync --frozen --inexact --compile-bytecode \
|
|
--no-install-package msgq \
|
|
--no-install-package opendbc \
|
|
--no-install-package pandacan \
|
|
--no-install-package rednose \
|
|
--no-install-package teleoprtc \
|
|
--no-install-package tinygrad
|
|
|
|
# Install nice to haves
|
|
COPY ./userspace/install_extras.sh /tmp/agnos/
|
|
RUN /tmp/agnos/install_extras.sh
|
|
RUN /usr/comma/adbd --version
|
|
|
|
# Root filesystem overlay, all files at their final paths.
|
|
# tar keeps the ownership and permissions of existing directories, COPY resets them.
|
|
# --mode=go-w makes the result independent of the umask of the checkout.
|
|
RUN rm -r /etc/update-motd.d/*
|
|
RUN --mount=type=bind,source=userspace/root,target=/tmp/agnos/root \
|
|
set -o pipefail && \
|
|
tar -C /tmp/agnos/root --owner=0 --group=0 --mode=go-w -cf - . | tar -C / --no-overwrite-dir -xf -
|
|
COPY ./userspace/root/home/$USERNAME/.config/ /root/.config
|
|
|
|
# These vendor libraries retain unused PCRE dependencies from their original GLib build.
|
|
RUN cd /usr/lib/aarch64-linux-gnu && \
|
|
for lib in libdiag.so.1 libconfigdb.so.0 libqmi_cci.so.1 libxml.so.0 libqmi_client_qmux.so.1 libdsutils.so.1; do \
|
|
patchelf --remove-needed libpcre.so.1 "$lib" || exit 1; \
|
|
done && \
|
|
patchelf --replace-needed libjson-c.so.2 libjson-c.so.5 /usr/bin/pdmappersvc && \
|
|
apt-get purge -y patchelf
|
|
|
|
RUN chown -R $USERNAME: /home/$USERNAME
|
|
RUN touch -r /lib/systemd/systemd /etc/fstab
|
|
|
|
COPY ./output/linux-headers/include/ /usr/include/
|
|
|
|
COPY ./userspace/irsc_util.c /tmp/agnos/
|
|
RUN clang -O2 -Wall -Wextra -Werror -o /usr/bin/irsc_util /tmp/agnos/irsc_util.c && rm /tmp/agnos/irsc_util.c
|
|
|
|
COPY ./userspace/power_burn/power_burn_max.c /tmp/agnos/
|
|
RUN clang -O2 -o /home/$USERNAME/power_burn_max /tmp/agnos/power_burn_max.c \
|
|
-lpthread && rm /tmp/agnos/power_burn_max.c \
|
|
&& chown $USERNAME: /home/$USERNAME/power_burn_max
|
|
|
|
# Setup systemd services
|
|
COPY ./userspace/services.sh /tmp/agnos
|
|
RUN /tmp/agnos/services.sh
|
|
|
|
# Prefer ipv4 over ipv6
|
|
RUN echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf
|
|
|
|
# Block incoming cellular traffic, including modem.py's PPP interface.
|
|
# The SDM845 kernel supports xtables, not Ubuntu's default nftables backend.
|
|
RUN update-alternatives --set iptables /usr/sbin/iptables-legacy && \
|
|
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
|
|
|
|
# Setup hostname resolution for our custom hostname
|
|
RUN sed -i 's/hosts: files dns myhostname/hosts: files myhostname dns/g' /etc/nsswitch.conf
|
|
|
|
COPY ./userspace/trim.sh /tmp/agnos/
|
|
RUN /tmp/agnos/trim.sh
|
|
|
|
# keep this last
|
|
RUN ldconfig
|
|
# ldconfig rewrites these SONAME links back to Mesa; raylib COMMA needs Adreno.
|
|
RUN cd /usr/lib/aarch64-linux-gnu && \
|
|
test -f libEGL_adreno.so && \
|
|
test -f libGLESv2_adreno.so && \
|
|
install -m 755 libgbm.so /tmp/libgbm_adreno.so && \
|
|
ln -sf libEGL_adreno.so libEGL.so.1 && \
|
|
ln -sf libGLESv2_adreno.so libGLESv2.so.2 && \
|
|
rm -f libgbm.so.1 && \
|
|
mv /tmp/libgbm_adreno.so libgbm.so.1
|
|
|
|
# Setup RO rootfs
|
|
RUN mkdir -p /rwtmp
|
|
RUN mkdir -p /tmptmp
|
|
COPY ./userspace/readonly_setup.sh /tmptmp/readonly_setup.sh
|
|
RUN /tmptmp/readonly_setup.sh && rm -rf /tmptmp
|
|
|
|
# copy version file
|
|
COPY VERSION /VERSION
|
|
|
|
# ################# #
|
|
# #### Cleanup #### #
|
|
# ################# #
|
|
|
|
RUN rm -rf /usr/share/icons/* && \
|
|
rm -rf /var/lib/apt/lists/* && \
|
|
rm -rf /home/$USERNAME/.cache && \
|
|
rm -rf /root/.cache && \
|
|
apt-get clean
|
|
|
|
# ################## #
|
|
# ##### Image ###### #
|
|
# ################## #
|
|
# Build the system image in BuildKit, so only the sparse image leaves the builder.
|
|
FROM --platform=$BUILDPLATFORM ubuntu:20.04 AS agnos-image-tools
|
|
RUN apt-get update && \
|
|
apt-get install -yq --no-install-recommends \
|
|
android-sdk-libsparse-utils \
|
|
e2fsprogs \
|
|
libcap2-bin \
|
|
zstd \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
FROM agnos-image-tools AS agnos-image-build
|
|
# the partition is 10G, but openpilot's updater didn't always handle the full size
|
|
# openpilot fix, shipped in 0.9.8 (8/18/24): https://github.com/commaai/openpilot/pull/33320
|
|
# Package-install helpers expand the read-only rootfs before writing.
|
|
ARG ROOTFS_IMAGE_SIZE=2048M
|
|
ARG GIT_HASH
|
|
ARG BUILD_DATETIME
|
|
# Compress the image for remote builders, where the download is the bottleneck
|
|
ARG ZSTD
|
|
# These files are bind mounted in containers, so they can only be set here.
|
|
RUN --mount=type=bind,from=agnos,target=/rootfs,rw \
|
|
cd /rootfs && \
|
|
ln -sf /proc/sys/kernel/hostname etc/hostname && \
|
|
printf "127.0.0.1 localhost.localdomain localhost\n127.0.0.1 comma\n" > etc/hosts && \
|
|
ln -sf /run/systemd/resolve/stub-resolv.conf etc/resolv.conf && \
|
|
setcap cap_net_raw+ep bin/ping && \
|
|
printf "%s\n%s\n" "$GIT_HASH" "$BUILD_DATETIME" > BUILD && \
|
|
mkdir /out && \
|
|
mkfs.ext4 -q -d /rootfs /tmp/system.img $ROOTFS_IMAGE_SIZE && \
|
|
img2simg /tmp/system.img /out/system.img && \
|
|
rm /tmp/system.img && \
|
|
if [ -n "$ZSTD" ]; then zstd -q -T0 -9 --rm /out/system.img; fi
|
|
|
|
FROM scratch AS agnos-image
|
|
COPY --from=agnos-image-build /out/ /
|