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

Add shm_size extension to provide --shm-size argument #306

Merged
merged 1 commit into from
Jan 10, 2025
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'privileged = rocker.extensions:Privileged',
'pulse = rocker.extensions:PulseAudio',
'rmw = rocker.rmw_extension:RMW',
'shm_size = rocker.extensions:ShmSize',
'ssh = rocker.ssh_extension:Ssh',
'ulimit = rocker.ulimit_extension:Ulimit',
'user = rocker.extensions:User',
Expand Down
24 changes: 24 additions & 0 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,27 @@ def register_arguments(parser, defaults):
default=defaults.get(GroupAdd.get_name(), None),
action='append',
help="Add additional groups to join.")

class ShmSize(RockerExtension):
@staticmethod
def get_name():
return 'shm_size'

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

def get_preamble(self, cliargs):
return ''

def get_docker_args(self, cliargs):
args = ''
shm_size = cliargs.get('shm_size', None)
if shm_size:
args += f' --shm-size {shm_size} '
return args

@staticmethod
def register_arguments(parser, defaults={}):
parser.add_argument('--shm-size',
default=defaults.get('shm_size', None),
help="Set the size of the shared memory for the container (e.g., 512m, 1g).")
32 changes: 32 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,35 @@ def test_group_add_extension(self):
args = p.get_docker_args(mock_cliargs)
self.assertIn('--group-add sudo', args)
self.assertIn('--group-add docker', args)

class ShmSizeExtensionTest(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_shm_size_extension(self):
plugins = list_plugins()
shm_size_plugin = plugins['shm_size']
self.assertEqual(shm_size_plugin.get_name(), 'shm_size')

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

mock_cliargs = {}
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
args = p.get_docker_args(mock_cliargs)
self.assertNotIn('--shm-size', args)

mock_cliargs = {'shm_size': '12g'}
args = p.get_docker_args(mock_cliargs)
self.assertIn('--shm-size 12g', args)