Skip to content

Instantly share code, notes, and snippets.

@Achllle
Last active January 25, 2023 01:59
Show Gist options
  • Save Achllle/e55a5f34c02720963898ef807ae396ac to your computer and use it in GitHub Desktop.
Save Achllle/e55a5f34c02720963898ef807ae396ac to your computer and use it in GitHub Desktop.
Building a ROS2 component from source with Docker for development

In this example we're setting up ros2 and its dependencies so we can debug a particular component, in this case rclpy. To replicate this, you need to fork ros so you can edit ros2.repos to point to your modified component (here forked rclpy). See for example this commit on branch custom_rclpy.

The devcontainer.json file can be used to develop with VS code's devcontainer extension. If you're not using VS code, you can build the container using

docker build -f Dockerfile  --build-arg GH_USER yourgithubhandle --build-arg GH_BRANCH=branchinyourforkedrepo

where GH_BRANCH is the branch in the ros2 repo.

Latest instructions on building from source can be found here. Make sure you pick the right distro.

Note: I'm hoping there was a better/faster way to do this. I initially just started with base image ros:rolling and cloned the forked rclpy repo, but got an error with colcon complaining that two repos were installed. This also means that all the other repositories need to be built from source rather than just the one you're trying to modify.

{
"dockerFile": "Dockerfile",
"build": {
"args": {
"WORKSPACE": "${containerWorkspaceFolder}",
"GH_USER": "Achllle",
"GH_BRANCH": "custom_rclpy"
}
}
}
FROM ubuntu:jammy
ARG GH_USER=ros2
ARG GH_BRANCH=rolling
ENV DEBIAN_FRONTEND=noninteractive
RUN \
# apt-get -y install --no-install-recommends software-properties-common \
apt-get update \
&& apt-get -y install --no-install-recommends \
software-properties-common curl wget cmake locales \
&& add-apt-repository universe
RUN \
locale-gen en_US en_US.UTF-8 \
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
&& export LANG=en_US.UTF-8
RUN \
# install development tools and ros tools
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
python3-colcon-common-extensions python3-pip python3-rosdep python3-setuptools python3-vcstool \
ros-dev-tools \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# build ros2 from source
# Setup ROS2 Rolling from source as per
# https://index.ros.org/doc/ros2/Installation/Rolling/Linux-Development-Setup/
ARG WORKSPACE=/workspaces/${GH_BRANCH}
WORKDIR ${WORKSPACE}
RUN \
# setup the workspace
wget https://raw.githubusercontent.com/${GH_USER}/ros2/${GH_BRANCH}/ros2.repos \
&& mkdir src \
&& vcs import src < ros2.repos
RUN \
# install Fast-RTPS && Cyclone DDS dependencies
apt-get update \
&& apt-get install --no-install-recommends -y \
# Fast-RTPS
libasio-dev \
libtinyxml2-dev \
# Cyclone DDS
libcunit1-dev
RUN \
# install package dependencies
# version of rti-connext-dds depends on ROS2 version, consult official from source instructions.
apt-get update && rosdep init && rosdep update \
&& rosdep install --from-paths src --ignore-src --rosdistro rolling -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"
ENV DEBIAN_FRONTEND=dialog
# Build the ROS2 workspace
RUN colcon build --symlink-install
# Set up auto-source of workspace for ros user
RUN echo "if [ -f ${WORKSPACE}/install/setup.bash ]; then source ${WORKSPACE}/install/setup.bash; fi" >> /root/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment