diff --git a/features/src/ros2/README.md b/features/src/ros2/README.md index 9cf6b5c..9af16eb 100644 --- a/features/src/ros2/README.md +++ b/features/src/ros2/README.md @@ -17,6 +17,7 @@ Install ROS 2 and the tools needed to develop ROS packages. |-----|-----|-----|-----| | distro | ROS 2 distribution to install. By default, select the recommended distribution for the container's Ubuntu release. | string | auto | | package | ROS 2 metapackage to install. | string | desktop | +| additionalPackages | Space-separated ROS package suffixes to install in addition to the selected metapackage, without the ros-- prefix. | string | - | | workspace | Workspace whose install/setup.sh file should be sourced when present. | string | ${containerWorkspaceFolder} | ## Supported Ubuntu releases diff --git a/features/src/ros2/devcontainer-feature.json b/features/src/ros2/devcontainer-feature.json index 9b7ab44..080138f 100644 --- a/features/src/ros2/devcontainer-feature.json +++ b/features/src/ros2/devcontainer-feature.json @@ -27,6 +27,11 @@ "default": "desktop", "description": "ROS 2 metapackage to install." }, + "additionalPackages": { + "type": "string", + "default": "", + "description": "Space-separated ROS package suffixes to install in addition to the selected metapackage, without the ros-- prefix." + }, "workspace": { "type": "string", "default": "${containerWorkspaceFolder}", diff --git a/features/src/ros2/install.sh b/features/src/ros2/install.sh index 58b68a6..414d3c7 100755 --- a/features/src/ros2/install.sh +++ b/features/src/ros2/install.sh @@ -4,6 +4,7 @@ set -euo pipefail ros_distro="${DISTRO:-auto}" ros_package="${PACKAGE:-desktop}" +ros_additional_packages="${ADDITIONALPACKAGES:-}" ros_workspace="${WORKSPACE:-${_REMOTE_USER_HOME:-/workspaces}/ros2_ws}" feature_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" distribution_config="${feature_dir}/distributions.json" @@ -130,8 +131,17 @@ dpkg -i "${ros_apt_source_package}" rm -f "${ros_apt_source_package}" apt-get update +additional_apt_packages=() +if [[ -n "${ros_additional_packages}" ]]; then + read -r -a additional_package_names <<<"${ros_additional_packages}" + for additional_package_name in "${additional_package_names[@]}"; do + additional_apt_packages+=("ros-${ros_distro}-${additional_package_name}") + done +fi + apt-get install -y --no-install-recommends \ "ros-${ros_distro}-${ros_package}" \ + "${additional_apt_packages[@]}" \ python3-colcon-common-extensions \ python3-rosdep \ python3-vcstool \ diff --git a/features/test/ros2/additional_packages.sh b/features/test/ros2/additional_packages.sh new file mode 100755 index 0000000..6e7abc1 --- /dev/null +++ b/features/test/ros2/additional_packages.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +source dev-container-features-test-lib + +check "ROS 2 Kilted is selected" bash -lc '[ "${ROS_DISTRO:-}" = "kilted" ]' +check "ROS 2 CLI is installed" bash -lc 'command -v ros2 >/dev/null' +check "RViz is installed" bash -lc 'ros2 pkg prefix rviz2 >/dev/null' + +reportResults diff --git a/features/test/ros2/scenarios.json b/features/test/ros2/scenarios.json index 10777ca..4b4bdc8 100644 --- a/features/test/ros2/scenarios.json +++ b/features/test/ros2/scenarios.json @@ -7,6 +7,16 @@ "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", "features": { "ros2": { "distro": "kilted", "package": "ros-base" } } }, + "additional_packages": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "features": { + "ros2": { + "distro": "kilted", + "package": "ros-base", + "additionalPackages": "rviz2" + } + } + }, "lyrical": { "image": "ubuntu:26.04", "features": { "ros2": { "package": "ros-base" } }