Merge bdfecd5945
into 03e9777c3f
commit
9da4ae8736
13 changed files with 247 additions and 162 deletions
@ -1,12 +0,0 @@ |
||||
FROM ghcr.io/commaai/openpilot-base:latest |
||||
|
||||
ENV PYTHONUNBUFFERED=1 |
||||
|
||||
ENV OPENPILOT_PATH=/home/batman/openpilot |
||||
|
||||
RUN mkdir -p ${OPENPILOT_PATH} |
||||
WORKDIR ${OPENPILOT_PATH} |
||||
|
||||
COPY . ${OPENPILOT_PATH}/ |
||||
|
||||
RUN scons --cache-readonly -j$(nproc) |
@ -1,81 +0,0 @@ |
||||
FROM ubuntu:24.04 |
||||
|
||||
ENV PYTHONUNBUFFERED=1 |
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive |
||||
RUN apt-get update && \ |
||||
apt-get install -y --no-install-recommends sudo tzdata locales ssh pulseaudio xvfb x11-xserver-utils gnome-screenshot python3-tk python3-dev && \ |
||||
rm -rf /var/lib/apt/lists/* |
||||
|
||||
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen |
||||
ENV LANG=en_US.UTF-8 |
||||
ENV LANGUAGE=en_US:en |
||||
ENV LC_ALL=en_US.UTF-8 |
||||
|
||||
COPY tools/install_ubuntu_dependencies.sh /tmp/tools/ |
||||
RUN /tmp/tools/install_ubuntu_dependencies.sh && \ |
||||
rm -rf /var/lib/apt/lists/* /tmp/* && \ |
||||
cd /usr/lib/gcc/arm-none-eabi/* && \ |
||||
rm -rf arm/ thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp |
||||
|
||||
# Add OpenCL |
||||
RUN apt-get update && apt-get install -y --no-install-recommends \ |
||||
apt-utils \ |
||||
alien \ |
||||
unzip \ |
||||
tar \ |
||||
curl \ |
||||
xz-utils \ |
||||
dbus \ |
||||
gcc-arm-none-eabi \ |
||||
tmux \ |
||||
vim \ |
||||
libx11-6 \ |
||||
wget \ |
||||
&& rm -rf /var/lib/apt/lists/* |
||||
|
||||
RUN mkdir -p /tmp/opencl-driver-intel && \ |
||||
cd /tmp/opencl-driver-intel && \ |
||||
wget https://github.com/intel/llvm/releases/download/2024-WW14/oclcpuexp-2024.17.3.0.09_rel.tar.gz && \ |
||||
wget https://github.com/oneapi-src/oneTBB/releases/download/v2021.12.0/oneapi-tbb-2021.12.0-lin.tgz && \ |
||||
mkdir -p /opt/intel/oclcpuexp_2024.17.3.0.09_rel && \ |
||||
cd /opt/intel/oclcpuexp_2024.17.3.0.09_rel && \ |
||||
tar -zxvf /tmp/opencl-driver-intel/oclcpuexp-2024.17.3.0.09_rel.tar.gz && \ |
||||
mkdir -p /etc/OpenCL/vendors && \ |
||||
echo /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64/libintelocl.so > /etc/OpenCL/vendors/intel_expcpu.icd && \ |
||||
cd /opt/intel && \ |
||||
tar -zxvf /tmp/opencl-driver-intel/oneapi-tbb-2021.12.0-lin.tgz && \ |
||||
ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbb.so /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 && \ |
||||
ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbbmalloc.so /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 && \ |
||||
ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbb.so.12 /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 && \ |
||||
ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbbmalloc.so.2 /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 && \ |
||||
mkdir -p /etc/ld.so.conf.d && \ |
||||
echo /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 > /etc/ld.so.conf.d/libintelopenclexp.conf && \ |
||||
ldconfig -f /etc/ld.so.conf.d/libintelopenclexp.conf && \ |
||||
cd / && \ |
||||
rm -rf /tmp/opencl-driver-intel |
||||
|
||||
ENV NVIDIA_VISIBLE_DEVICES=all |
||||
ENV NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute |
||||
ENV QTWEBENGINE_DISABLE_SANDBOX=1 |
||||
|
||||
RUN dbus-uuidgen > /etc/machine-id |
||||
|
||||
ARG USER=batman |
||||
ARG USER_UID=1001 |
||||
RUN useradd -m -s /bin/bash -u $USER_UID $USER |
||||
RUN usermod -aG sudo $USER |
||||
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers |
||||
USER $USER |
||||
|
||||
COPY --chown=$USER pyproject.toml uv.lock /home/$USER |
||||
COPY --chown=$USER tools/install_python_dependencies.sh /home/$USER/tools/ |
||||
|
||||
ENV VIRTUAL_ENV=/home/$USER/.venv |
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
||||
RUN cd /home/$USER && \ |
||||
tools/install_python_dependencies.sh && \ |
||||
rm -rf tools/ pyproject.toml uv.lock .cache |
||||
|
||||
USER root |
||||
RUN sudo git config --global --add safe.directory /tmp/openpilot |
@ -0,0 +1,104 @@ |
||||
#!/usr/bin/env bash |
||||
set -e |
||||
ORG_PWD="$PWD" |
||||
SELF_PATH="$(realpath $0)" |
||||
SCRIPT_DIR="$(dirname "$SELF_PATH")" |
||||
|
||||
REPO="$HOME/work/openpilot/openpilot" |
||||
CACHE_ROOTFS_TARBALL_PATH="/tmp/rootfs_cache.tar" |
||||
|
||||
source "$SCRIPT_DIR/build_common.sh" |
||||
|
||||
# if the rootfs diff tarball (also created by this script) got restored from the CI native cache |
||||
if [ -f "$CACHE_ROOTFS_TARBALL_PATH" ] |
||||
then |
||||
# apply it, upgrading the rootfs |
||||
echo "restoring rootfs from the native build cache" |
||||
apply_rootfs_diff |
||||
rm "$CACHE_ROOTFS_TARBALL_PATH" |
||||
|
||||
# before the next tasks are run, finalize the environment for them |
||||
prepare_build |
||||
|
||||
# EXITS HERE - if the rootfs could been prepared entirely from the cache, there's no need for any further action like re-building |
||||
exit 0 |
||||
else |
||||
# otherwise, we'll have to install everything from scratch and build the tarball to be available for the next run |
||||
if ! [ -f /root_committed ] |
||||
then |
||||
echo "no native build cache entry restored, rebuilding" |
||||
fi |
||||
fi |
||||
|
||||
# in order to be able to build a diff rootfs tarball, we need to commit its initial state |
||||
# by moving it on-the-fly to overlayfs; below, we prepare the system and the new rootfs itself |
||||
commit_root |
||||
|
||||
# -------- at this point, the original rootfs was committed and all the changes to it done below will be saved to the newly created rootfs diff tarball -------- |
||||
|
||||
# install and set up the native dependencies needed |
||||
PYTHONUNBUFFERED=1 |
||||
DEBIAN_FRONTEND=noninteractive |
||||
|
||||
mkdir -p /tmp/tools |
||||
cp "$REPO/tools/install_ubuntu_dependencies.sh" /tmp/tools/ |
||||
sudo /tmp/tools/install_ubuntu_dependencies.sh |
||||
|
||||
sudo apt-get install -y --no-install-recommends \ |
||||
sudo tzdata locales ssh pulseaudio xvfb x11-xserver-utils gnome-screenshot python3-tk python3-dev \ |
||||
apt-utils alien unzip tar curl xz-utils dbus gcc-arm-none-eabi tmux vim libx11-6 wget |
||||
|
||||
sudo rm -rf /var/lib/apt/lists/* |
||||
sudo apt-get clean |
||||
|
||||
cd /usr/lib/gcc/arm-none-eabi/* |
||||
sudo rm -rf arm/ thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp |
||||
cd |
||||
|
||||
sudo sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen |
||||
sudo locale-gen |
||||
LANG=en_US.UTF-8 |
||||
LANGUAGE=en_US:en |
||||
LC_ALL=en_US.UTF-8 |
||||
|
||||
mkdir -p /tmp/opencl-driver-intel |
||||
cd /tmp/opencl-driver-intel |
||||
wget https://github.com/intel/llvm/releases/download/2024-WW14/oclcpuexp-2024.17.3.0.09_rel.tar.gz &>/dev/null |
||||
wget https://github.com/oneapi-src/oneTBB/releases/download/v2021.12.0/oneapi-tbb-2021.12.0-lin.tgz &>/dev/null |
||||
sudo mkdir -p /opt/intel/oclcpuexp_2024.17.3.0.09_rel |
||||
cd /opt/intel/oclcpuexp_2024.17.3.0.09_rel |
||||
sudo tar -zxvf /tmp/opencl-driver-intel/oclcpuexp-2024.17.3.0.09_rel.tar.gz |
||||
sudo mkdir -p /etc/OpenCL/vendors |
||||
sudo bash -c "echo /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64/libintelocl.so > /etc/OpenCL/vendors/intel_expcpu.icd" |
||||
cd /opt/intel |
||||
sudo tar -zxvf /tmp/opencl-driver-intel/oneapi-tbb-2021.12.0-lin.tgz |
||||
sudo ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbb.so /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 |
||||
sudo ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbbmalloc.so /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 |
||||
sudo ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbb.so.12 /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 |
||||
sudo ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbbmalloc.so.2 /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 |
||||
sudo mkdir -p /etc/ld.so.conf.d |
||||
sudo bash -c "echo /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 > /etc/ld.so.conf.d/libintelopenclexp.conf" |
||||
sudo ldconfig -f /etc/ld.so.conf.d/libintelopenclexp.conf |
||||
rm -rf /tmp/opencl-driver-intel |
||||
cd |
||||
|
||||
sudo bash -c "dbus-uuidgen > /etc/machine-id" |
||||
|
||||
NVIDIA_VISIBLE_DEVICES=all |
||||
NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute |
||||
QTWEBENGINE_DISABLE_SANDBOX=1 |
||||
|
||||
# install and set up the Python dependencies needed |
||||
cp "$REPO/pyproject.toml" "$REPO/uv.lock" "$HOME/" |
||||
mkdir "$HOME/tools" |
||||
cp "$REPO/tools/install_python_dependencies.sh" "$HOME/tools/" |
||||
|
||||
VIRTUAL_ENV=/home/$USER/.venv |
||||
PATH="$VIRTUAL_ENV/bin:$PATH" |
||||
|
||||
cd |
||||
tools/install_python_dependencies.sh |
||||
rm -rf tools/ pyproject.toml uv.lock .cache |
||||
|
||||
# add a git safe directory for compiling openpilot |
||||
sudo git config --global --add safe.directory /tmp/openpilot |
@ -0,0 +1,113 @@ |
||||
error_handler() { |
||||
echo failed at ${BASH_LINENO[0]} |
||||
} |
||||
trap error_handler ERR |
||||
|
||||
create_rootfs_diff() { |
||||
sudo rm -f "$CACHE_ROOTFS_TARBALL_PATH" # remove the old diff tarball from previous run, if exists |
||||
cd /upper |
||||
sudo tar -cf "$CACHE_ROOTFS_TARBALL_PATH" . |
||||
cd |
||||
} |
||||
|
||||
apply_rootfs_diff() { |
||||
cd / |
||||
sudo tar -xf "$CACHE_ROOTFS_TARBALL_PATH" 2>/dev/null || true |
||||
cd |
||||
} |
||||
|
||||
prepare_build() { |
||||
# create and mount the required volumes where they're expected |
||||
mkdir -p /tmp/openpilot /tmp/scons_cache /tmp/comma_download_cache /tmp/openpilot_cache |
||||
sudo mount --bind "$REPO" /tmp/openpilot |
||||
|
||||
sudo mount --bind "$REPO/.ci_cache/scons_cache" /tmp/scons_cache || true |
||||
sudo mount --bind "$REPO/.ci_cache/comma_download_cache" /tmp/comma_download_cache || true |
||||
sudo mount --bind "$REPO/.ci_cache/openpilot_cache" /tmp/openpilot_cache || true |
||||
|
||||
# needed for the unit tests not to fail |
||||
sudo chmod 755 /sys/fs/pstore |
||||
} |
||||
|
||||
post_commit_root() { |
||||
# we have the diff tarball, now let's remove the folder too |
||||
sudo rm -rf /upper |
||||
|
||||
# now we apply it straight away |
||||
apply_rootfs_diff |
||||
|
||||
# before the next tasks are run, finalize the environment for them |
||||
prepare_build |
||||
} |
||||
|
||||
# warning: this function initiates a somewhat complicated program flow, follow carefully |
||||
# (even despite this part was made sure to not be too relevant for the rest of the job) |
||||
commit_root() { |
||||
# if that's a first execution |
||||
if ! [ -e /root_committed ] |
||||
then |
||||
# prepare directories |
||||
sudo mkdir -p /base /newroot /upper /work |
||||
|
||||
# re-execute the main script (causing it to go straight to `build_inside_namespace`), but |
||||
# inside the newly created namespace, in a way which would cause all mounts |
||||
# created to automatically umount before it exits |
||||
sudo unshare -f --kill-child -m "$SELF_PATH" build_inside_namespace |
||||
ec=$? |
||||
|
||||
# after it exited, remove the created directories (except the one containing created diff) |
||||
sudo rm -rf /base /newroot /work |
||||
|
||||
# finally, create the rootfs diff tarball (to be pushed into the CI native cache) |
||||
create_rootfs_diff |
||||
|
||||
# after creating the rootfs diff, bring the system into a state as if it was restored from cache |
||||
post_commit_root |
||||
|
||||
exit $ec |
||||
fi |
||||
} |
||||
|
||||
reexecute() { |
||||
touch /root_committed |
||||
sudo -u runner "$SELF_PATH" |
||||
ec=$? |
||||
exit $ec |
||||
} |
||||
|
||||
# that's where the script goes after being re-executed for the first time |
||||
build_inside_namespace() { |
||||
# initialize the mounts namespace on overlayfs to be able to prepare the rootfs diff |
||||
mount --bind / /base |
||||
mount -t overlay overlay -o lowerdir=/base,upperdir=/upper,workdir=/work /newroot |
||||
|
||||
# apply the current DNS config (beware: systemd often symlinks /etc/resolv.conf, that's why it's needed) |
||||
rm -f /newroot/etc/resolv.conf |
||||
touch /newroot/etc/resolv.conf |
||||
cat /etc/resolv.conf > /newroot/etc/resolv.conf |
||||
|
||||
# switch the namespace's root mount to the newly created one |
||||
mkdir -p /newroot/old |
||||
cd /newroot |
||||
pivot_root . old |
||||
|
||||
# initialize basic required POSIX-standard additional mounts |
||||
mount -t proc proc /proc |
||||
mount -t devtmpfs devtmpfs /dev |
||||
mkdir -p /dev/pts |
||||
mount -t devpts devpts /dev/pts |
||||
mount -t proc proc /proc |
||||
mount -t sysfs sysfs /sys |
||||
|
||||
# re-execute the main script for the 2nd time, causing it to go back to the main flow |
||||
# (but this time already inside the newly created namespace) |
||||
reexecute |
||||
|
||||
# after the main flow terminates and the namespace exist, post_commit_root is executed - be sure to look at it |
||||
} |
||||
|
||||
if [ "$1" = "build_inside_namespace" ] |
||||
then |
||||
build_inside_namespace |
||||
exit |
||||
fi |
@ -1,26 +0,0 @@ |
||||
#!/usr/bin/env bash |
||||
set -e |
||||
|
||||
# To build sim and docs, you can run the following to mount the scons cache to the same place as in CI: |
||||
# mkdir -p .ci_cache/scons_cache |
||||
# sudo mount --bind /tmp/scons_cache/ .ci_cache/scons_cache |
||||
|
||||
SCRIPT_DIR=$(dirname "$0") |
||||
OPENPILOT_DIR=$SCRIPT_DIR/../../ |
||||
if [ -n "$TARGET_ARCHITECTURE" ]; then |
||||
PLATFORM="linux/$TARGET_ARCHITECTURE" |
||||
TAG_SUFFIX="-$TARGET_ARCHITECTURE" |
||||
else |
||||
PLATFORM="linux/$(uname -m)" |
||||
TAG_SUFFIX="" |
||||
fi |
||||
|
||||
source $SCRIPT_DIR/docker_common.sh $1 "$TAG_SUFFIX" |
||||
|
||||
DOCKER_BUILDKIT=1 docker buildx build --provenance false --pull --platform $PLATFORM --load --cache-to type=inline --cache-from type=registry,ref=$REMOTE_TAG -t $DOCKER_IMAGE:latest -t $REMOTE_TAG -t $LOCAL_TAG -f $OPENPILOT_DIR/$DOCKER_FILE $OPENPILOT_DIR |
||||
|
||||
if [ -n "$PUSH_IMAGE" ]; then |
||||
docker push $REMOTE_TAG |
||||
docker tag $REMOTE_TAG $REMOTE_SHA_TAG |
||||
docker push $REMOTE_SHA_TAG |
||||
fi |
@ -1,18 +0,0 @@ |
||||
if [ "$1" = "base" ]; then |
||||
export DOCKER_IMAGE=openpilot-base |
||||
export DOCKER_FILE=Dockerfile.openpilot_base |
||||
elif [ "$1" = "prebuilt" ]; then |
||||
export DOCKER_IMAGE=openpilot-prebuilt |
||||
export DOCKER_FILE=Dockerfile.openpilot |
||||
else |
||||
echo "Invalid docker build image: '$1'" |
||||
exit 1 |
||||
fi |
||||
|
||||
export DOCKER_REGISTRY=ghcr.io/commaai |
||||
export COMMIT_SHA=$(git rev-parse HEAD) |
||||
|
||||
TAG_SUFFIX=$2 |
||||
LOCAL_TAG=$DOCKER_IMAGE$TAG_SUFFIX |
||||
REMOTE_TAG=$DOCKER_REGISTRY/$LOCAL_TAG |
||||
REMOTE_SHA_TAG=$DOCKER_REGISTRY/$LOCAL_TAG:$COMMIT_SHA |
Loading…
Reference in new issue