Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/added ipc flag #285

Merged
merged 7 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ You can get full details on the extensions from the main `rocker --help` command
- pulse -- Mount pulse audio into the container
- ssh -- Pass through ssh access to the container.

As well as access to many of the docker arguments as well such as `device`, `env`, `volume`, `name`, `network`, and `privileged`.
As well as access to many of the docker arguments as well such as `device`, `env`, `volume`, `name`, `network`, `ipc`, and `privileged`.

### Externally maintained extensions

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'group_add = rocker.extensions:GroupAdd',
'home = rocker.extensions:HomeDir',
'hostname = rocker.extensions:Hostname',
'ipc = rocker.extensions:Ipc',
'name = rocker.extensions:Name',
'network = rocker.extensions:Network',
'nvidia = rocker.nvidia_extension:Nvidia',
Expand Down
75 changes: 49 additions & 26 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ def register_arguments(parser, defaults={}):
help="add development tools emacs and byobu to your environment")


class Expose(RockerExtension):
@staticmethod
def get_name():
return 'expose'

def __init__(self):
self.name = Expose.get_name()

def get_preamble(self, cliargs):
return ''

def get_docker_args(self, cliargs):
args = ['']
ports = cliargs.get('expose', [])
for port in ports:
args.append(' --expose {0}'.format(port))
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
parser.add_argument('--expose',
default=defaults.get('expose', None),
action='append',
help="Exposes a port from the container to host machine.")


class Hostname(RockerExtension):
@staticmethod
def get_name():
Expand All @@ -114,6 +140,29 @@ def register_arguments(parser, defaults={}):
parser.add_argument('--hostname', default=defaults.get('hostname', ''),
help='Hostname of the container.')


class Ipc(RockerExtension):
@staticmethod
def get_name():
return 'ipc'
def __init__(self):
self.name = Ipc.get_name()

def get_preamble(self, cliargs):
return ''

def get_docker_args(self, cliargs):
args = ''
ipc = cliargs.get('ipc', None)
args += ' --ipc %s ' % ipc
return args

@staticmethod
def register_arguments(parser, defaults={}):
parser.add_argument('--ipc', default=defaults.get('ipc', None),
help='IPC namespace to use. To share ipc with the host use host. More details can be found at https://docs.docker.com/reference/cli/docker/container/run/#ipc')


class Name(RockerExtension):
@staticmethod
def get_name():
Expand Down Expand Up @@ -163,32 +212,6 @@ def register_arguments(parser, defaults={}):
help="What network configuration to use.")


class Expose(RockerExtension):
@staticmethod
def get_name():
return 'expose'

def __init__(self):
self.name = Expose.get_name()

def get_preamble(self, cliargs):
return ''

def get_docker_args(self, cliargs):
args = ['']
ports = cliargs.get('expose', [])
for port in ports:
args.append(' --expose {0}'.format(port))
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
parser.add_argument('--expose',
default=defaults.get('expose', None),
action='append',
help="Exposes a port from the container to host machine.")


class Port(RockerExtension):
@staticmethod
def get_name():
Expand Down
34 changes: 34 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,40 @@ def test_home_extension(self):
args = p.get_docker_args(mock_cliargs)
self.assertTrue('-v %s:%s' % (Path.home(), Path.home()) in args)


class IpcExtensionTest(unittest.TestCase):

def setUp(self):
# Work around interference between empy Interpreter
# stdout proxy and test runner. empy installs a proxy on stdout
# to be able to capture the information.
# And the test runner creates a new stdout object for each test.
# This breaks empy as it assumes that the proxy has persistent
# between instances of the Interpreter class
# empy will error with the exception
# "em.Error: interpreter stdout proxy lost"
em.Interpreter._wasProxyInstalled = False

@pytest.mark.docker
def test_ipc_extension(self):
plugins = list_plugins()
ipc_plugin = plugins['ipc']
self.assertEqual(ipc_plugin.get_name(), 'ipc')

p = ipc_plugin()
self.assertTrue(plugin_load_parser_correctly(ipc_plugin))

mock_cliargs = {'ipc': 'none'}
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--ipc none' in args)

mock_cliargs = {'ipc': 'host'}
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--ipc host' in args)


class NetworkExtensionTest(unittest.TestCase):

def setUp(self):
Expand Down
Loading