Files
agnos-builder/Dockerfile.agnos
T

182 lines
6.1 KiB
Docker

# 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"
# 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 \
--add-needed libagnos-wayland-stubs.so "$lib" || exit 1; \
done
# ################## #
# ###### 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/debs /tmp/agnos/debs
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
COPY --from=agnos-compiler-graphics /tmp/agnos/graphics/ /usr/lib/aarch64-linux-gnu/
RUN mv /data/persist /system/ && rm -rf /data/*
# 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 \
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
# Root filesystem overlay, all files at their final paths.
# tar keeps the ownership and permissions of existing directories, COPY resets them.
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 -cf - . | tar -C / --no-overwrite-dir -xf -
COPY ./userspace/root/home/$USERNAME/.config/ /root/.config
RUN chown -R $USERNAME: /home/$USERNAME/.config
RUN chmod 644 /etc/logrotate.conf
RUN touch -r /lib/systemd/systemd /etc/fstab
COPY ./output/linux-headers/include/ /usr/include/
COPY ./userspace/irsc_util.c /tmp/agnos/
RUN gcc -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 gcc -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
# Setup hostname resolution for our custom hostname
RUN sed -i 's/hosts: files dns myhostname/hosts: files myhostname dns/g' /etc/nsswitch.conf
# 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
COPY ./userspace/trim.sh /tmp/agnos/
RUN /tmp/agnos/trim.sh
# 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