Skip to content

Commit 0f23176

Browse files
committed
Fix ulimit issue with docker
1 parent 0f19846 commit 0f23176

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

skipper/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,16 @@ def _prepare_build_container(registry, image, tag, git_revision, container_conte
408408
build_context = '.'
409409

410410
command = ['build', '--network=host', '-t', tagged_image_name, '-f', docker_file, build_context]
411+
412+
for cmd_limit in utils.SKIPPER_ULIMIT:
413+
command += cmd_limit
414+
411415
if use_cache:
412416
cache_image = utils.generate_fqdn_image(registry, namespace=None, image=image, tag=DOCKER_TAG_FOR_CACHE)
413417
runner.run(['pull', cache_image])
414418
command.extend(['--cache-from', cache_image])
415-
ret = runner.run(command)
416-
if ret != 0:
419+
420+
if runner.run(command) != 0:
417421
exit('Failed to build image: %(image)s' % dict(image=image))
418422

419423
if git_revision and not git.uncommitted_changes():

skipper/runner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def _run_nested(fqdn_image, environment, command, interactive, name, net, publis
6060
else:
6161
cmd += ['--rm']
6262

63+
for cmd_limit in utils.SKIPPER_ULIMIT:
64+
cmd += cmd_limit
65+
6366
cmd += ['--privileged']
6467

6568
cmd = handle_networking(cmd, publish, net)

skipper/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
CONTAINER_RUNTIME_COMMAND = os.getenv("CONTAINER_RUNTIME_COMMAND")
2424

25+
SKIPPER_ULIMIT = [['--ulimit', limit] for limit in os.environ.get('SKIPPER_ULIMITS', 'nofile=65536:65536').split(',')]
26+
2527

2628
def configure_logging(name, level):
2729
global logger # pylint: disable=global-statement,invalid-name

tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def test_make_without_build_container_tag_with_context(self, skipper_runner_run_
338338
mock.call(['build', '--network=host',
339339
'-t', 'build-container-image', '-f',
340340
'Dockerfile.build-container-image',
341-
SKIPPER_CONF_CONTAINER_CONTEXT]),
341+
SKIPPER_CONF_CONTAINER_CONTEXT, '--ulimit', 'nofile=65536:65536']),
342342
mock.call(['make'] + make_params, fqdn_image='build-container-image', environment=[],
343343
interactive=False, name=None, net=None, publish=(), volumes=None, workdir=None,
344344
use_cache=False, workspace=None, env_file=()),
@@ -1401,7 +1401,7 @@ def test_run_without_build_container_tag(self, skipper_runner_run_mock):
14011401
)
14021402
expected_commands = [
14031403
mock.call(['build', '--network=host', '-t', 'build-container-image', '-f',
1404-
'Dockerfile.build-container-image', '.']),
1404+
'Dockerfile.build-container-image', '.', '--ulimit', 'nofile=65536:65536']),
14051405
mock.call(command, fqdn_image='build-container-image', environment=[],
14061406
interactive=False, name=None, net=None, publish=(), volumes=None, workdir=None, workspace=None,
14071407
use_cache=False, env_file=()),
@@ -1804,7 +1804,7 @@ def test_make_without_build_container_tag(self, skipper_runner_run_mock):
18041804
)
18051805
expected_commands = [
18061806
mock.call(['build', '--network=host', '-t', 'build-container-image', '-f',
1807-
'Dockerfile.build-container-image', '.']),
1807+
'Dockerfile.build-container-image', '.', '--ulimit', 'nofile=65536:65536']),
18081808
mock.call(['make'] + make_params, fqdn_image='build-container-image', environment=[],
18091809
interactive=False, name=None, net=None, publish=(), volumes=None, workdir=None, workspace=None,
18101810
use_cache=False, env_file=()),

tests/test_runner.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def test_run_simple_command_nested_network_exist(self, resource_filename_mock, c
8282
'docker', 'run',
8383
'-t',
8484
'-e', 'KEEP_CONTAINERS=True',
85+
'--ulimit', 'nofile=65536:65536',
8586
'--privileged',
8687
'--net', get_default_net(),
8788
'-e', 'SKIPPER_USERNAME=testuser',
@@ -127,6 +128,7 @@ def test_run_simple_command_nested_network_not_exist(self, resource_filename_moc
127128
'docker', 'run',
128129
'-t',
129130
'-e', 'KEEP_CONTAINERS=True',
131+
'--ulimit', 'nofile=65536:65536',
130132
'--privileged',
131133
'--net', get_default_net(),
132134
'-e', 'SKIPPER_USERNAME=testuser',
@@ -171,6 +173,7 @@ def test_run_simple_command_nested_with_env(self, resource_filename_mock, check_
171173
'docker', 'run',
172174
'-t',
173175
'-e', 'KEEP_CONTAINERS=True',
176+
'--ulimit', 'nofile=65536:65536',
174177
'--privileged',
175178
'--net', get_default_net(),
176179
'-e', 'KEY1=VAL1',
@@ -225,6 +228,7 @@ def test_run_simple_command_nested_with_env_file(
225228
'docker', 'run',
226229
'-t',
227230
'-e', 'KEEP_CONTAINERS=True',
231+
'--ulimit', 'nofile=65536:65536',
228232
'--privileged',
229233
'--net', get_default_net(),
230234
'--env-file', ENV_FILE_PATH,
@@ -281,6 +285,7 @@ def test_run_simple_command_nested_with_multiple_env_files(
281285
'docker', 'run',
282286
'-t',
283287
'-e', 'KEEP_CONTAINERS=True',
288+
'--ulimit', 'nofile=65536:65536',
284289
'--privileged',
285290
'--net', 'host',
286291
'--env-file', ENV_FILE_PATH,
@@ -335,6 +340,7 @@ def test_run_simple_command_nested_interactive(self, resource_filename_mock,
335340
'-e', 'SKIPPER_INTERACTIVE=True',
336341
'-t',
337342
'-e', 'KEEP_CONTAINERS=True',
343+
'--ulimit', 'nofile=65536:65536',
338344
'--privileged',
339345
'--net', get_default_net(),
340346
'-e', 'SKIPPER_USERNAME=testuser',
@@ -379,6 +385,7 @@ def test_run_complex_command_nested(self, resource_filename_mock, check_output_m
379385
'docker', 'run',
380386
'-t',
381387
'-e', 'KEEP_CONTAINERS=True',
388+
'--ulimit', 'nofile=65536:65536',
382389
'--privileged',
383390
'--net', get_default_net(),
384391
'-e', 'SKIPPER_USERNAME=testuser',
@@ -425,6 +432,7 @@ def test_run_complex_command_nested_with_env(self, resource_filename_mock, check
425432
'test',
426433
'-t',
427434
'-e', 'KEEP_CONTAINERS=True',
435+
'--ulimit', 'nofile=65536:65536',
428436
'--privileged',
429437
'--net', get_default_net(),
430438
'-e', 'KEY1=VAL1',
@@ -479,6 +487,7 @@ def test_run_complex_command_nested_with_special_case_verification(self, resourc
479487
'test',
480488
'-t',
481489
'-e', 'KEEP_CONTAINERS=True',
490+
'--ulimit', 'nofile=65536:65536',
482491
'--privileged',
483492
'--net', get_default_net(),
484493
'-e', 'KEY1=VAL1',

tests/test_runner_podman.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_run_simple_command_nested_network_exist(self, resource_filename_mock, c
6464
self.runtime, 'run',
6565
'-t',
6666
'-e', 'KEEP_CONTAINERS=True',
67+
'--ulimit', 'nofile=65536:65536',
6768
'--privileged',
6869
'--net', get_default_net(),
6970
'-e', 'SKIPPER_USERNAME=testuser',
@@ -104,6 +105,7 @@ def test_run_simple_command_nested_network_not_exist(self, resource_filename_moc
104105
self.runtime, 'run',
105106
'-t',
106107
'-e', 'KEEP_CONTAINERS=True',
108+
'--ulimit', 'nofile=65536:65536',
107109
'--privileged',
108110
'--net', get_default_net(),
109111
'-e', 'SKIPPER_USERNAME=testuser',
@@ -144,6 +146,7 @@ def test_run_complex_command_nested(self, resource_filename_mock, check_output_m
144146
self.runtime, 'run',
145147
'-t',
146148
'-e', 'KEEP_CONTAINERS=True',
149+
'--ulimit', 'nofile=65536:65536',
147150
'--privileged',
148151
'--net', get_default_net(),
149152
'-e', 'SKIPPER_USERNAME=testuser',
@@ -184,6 +187,7 @@ def test_run_complex_command_nested_with_env(self, resource_filename_mock, check
184187
self.runtime, 'run',
185188
'-t',
186189
'-e', 'KEEP_CONTAINERS=True',
190+
'--ulimit', 'nofile=65536:65536',
187191
'--privileged',
188192
'--net', get_default_net(),
189193
'-e', 'KEY1=VAL1',

0 commit comments

Comments
 (0)