From 955fcff8e76d704f341a655d8d3a6a4acee31e54 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Fri, 16 Feb 2024 13:04:06 -0800 Subject: [PATCH] Basic rocker config to install and enable different rmw layers Only tested with cyclonedds for the moment. --- setup.py | 1 + src/rocker/rmw_extension.py | 63 +++++++++++++++++++ .../templates/rmw_snippet.Dockerfile.em | 13 ++++ 3 files changed, 77 insertions(+) create mode 100644 src/rocker/rmw_extension.py create mode 100644 src/rocker/templates/rmw_snippet.Dockerfile.em diff --git a/setup.py b/setup.py index f27a0f97..013ef998 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ 'port = rocker.extensions:Port', 'privileged = rocker.extensions:Privileged', 'pulse = rocker.extensions:PulseAudio', + 'rmw = rocker.rmw_extension:RMW', 'ssh = rocker.ssh_extension:Ssh', 'user = rocker.extensions:User', 'volume = rocker.volume_extension:Volume', diff --git a/src/rocker/rmw_extension.py b/src/rocker/rmw_extension.py new file mode 100644 index 00000000..3f2481ea --- /dev/null +++ b/src/rocker/rmw_extension.py @@ -0,0 +1,63 @@ +# Copyright 2024 Open Source Robotics Foundation + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from argparse import ArgumentTypeError +import os +import pkgutil + +from .em import empy_expand +from rocker.extensions import RockerExtension +from rocker.extensions import name_to_argument + + +class RMW(RockerExtension): + @staticmethod + def get_name(): + return 'rmw' + + def __init__(self): + self._env_subs = None + self.name = RMW.get_name() + + def get_docker_args(self, cli_args): + implementation = cli_args.get('rmw') + args = f' -e RMW_IMPLEMENTATION=rmw_{implementation}_cpp' + return args #% self.get_environment_subs() + + def get_environment_subs(self): + if not self._env_subs: + self._env_subs = {} + return self._env_subs + + def get_preamble(self, cliargs): + return '' + + def get_snippet(self, cliargs): + snippet = pkgutil.get_data('rocker', 'templates/%s_snippet.Dockerfile.em' % self.get_name()).decode('utf-8') + data = self.get_environment_subs() + # data['rosdistro'] = cliargs.get('rosdistro', 'rolling') + data['rmw'] = cliargs.get('rmw', None) + # data['rosdistro'] = 'rolling' + return empy_expand(snippet, data) + + @staticmethod + def register_arguments(parser, defaults={}): + parser.add_argument(name_to_argument(RMW.get_name()), + default=defaults.get('rmw', 'fastrtps'), + nargs='?', + help="Set the default RMW implementation") + + # parser.add_argument('rosdistro', + # default=defaults.get('rosdistro', None), + # help="Set the default rosdistro, else autodetect") diff --git a/src/rocker/templates/rmw_snippet.Dockerfile.em b/src/rocker/templates/rmw_snippet.Dockerfile.em new file mode 100644 index 00000000..733c6eb9 --- /dev/null +++ b/src/rocker/templates/rmw_snippet.Dockerfile.em @@ -0,0 +1,13 @@ +# workspace development helpers + + +@[ if rmw ]@ +RUN if [ -z "${ROS_DISTRO}" ]; then echo "ROS_DISTRO is unset cannot override RMW" ; exit 1 ; fi \ + && apt-get update \ + && apt-get install -y \ + ros-${ROS_DISTRO}-rmw-@(rmw)-cpp \ + ros-${ROS_DISTRO}-rmw-dds-common \ + && apt-get clean +@[ end if ]@ + +# working around recent upgrade of dds-common from 2.x to 3.x which is out of date in the image