Skip to content

Commit

Permalink
Basic rocker config to install and enable different rmw layers
Browse files Browse the repository at this point in the history
Only tested with cyclonedds for the moment.
  • Loading branch information
tfoote committed Feb 16, 2024
1 parent 80a9292 commit 955fcff
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
63 changes: 63 additions & 0 deletions src/rocker/rmw_extension.py
Original file line number Diff line number Diff line change
@@ -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")
13 changes: 13 additions & 0 deletions src/rocker/templates/rmw_snippet.Dockerfile.em
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 955fcff

Please sign in to comment.