diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 81ef2e47..2f836ca6 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -44,9 +44,10 @@ RUN apt-get -q update \ # - Installing blue deps using pip, apt and rosdep # - Installs the remaining blue dependencies from blue_robot.repos # - Installs deps from rosdep for all src dependencies -# - colcon build # -FROM ci AS robot +# robot_unbuilt **does not** colcon build, to save time +# +FROM ci AS robot_unbuilt # # Ubuntu 24.04 "Noble", which is used as the base image for @@ -137,16 +138,19 @@ RUN sudo apt-get -q update \ && sudo apt-get clean -y \ && sudo rm -rf /var/lib/apt/lists/* -# Actually build workspace -RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \ - && colcon build - -RUN echo "source ${USER_WORKSPACE}/install/setup.bash" >> /home/$USERNAME/.bashrc \ +RUN echo "if [ -f ${USER_WORKSPACE}/install/setup.bash ]; then source ${USER_WORKSPACE}/install/setup.bash; fi" >> /home/$USERNAME/.bashrc \ && echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc \ && echo "source $VIRTUAL_ENV/bin/activate" >> /home/$USERNAME/.bashrc \ && echo "\n# Ensure colcon is run in the venv\nalias colcon='python3 -m colcon'" >> /home/$USERNAME/.bashrc -FROM robot AS desktop +# Finally, build +FROM robot_unbuilt AS robot + +# Actually build workspace +RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \ + && colcon build + +FROM robot_unbuilt AS desktop_unbuilt ENV DEBIAN_FRONTEND=noninteractive ENV GZ_VERSION=harmonic @@ -223,12 +227,6 @@ RUN sudo apt-get -q update \ && sudo apt-get clean -y \ && sudo rm -rf /var/lib/apt/lists/* -# For users that build this on a laptop or system with limited RAM, -# Modify the 'colcon build' line to be 'MAKEFLAGS="-j1 -l1" colcon build' -# This will limit the amount of RAM that colcon is allowed to use -RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \ - && colcon build - # Setup the simulation environment variables RUN <> /home/$USERNAME/.bashrc @@ -245,6 +243,40 @@ export GZ_SIM_SYSTEM_PLUGIN_PATH=\$HOME/ardupilot_gazebo/build:\$GZ_SIM_SYSTEM_P export GZ_SIM_RESOURCE_PATH=\$HOME/ardupilot_gazebo/models:\$HOME/ardupilot_gazebo/worlds:\$GZ_SIM_RESOURCE_PATH EOT + +FROM desktop_unbuilt AS desktop + +# For users that build this on a laptop or system with limited RAM, +# Modify the 'colcon build' line to be 'MAKEFLAGS="-j1 -l1" colcon build' +# This will limit the amount of RAM that colcon is allowed to use +RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \ + && colcon build + +# This repetition doesn't exactly sit right ... but I can't quite figure +# out how to make this work without repeating either these instructions or +# the colcon build +FROM desktop_unbuilt AS desktop-nvidia_unbuilt + +# Install NVIDIA software +RUN sudo apt-get update \ + && sudo apt-get -q -y upgrade \ + && sudo apt-get install -y -qq --no-install-recommends \ + libglvnd0 \ + libgl1 \ + libglx0 \ + libegl1 \ + libxext6 \ + libx11-6 \ + && sudo apt-get autoremove -y \ + && sudo apt-get clean -y \ + && sudo rm -rf /var/lib/apt/lists/* + +# Env vars for the nvidia-container-runtime. +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute +ENV QT_X11_NO_MITSHM=1 + + FROM desktop AS desktop-nvidia # Install NVIDIA software diff --git a/.docker/docker-bake.hcl b/.docker/docker-bake.hcl index 6c104206..d35f26d2 100644 --- a/.docker/docker-bake.hcl +++ b/.docker/docker-bake.hcl @@ -58,37 +58,56 @@ target "ci" { platforms = ["linux/amd64", "linux/arm64"] } +target "robot_unbuilt" { + inherits = [ "ci" ] + target = "robot_unbuilt" + tags = [ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot-unbuilt" + ] + +} + target "robot" { - inherits = [ "ci", "docker-metadata-action-robot" ] + inherits = [ "robot_unbuilt", "docker-metadata-action-robot" ] target = "robot" tags = [ "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot" ] - cache_to = [ - "type=local,dest=.docker-cache" +} + +target "desktop_unbuilt" { + inherits = [ "ci" ] + target = "desktop" + tags = [ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-unbuilt" ] + # amd64 only builds for desktop and desktop-nvidia + platforms = ["linux/amd64"] } target "desktop" { - inherits = [ "ci", "docker-metadata-action-desktop" ] + inherits = [ "desktop_unbuilt", "docker-metadata-action-desktop" ] target = "desktop" tags = [ "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop" ] - cache_to = [ - "type=local,dest=.docker-cache" +} + +target "desktop-nvidia_unbuilt" { + inherits = [ "desktop", "docker-metadata-action-desktop-nvidia" ] + target = "desktop-nvidia_unbuilt" + tags = [ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia-unbuilt" ] - # amd64 only builds for desktop and desktop-nvidia - platforms = ["linux/amd64"] + } + target "desktop-nvidia" { inherits = [ "desktop", "docker-metadata-action-desktop-nvidia" ] target = "desktop-nvidia" tags = [ "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia" ] - cache_to = [ - "type=local,dest=.docker-cache" - ] + }