@@ -18,6 +18,7 @@ RUN apt-get -q update \
1818 clang-tools \
1919 python3-pip \
2020 python3-dev \
21+ python3-venv \
2122 lsb-release \
2223 wget \
2324 gnupg \
@@ -47,14 +48,14 @@ RUN apt-get -q update \
4748#
4849FROM ci AS robot
4950
50- # Configure a new non-root user
51- ARG USERNAME=blue
51+ #
52+ # Ubuntu 24.04 "Noble", which is used as the base image for
53+ # jazzy and rolling images, now includes a user "ubuntu" at UID 1000
54+ ARG USERNAME=ubuntu
5255ARG USER_UID=1000
5356ARG USER_GID=$USER_UID
5457
55- RUN groupadd --gid $USER_GID $USERNAME \
56- && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
57- && echo $USERNAME ALL=\( root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
58+ RUN echo $USERNAME ALL=\( root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
5859 && chmod 0440 /etc/sudoers.d/$USERNAME \
5960 && usermod -a -G dialout $USERNAME \
6061 && echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc
@@ -65,6 +66,16 @@ ENV DEBIAN_FRONTEND=noninteractive
6566USER $USERNAME
6667ENV USER=$USERNAME
6768
69+ # Python in Ubuntu is now marked as a "Externally managed environment",
70+ # Per best practice, create a venv for local python packages
71+ #
72+ # These two ENVs effectively "activate" the venv for subsequent calls to
73+ # python/pip in the Dockerfile
74+ WORKDIR /home/$USERNAME
75+ ENV VIRTUAL_ENV=/home/$USERNAME/.venv/blue
76+ RUN python3 -m venv --system-site-packages --symlinks $VIRTUAL_ENV
77+ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
78+
6879# Install MAVROS dependencies
6980WORKDIR /home/$USERNAME
7081RUN wget https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh \
@@ -97,6 +108,25 @@ RUN sudo apt-get -q update \
97108 && sudo apt-get clean -y \
98109 && sudo rm -rf /var/lib/apt/lists/*
99110
111+ # Manually install MAVROS from source in the ws_blue/ workspace
112+ WORKDIR $USER_WORKSPACE/src/
113+ ARG MAVROS_RELEASE=ros2
114+ ARG MAVLINK_RELEASE=release/rolling/mavlink
115+ RUN git clone --depth 1 -b ${MAVROS_RELEASE} https://github.com/mavlink/mavros.git
116+ RUN git clone --depth 1 --recursive -b ${MAVLINK_RELEASE} https://github.com/mavlink/mavlink-gbp-release.git mavlink
117+ # - mavgen uses future.standard_library for backwards compatibility with Python2;
118+ # However, this caused issues with Python 3.12 installed in "noble".
119+ # Comment those lines out in mavlink.
120+ #
121+ # - Fix linkage for yaml-cpp in mavros_extra_plugins
122+ RUN sed -i -e 's/^from future import standard_library/#from future import standard_library/' \
123+ -e 's/standard_library.install_aliases()/#standard_library.install_aliases()/' \
124+ mavlink/pymavlink/generator/mavgen.py && \
125+ sed -i -e 's/^# find_package(yaml_cpp REQUIRED)/find_package(yaml-cpp REQUIRED)/' \
126+ -e '/^ament_target_dependencies(mavros_extras_plugins$/i target_link_libraries(mavros_extras_plugins yaml-cpp::yaml-cpp)' \
127+ -e '/^ament_target_dependencies(mavros_extras$/i target_link_libraries(mavros_extras yaml-cpp::yaml-cpp)' \
128+ mavros/mavros_extras/CMakeLists.txt
129+
100130WORKDIR $USER_WORKSPACE
101131RUN sudo apt-get -q update \
102132 && sudo apt-get -q -y upgrade \
@@ -112,48 +142,58 @@ RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \
112142 && colcon build
113143
114144RUN echo "source ${USER_WORKSPACE}/install/setup.bash" >> /home/$USERNAME/.bashrc \
115- && echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc
145+ && echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc \
146+ && echo "source $VIRTUAL_ENV/bin/activate" >> /home/$USERNAME/.bashrc \
147+ && echo "\n # Ensure colcon is run in the venv\n alias colcon='python3 -m colcon'" >> /home/$USERNAME/.bashrc
116148
117149FROM robot AS desktop
118150
119151ENV DEBIAN_FRONTEND=noninteractive
120- ENV GZ_VERSION=garden
121-
122- # Install Gazebo Garden: https://gazebosim.org/docs/garden/install_ubuntu
123- RUN sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg \
124- && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null \
125- && sudo apt-get -q update \
126- && sudo apt-get -y --quiet --no-install-recommends install \
127- gz-garden \
128- && sudo apt-get autoremove -y \
129- && sudo apt-get clean -y \
130- && sudo rm -rf /var/lib/apt/lists/*
131-
132- # Install ArduPilot and ardupilot_gazebo dependencies
133- RUN sudo apt-get -q update \
134- && sudo apt-get -q -y upgrade \
135- && sudo apt-get -q install --no-install-recommends -y \
152+ ENV GZ_VERSION=harmonic
153+
154+ # Install Gazebo Harmonic: https://gazebosim.org/docs/harmonic/install_ubuntu
155+ # Per DL3004, use "USER root" rather than "sudo"
156+ # https://github.com/hadolint/hadolint/wiki/DL3004
157+ USER root
158+ # Install custom rosdep list
159+ ADD --chown=root:root --chmod=0644 https://raw.githubusercontent.com/osrf/osrf-rosdep/master/gz/00-gazebo.list /etc/ros/rosdep/sources.list.d/00-gazebo.list
160+ RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg \
161+ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null \
162+ && apt-get -q update \
163+ && apt-get -y --quiet --no-install-recommends install \
164+ cppzmq-dev \
165+ gz-${GZ_VERSION} \
166+ python3-pexpect \
136167 python3-wxgtk4.0 \
168+ python3-future \
137169 rapidjson-dev \
138170 xterm \
139- libgz-sim7-dev \
140171 rapidjson-dev \
141172 libopencv-dev \
142- && sudo apt-get autoremove -y \
143- && sudo apt-get clean -y \
144- && sudo rm -rf /var/lib/apt/lists/*
173+ && apt-get autoremove -y \
174+ && apt-get clean -y \
175+ && rm -rf /var/lib/apt/lists/*
176+ USER $USERNAME
145177
146178# Clone ArduSub
147179# ArduSub is installed for simulation purposes ONLY
148180# When deployed onto hardware, the native installation of ArduSub
149181# (on the FCU) will be used.
150182WORKDIR /home/$USERNAME
151- RUN git clone https://github.com/ArduPilot/ardupilot.git --recurse-submodules
183+ # Really should do version pinning but Sub-4.5 is waaaay behind master
184+ # (e.g. it doesn't know about "noble" yet)
185+ ARG ARDUPILOT_RELEASE=master
186+ RUN git clone -b ${ARDUPILOT_RELEASE} https://github.com/ArduPilot/ardupilot.git --recurse-submodules
152187
153188# Install ArduSub dependencies
154189WORKDIR /home/$USERNAME/ardupilot
155190ENV SKIP_AP_EXT_ENV=1 SKIP_AP_GRAPHIC_ENV=1 SKIP_AP_COV_ENV=1 SKIP_AP_GIT_CHECK=1
156- RUN Tools/environment_install/install-prereqs-ubuntu.sh -y
191+ # Do not install the STM development tools
192+ ENV DO_AP_STM_ENV=0
193+ # Do not activate the Ardupilot venv by default
194+ ENV DO_PYTHON_VENV_ENV=0
195+ RUN echo "\n # Below from ardupilot script \" install-prereqs-ubuntu.sh\"\n " >> /home/$USERNAME/.bashrc && \
196+ Tools/environment_install/install-prereqs-ubuntu.sh -y
157197
158198# Build ArduSub
159199WORKDIR /home/$USERNAME/ardupilot
0 commit comments