-
Notifications
You must be signed in to change notification settings - Fork 17
Mavros in its own build stage #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amarburg
wants to merge
6
commits into
Robotic-Decision-Making-Lab:main
Choose a base branch
from
apl-ocean-engineering:dev/mavros_in_build_stage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3fb8fbf
Allow pushing to apl-ocean-engineering
amarburg d252397
Install cppzmq-dev for Gazebo
amarburg 404b5ef
Reverse change in docker.yaml action.
amarburg d7dae25
Moved Mavros build to a build stage, which hopefully will get cached.
amarburg ae3c175
Minor update of comment in docker-bake.hcl
amarburg 666bdd6
Use ros2-gbp/ repo for mavlink.
amarburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,102 @@ | ||
ARG ROS_DISTRO=rolling | ||
FROM ros:$ROS_DISTRO-ros-base AS ci | ||
FROM ros:$ROS_DISTRO-ros-base AS base | ||
|
||
# Create the non-root user early because both "mavros" and "robot" | ||
# stages depend its existence | ||
RUN apt-get -q update \ | ||
&& apt-get -q -y upgrade \ | ||
&& apt-get -q install --no-install-recommends -y \ | ||
git \ | ||
gosu \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to leaving gosu in here if we split this into its own temporary Dockerfile, but if we add it to the original, we should consider a separate PR (or just add it with #226) |
||
sudo \ | ||
&& apt-get autoremove -y \ | ||
&& apt-get clean -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Ubuntu 24.04 "Noble", which is used as the base image for | ||
# jazzy and rolling images, now includes a user "ubuntu" at UID 1000 | ||
ARG USERNAME=ubuntu | ||
ARG USER_UID=1000 | ||
ARG USER_GID=$USER_UID | ||
|
||
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ | ||
&& chmod 0440 /etc/sudoers.d/$USERNAME \ | ||
&& usermod -a -G dialout $USERNAME \ | ||
&& echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
ENV USER=$USERNAME | ||
|
||
# This needs to be defined in a shared stage so it's available in both "mavros" and "robot" | ||
ENV MAVROS_WORKSPACE=/home/$USERNAME/ws_mavros | ||
|
||
#== Build Mavros/Mavlink from source in its own workspace. | ||
# Extend that workspace into the "blue" workspace | ||
# | ||
FROM base AS mavros | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
USER $USERNAME | ||
|
||
WORKDIR $MAVROS_WORKSPACE/src | ||
|
||
# As a reminder to self. git clone by itself will not break cache | ||
# when the repo changes. To rebuild mavros from the latest, you | ||
# must "docker build --no-cache" to force a rebuild | ||
ARG MAVROS_RELEASE=ros2 | ||
ARG MAVLINK_RELEASE=release/rolling/mavlink | ||
RUN git clone --depth 1 -b ${MAVROS_RELEASE} https://github.com/mavlink/mavros.git | ||
RUN git clone --depth 1 --recursive -b ${MAVLINK_RELEASE} https://github.com/ros2-gbp/mavlink-gbp-release.git mavlink | ||
# Fix two issues currently in mavros/ros2 | ||
# - mavgen uses future.standard_library for backwards compatibility with Python2; | ||
# However, this caused issues with Python 3.12 installed in "noble". | ||
# Comment those lines out in mavlink. | ||
# | ||
# - Fix linkage for yaml-cpp in mavros_extra_plugins | ||
RUN sed -i -e 's/^from future import standard_library/#from future import standard_library/' \ | ||
-e 's/standard_library.install_aliases()/#standard_library.install_aliases()/' \ | ||
mavlink/pymavlink/generator/mavgen.py && \ | ||
sed -i -e 's/^# find_package(yaml_cpp REQUIRED)/find_package(yaml-cpp REQUIRED)/' \ | ||
-e '/^ament_target_dependencies(mavros_extras_plugins$/i target_link_libraries(mavros_extras_plugins yaml-cpp::yaml-cpp)' \ | ||
-e '/^ament_target_dependencies(mavros_extras$/i target_link_libraries(mavros_extras yaml-cpp::yaml-cpp)' \ | ||
mavros/mavros_extras/CMakeLists.txt | ||
|
||
WORKDIR $MAVROS_WORKSPACE | ||
USER root | ||
RUN apt-get -q update \ | ||
&& apt-get -q -y upgrade \ | ||
&& gosu $USERNAME rosdep update \ | ||
&& gosu $USERNAME rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} \ | ||
&& apt-get autoremove -y \ | ||
&& apt-get clean -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
USER $USERNAME | ||
|
||
# Build Mavros workspace | ||
RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \ | ||
&& colcon build \ | ||
&& rm -rf $MAVROS_WORKSPACE/build | ||
|
||
# == "Standard" Blue Docker image proceeds from here | ||
# | ||
FROM base AS ci | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
USER root | ||
|
||
WORKDIR /root/ws_blue | ||
COPY . src/blue | ||
|
||
# Install apt packages needed for CI | ||
# | ||
# Explicitly uninstall and block mavros and mavlink packages from APT | ||
# this will trigger an error if rosdep attempts to install mavros | ||
# from APT rather than using the version in $MAVROS_WORKSPACE | ||
RUN apt-get -q update \ | ||
&& apt-get -q -y upgrade \ | ||
&& apt-get remove -y "*mavros*" "*mavlink*" \ | ||
&& apt-mark hold "*mavros*" "*mavlink*" \ | ||
&& apt-get -q install --no-install-recommends -y \ | ||
git \ | ||
sudo \ | ||
clang \ | ||
clang-format-14 \ | ||
clang-tidy \ | ||
|
@@ -27,12 +112,17 @@ RUN apt-get -q update \ | |
&& apt-get clean -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install all ROS dependencies for _just_ blue | ||
# (we have not imported other repos from .repos files) | ||
# As it's a dependency for blue, copy Mavros from its build stage | ||
COPY --from=mavros --chown=$USERNAME:$USERNAME $MAVROS_WORKSPACE $MAVROS_WORKSPACE | ||
|
||
# Install all ROS dependencies for _just_ blue (and mavros) | ||
# (we have not imported the other repos from blue.repos files) | ||
RUN apt-get -q update \ | ||
&& apt-get -q -y upgrade \ | ||
&& rosdep update \ | ||
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} --as-root=apt:false \ | ||
&& . "${MAVROS_WORKSPACE}/install/setup.sh" \ | ||
&& rosdep install -y --from-paths ${MAVROS_WORKSPACE}/src --ignore-src --rosdistro ${ROS_DISTRO} \ | ||
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} \ | ||
&& rm -rf src \ | ||
&& apt-get autoremove -y \ | ||
&& apt-get clean -y \ | ||
|
@@ -48,23 +138,8 @@ RUN apt-get -q update \ | |
# | ||
FROM ci AS robot | ||
|
||
# | ||
# Ubuntu 24.04 "Noble", which is used as the base image for | ||
# jazzy and rolling images, now includes a user "ubuntu" at UID 1000 | ||
ARG USERNAME=ubuntu | ||
ARG USER_UID=1000 | ||
ARG USER_GID=$USER_UID | ||
|
||
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ | ||
&& chmod 0440 /etc/sudoers.d/$USERNAME \ | ||
&& usermod -a -G dialout $USERNAME \ | ||
&& echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# Switch to the non-root user for the rest of the installation | ||
USER $USERNAME | ||
ENV USER=$USERNAME | ||
|
||
# Python in Ubuntu is now marked as a "Externally managed environment", | ||
# Per best practice, create a venv for local python packages | ||
|
@@ -108,41 +183,23 @@ RUN sudo apt-get -q update \ | |
&& sudo apt-get clean -y \ | ||
&& sudo rm -rf /var/lib/apt/lists/* | ||
|
||
# Manually install MAVROS from source in the ws_blue/ workspace | ||
WORKDIR $USER_WORKSPACE/src/ | ||
ARG MAVROS_RELEASE=ros2 | ||
ARG MAVLINK_RELEASE=release/rolling/mavlink | ||
RUN git clone --depth 1 -b ${MAVROS_RELEASE} https://github.com/mavlink/mavros.git | ||
RUN git clone --depth 1 --recursive -b ${MAVLINK_RELEASE} https://github.com/mavlink/mavlink-gbp-release.git mavlink | ||
# - mavgen uses future.standard_library for backwards compatibility with Python2; | ||
# However, this caused issues with Python 3.12 installed in "noble". | ||
# Comment those lines out in mavlink. | ||
# | ||
# - Fix linkage for yaml-cpp in mavros_extra_plugins | ||
RUN sed -i -e 's/^from future import standard_library/#from future import standard_library/' \ | ||
-e 's/standard_library.install_aliases()/#standard_library.install_aliases()/' \ | ||
mavlink/pymavlink/generator/mavgen.py && \ | ||
sed -i -e 's/^# find_package(yaml_cpp REQUIRED)/find_package(yaml-cpp REQUIRED)/' \ | ||
-e '/^ament_target_dependencies(mavros_extras_plugins$/i target_link_libraries(mavros_extras_plugins yaml-cpp::yaml-cpp)' \ | ||
-e '/^ament_target_dependencies(mavros_extras$/i target_link_libraries(mavros_extras yaml-cpp::yaml-cpp)' \ | ||
mavros/mavros_extras/CMakeLists.txt | ||
|
||
WORKDIR $USER_WORKSPACE | ||
RUN sudo apt-get -q update \ | ||
&& sudo apt-get -q -y upgrade \ | ||
&& vcs import src < src/blue/blue.repos \ | ||
&& rosdep update \ | ||
&& . "${MAVROS_WORKSPACE}/install/setup.sh" \ | ||
&& rosdep install -y --from-paths ${MAVROS_WORKSPACE}/src --ignore-src --rosdistro ${ROS_DISTRO} \ | ||
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} \ | ||
&& sudo apt-get autoremove -y \ | ||
&& sudo apt-get clean -y \ | ||
&& sudo rm -rf /var/lib/apt/lists/* | ||
|
||
# Actually build workspace | ||
RUN . "/opt/ros/${ROS_DISTRO}/setup.sh" \ | ||
RUN . "${MAVROS_WORKSPACE}/install/setup.sh" \ | ||
&& colcon build | ||
|
||
RUN echo "source ${USER_WORKSPACE}/install/setup.bash" >> /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 | ||
|
||
|
@@ -170,6 +227,7 @@ RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pk | |
xterm \ | ||
rapidjson-dev \ | ||
libopencv-dev \ | ||
cppzmq-dev \ | ||
&& apt-get autoremove -y \ | ||
&& apt-get clean -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
@@ -218,6 +276,7 @@ RUN sudo apt-get -q update \ | |
&& sudo apt-get -q -y upgrade \ | ||
&& vcs import src < src/blue/sim.repos \ | ||
&& rosdep update \ | ||
&& . "${MAVROS_WORKSPACE}/install/setup.sh" \ | ||
&& rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} \ | ||
&& sudo apt-get autoremove -y \ | ||
&& sudo apt-get clean -y \ | ||
|
@@ -226,7 +285,7 @@ RUN sudo apt-get -q update \ | |
# 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" \ | ||
RUN . "${MAVROS_WORKSPACE}/install/setup.sh" \ | ||
&& colcon build | ||
|
||
# Setup the simulation environment variables | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.