Skip to content

Commit 045f144

Browse files
authored
Merge pull request #152 from xfiderek/issue/142
Pin navigation2 repos and simplify docker build (#142).
2 parents 09ec444 + 5c8467d commit 045f144

12 files changed

+766
-133
lines changed

nav2_demo/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ Start the space_nav2 container and launch the navigation2 nodes:
2222

2323
```
2424
./run.sh
25-
ros2 launch nav2_bringup navigation_launch.py use_sim_time:=True params_file:=nav2_params.yaml
25+
ros2 launch space_nav2_bringup navigation_launch.py use_sim_time:=True params_file:=nav2_params.yaml
2626
```
2727

2828
## Terminal 3 - launch localization with map
2929

3030
```
3131
docker exec -it osrf_space_nav2_demo bash
3232
source install/setup.bash
33-
ros2 launch nav2_bringup localization_launch.py use_sim_time:=True map:=mars_map.yaml
33+
ros2 launch space_nav2_bringup localization_launch.py use_sim_time:=True map:=mars_map.yaml params_file:=nav2_params.yaml
3434
```
3535

3636
## Terminal 4 - launch Rviz
3737

3838
Exec into the same space_nav2 container and launch Rviz2:
3939

4040
```
41-
docker exec -it -e DISPLAY=:0 osrf_space_nav2_demo bash
41+
docker exec -it -e DISPLAY osrf_space_nav2_demo bash
4242
source /opt/ros/humble/setup.bash
4343
source install/setup.bash
4444
ros2 launch nav2_bringup rviz_launch.py

navigation2/Dockerfile

+23-56
Original file line numberDiff line numberDiff line change
@@ -41,69 +41,36 @@ LABEL org.label-schema.vcs-ref=${VCS_REF}
4141
# Disable prompting during package installation
4242
ARG DEBIAN_FRONTEND=noninteractive
4343

44+
SHELL ["/bin/bash", "-c"]
45+
4446
# Define workspace locations
4547
ENV NAVIGATION2_WS=${HOME_DIR}/nav2_ws
46-
ENV NAV2_DEPS_WS=${HOME_DIR}/nav2_deps_ws
4748

48-
# Get the Navigation2 source code
4949
RUN mkdir -p ${NAVIGATION2_WS}/src
50-
WORKDIR ${NAVIGATION2_WS}/src
51-
ARG NAV2_BRANCH=humble
52-
RUN sudo git clone --branch $NAV2_BRANCH https://github.com/ros-navigation/navigation2.git
5350

54-
# Get keys for Nav2 dependencies
5551
WORKDIR ${NAVIGATION2_WS}/
56-
SHELL ["/bin/bash", "-c"]
57-
RUN source ${SPACEROS_DIR}/install/setup.bash && sudo apt update && rosdep keys --from-paths src --ignore-src --rosdistro humble -y > ${NAVIGATION2_WS}/nav2_dep_keys.txt
58-
59-
# Get rosinstall_generator
60-
RUN sudo apt-get update -y && sudo apt-get install -y python3-rosinstall-generator
61-
62-
# Clone Space ROS sources temporarily as input to rosinstall_generator
63-
RUN mkdir ${SPACEROS_DIR}/src \
64-
&& vcs import ${SPACEROS_DIR}/src < ${SPACEROS_DIR}/exact.repos
65-
66-
# Generate repos file for nav2 dependencies, exclude packages from Space ROS src
67-
RUN rosinstall_generator \
68-
--rosdistro ${ROS_DISTRO} \
69-
--deps \
70-
--exclude-path ${SPACEROS_DIR}/src -- \
71-
-- $(cat ${NAVIGATION2_WS}/nav2_dep_keys.txt) \
72-
> ${NAVIGATION2_WS}/nav2_deps.repos
73-
74-
# Remove unneeded src files now that repos are generated
75-
RUN rm -rf ${SPACEROS_DIR}/src
76-
77-
# Get the repositories required by Nav2
78-
RUN mkdir -p ${NAV2_DEPS_WS}/src
79-
WORKDIR ${NAV2_DEPS_WS}
80-
RUN sudo vcs import src < ${NAVIGATION2_WS}/nav2_deps.repos
81-
82-
# Update the ownership of the source files
83-
RUN sudo chown -R ${USERNAME}:${USERNAME} ${NAV2_DEPS_WS}
84-
85-
# Install nav2_deps_ws dependencies
86-
SHELL ["/bin/bash", "-c"]
87-
RUN source ${SPACEROS_DIR}/install/setup.bash && sudo apt update && rosdep install --from-paths src --ignore-src --rosdistro humble -y \
88-
--skip-keys "composition demo_nodes_py ikos lifecycle rmw_connextdds rmw_fastrtps_dynamic_cpp rmw_fastrtps_cpp \
89-
rosidl_typesupport_fastrtps_c rosidl_typesupport_fastrtps_cpp urdfdom_headers"
90-
91-
# Build dependencies
92-
RUN source ${SPACEROS_DIR}/install/setup.bash && colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
93-
94-
# Install remaining nav2 dependencies (not in rosdistro)
95-
WORKDIR ${NAVIGATION2_WS}
96-
SHELL ["/bin/bash", "-c"]
97-
RUN source ${NAV2_DEPS_WS}/install/setup.bash && sudo apt update && rosdep install --from-paths src --ignore-src --rosdistro humble -y \
98-
--skip-keys "composition demo_nodes_py ikos lifecycle rmw_connextdds rmw_fastrtps_dynamic_cpp rmw_fastrtps_cpp \
99-
rosidl_typesupport_fastrtps_c rosidl_typesupport_fastrtps_cpp urdfdom_headers"
100-
101-
# Build Navigation2
102-
SHELL ["/bin/bash", "-c"]
103-
RUN source ${NAV2_DEPS_WS}/install/setup.bash && colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
10452

105-
# Install rviz2 to send goals to Nav2
106-
RUN sudo apt update && sudo apt install -y ros-humble-rviz2
53+
COPY navigation2.repos .
54+
COPY excluded-pkgs.txt .
55+
RUN vcs import --shallow src < navigation2.repos
56+
COPY --chown=spaceros-user:spaceros-user src/ src
57+
58+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
59+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
60+
source ${SPACEROS_DIR}/install/setup.bash && \
61+
sudo apt update && \
62+
rosdep install -i --from-path src --skip-keys $(cat excluded-pkgs.txt) -y
63+
RUN source ${SPACEROS_DIR}/install/setup.bash && \
64+
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON --no-warn-unused-cli
65+
RUN rm -rf src build log
66+
67+
68+
# Install rviz2 to send goals to Nav2.
69+
# TODO(xfiderek): Remove rviz2 and humble-nav2 froms this image
70+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
71+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
72+
sudo apt update && \
73+
sudo apt install -y ros-humble-rviz2 ros-humble-nav2-bringup
10774

10875
# Set up the entrypoint
10976
COPY ./entrypoint.sh /

navigation2/README.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Navigation2 Docker Image
22

33
The Navigation2 Docker image uses the Space ROS docker image (*osrf/space-ros:latest*) as its base image.
4-
The Navigation2 Dockerfile installs all of the prerequisite system dependencies to build Navigation2
4+
The Navigation2 Dockerfile installs all of the prerequisite system dependencies to build Navigation2.
5+
All the required nav2 packages are cloned and built from sources using the `navigation2.repos` file. The `nav2_rviz_plugins` and `nav2_bringup` packages together with their dependencies (Rviz, Gazebo, etc) are excluded to reduce package dependencies. The image also contains a custom `space_nav2_bringup` package that can be used as a starting point for creating mission-specific nav2 launch files.
6+
57
## Building the Navigation2 Image
68

79
To build the docker image, run:
@@ -33,8 +35,7 @@ The output will look something like this:
3335
```
3436
REPOSITORY TAG IMAGE ID CREATED SIZE
3537
osrf/space_nav2 latest 6edb2edc9643 10 hours ago 15.5GB
36-
openrobotics/spaceros latest 629b13cf7b74 12 hours ago 7.8GB
37-
nvidia/cudagl 11.4.1-devel-ubuntu20.04 336416dfcbba 1 week ago 5.35GB
38+
osrf/space-ros latest 629b13cf7b74 12 hours ago 7.8GB
3839
```
3940

4041
The new image is named **osrf/space_nav2:latest**.
@@ -45,13 +46,34 @@ There is a run.sh script provided for convenience that will run the spaceros ima
4546
./run.sh
4647
```
4748

48-
Upon startup, the container automatically runs the entrypoint.sh script, which sources the MoveIt2 and Space ROS environment files.
49+
Upon startup, the container automatically runs the entrypoint.sh script, which sources the Nav2 and Space ROS environment files.
4950
You'll now be running inside the container and should see a prompt similar to this:
5051

5152
```
52-
root@ip-your-ip-address:/home/spaceros-user/nav2_ws#
53+
spaceros-user@ip-your-ip-address:/home/spaceros-user/nav2_ws#
5354
```
5455

5556
## Running Navigation2 Demo
5657

57-
To run the latest demo, see the README in the nav2_demos folder
58+
To run the latest demo, see the README in the [nav2_demo](../nav2_demo/README.md) folder.
59+
60+
## Updating navigation2 packages
61+
62+
The `navigation2.repos` file available in this repository provides a list of repos that are required to build the nav2 stack. ROS packages already included in the SpaceROS base image are omited from this file.
63+
64+
To update navigation2 packages used to build the space nav2 image, run the `docker_update_nav2_repos.sh` script:
65+
66+
```
67+
./docker_update_nav2_repos.sh
68+
```
69+
70+
This will update the `navigation2.repos` file with the newest versions of nav2 packages. The script resolves missing packages in base spaceros image and creates a list with their latest versions. The `navigation2.repos` file is then copied during build to the docker image with space nav2, and packages specified in the file are cloned and installed.
71+
72+
By default, this update nav2 repositories using the latest released version of the Space ROS base image (typically `osrf/space-ros:latest`).
73+
If building locally, the underlying base image can be set in the through the environment with:
74+
75+
```
76+
SPACE_ROS_IMAGE=osrf/space-ros:main ./docker_update_nav2_repos.sh
77+
```
78+
79+
To generate a list of required packages for any other ROS workspace (e.g. your custom workspace built on top of SpaceROS that already has some nav2 dependencies installed), consider using the `update_nav2_repos.sh` as your starting point. You may also need to clone `generate-repos.sh` script from the main spaceros repository.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
SPACE_ROS_IMAGE="${SPACE_ROS_IMAGE:-osrf/space-ros:latest}"
3+
4+
docker run --rm \
5+
-v ./:/home/spaceros-user/mount/ \
6+
-w /home/spaceros-user/mount/ \
7+
$SPACE_ROS_IMAGE \
8+
bash -c './update_nav2_repos.sh'

navigation2/excluded-pkgs.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nav2_rviz_plugins

navigation2/navigation2-pkgs.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
navigation2

0 commit comments

Comments
 (0)