@@ -151,6 +151,16 @@ ENV VIRTUAL_ENV=/home/$USERNAME/.venv/blue
151151RUN python3 -m venv --system-site-packages --symlinks $VIRTUAL_ENV
152152ENV PATH="$VIRTUAL_ENV/bin:$PATH"
153153
154+ # Python in Ubuntu is now marked as a "Externally managed environment",
155+ # Per best practice, create a venv for local python packages
156+ #
157+ # These two ENVs effectively "activate" the venv for subsequent calls to
158+ # python/pip in the Dockerfile
159+ WORKDIR /home/$USERNAME
160+ ENV VIRTUAL_ENV=/home/$USERNAME/.venv/blue
161+ RUN python3 -m venv --system-site-packages --symlinks $VIRTUAL_ENV
162+ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
163+
154164# Install MAVROS dependencies
155165WORKDIR /home/$USERNAME
156166RUN wget https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh \
@@ -183,6 +193,25 @@ RUN sudo apt-get -q update \
183193 && sudo apt-get clean -y \
184194 && sudo rm -rf /var/lib/apt/lists/*
185195
196+ # Manually install MAVROS from source in the ws_blue/ workspace
197+ WORKDIR $USER_WORKSPACE/src/
198+ ARG MAVROS_RELEASE=ros2
199+ ARG MAVLINK_RELEASE=release/rolling/mavlink
200+ RUN git clone --depth 1 -b ${MAVROS_RELEASE} https://github.com/mavlink/mavros.git
201+ RUN git clone --depth 1 --recursive -b ${MAVLINK_RELEASE} https://github.com/mavlink/mavlink-gbp-release.git mavlink
202+ # - mavgen uses future.standard_library for backwards compatibility with Python2;
203+ # However, this caused issues with Python 3.12 installed in "noble".
204+ # Comment those lines out in mavlink.
205+ #
206+ # - Fix linkage for yaml-cpp in mavros_extra_plugins
207+ RUN sed -i -e 's/^from future import standard_library/#from future import standard_library/' \
208+ -e 's/standard_library.install_aliases()/#standard_library.install_aliases()/' \
209+ mavlink/pymavlink/generator/mavgen.py && \
210+ sed -i -e 's/^# find_package(yaml_cpp REQUIRED)/find_package(yaml-cpp REQUIRED)/' \
211+ -e '/^ament_target_dependencies(mavros_extras_plugins$/i target_link_libraries(mavros_extras_plugins yaml-cpp::yaml-cpp)' \
212+ -e '/^ament_target_dependencies(mavros_extras$/i target_link_libraries(mavros_extras yaml-cpp::yaml-cpp)' \
213+ mavros/mavros_extras/CMakeLists.txt
214+
186215WORKDIR $USER_WORKSPACE
187216RUN sudo apt-get -q update \
188217 && sudo apt-get -q -y upgrade \
@@ -199,7 +228,7 @@ RUN sudo apt-get -q update \
199228RUN . "${MAVROS_WORKSPACE}/install/setup.sh" \
200229 && colcon build
201230
202- RUN echo "source ${USER_WORKSPACE }/install/setup.bash" >> /home/$USERNAME/.bashrc \
231+ RUN echo "source ${MAVROS_WORKSPACE }/install/setup.bash" >> /home/$USERNAME/.bashrc \
203232 && echo "source $VIRTUAL_ENV/bin/activate" >> /home/$USERNAME/.bashrc \
204233 && echo "\n # Ensure colcon is run in the venv\n alias colcon='python3 -m colcon'" >> /home/$USERNAME/.bashrc
205234
0 commit comments