-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix, use "service.build.ulimits" when it is present instead of "servi…
…ce.ulimits" Signed-off-by: Cam Spiers <camspiers@gmail.com>
- Loading branch information
Showing
5 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
|
||
"""Test how ulimits are applied in podman-compose build.""" | ||
|
||
import os | ||
import subprocess | ||
import unittest | ||
|
||
from .test_podman_compose import podman_compose_path | ||
from .test_podman_compose import test_path | ||
|
||
|
||
def compose_yaml_path(): | ||
""" "Returns the path to the compose file used for this test module""" | ||
return os.path.join(test_path(), "ulimit_build") | ||
|
||
|
||
class TestComposeBuildUlimits(unittest.TestCase): | ||
def test_build_ulimits_ulimit1(self): | ||
"""podman build should receive and apply limits when building service ulimit1""" | ||
|
||
cmd = ( | ||
"coverage", | ||
"run", | ||
podman_compose_path(), | ||
"--verbose", | ||
"-f", | ||
os.path.join(compose_yaml_path(), "docker-compose.yaml"), | ||
"build", | ||
"--no-cache", | ||
"ulimit1" | ||
) | ||
p = subprocess.run( | ||
cmd, stdout=subprocess.PIPE, check=False, stderr=subprocess.STDOUT, text=True | ||
) | ||
|
||
self.assertEqual(p.returncode, 0) | ||
self.assertIn("--ulimit nofile=1001", p.stdout) | ||
self.assertIn("soft process limit: 253744", p.stdout) | ||
self.assertIn("hard process limit: 253744", p.stdout) | ||
self.assertIn("soft nofile limit: 1001", p.stdout) | ||
self.assertIn("hard nofile limit: 1001", p.stdout) | ||
|
||
def test_build_ulimits_ulimit2(self): | ||
"""podman build should receive and apply limits when building service ulimit2""" | ||
|
||
cmd = ( | ||
"coverage", | ||
"run", | ||
podman_compose_path(), | ||
"--verbose", | ||
"-f", | ||
os.path.join(compose_yaml_path(), "docker-compose.yaml"), | ||
"build", | ||
"--no-cache", | ||
"ulimit2" | ||
) | ||
p = subprocess.run( | ||
cmd, stdout=subprocess.PIPE, check=False, stderr=subprocess.STDOUT, text=True | ||
) | ||
|
||
self.assertEqual(p.returncode, 0) | ||
self.assertIn("--ulimit nofile=1002", p.stdout) | ||
self.assertIn("--ulimit nproc=1002:2002", p.stdout) | ||
self.assertIn("soft process limit: 1002", p.stdout) | ||
self.assertIn("hard process limit: 2002", p.stdout) | ||
self.assertIn("soft nofile limit: 1002", p.stdout) | ||
self.assertIn("hard nofile limit: 1002", p.stdout) | ||
|
||
def test_build_ulimits_ulimit3(self): | ||
"""podman build should receive and apply limits when building service ulimit3""" | ||
|
||
cmd = ( | ||
"coverage", | ||
"run", | ||
podman_compose_path(), | ||
"--verbose", | ||
"-f", | ||
os.path.join(compose_yaml_path(), "docker-compose.yaml"), | ||
"build", | ||
"--no-cache", | ||
"ulimit3" | ||
) | ||
p = subprocess.run( | ||
cmd, stdout=subprocess.PIPE, check=False, stderr=subprocess.STDOUT, text=True | ||
) | ||
|
||
self.assertEqual(p.returncode, 0) | ||
self.assertIn("--ulimit nofile=1003", p.stdout) | ||
self.assertIn("--ulimit nproc=1003:2003", p.stdout) | ||
self.assertIn("soft process limit: 1003", p.stdout) | ||
self.assertIn("hard process limit: 2003", p.stdout) | ||
self.assertIn("soft nofile limit: 1003", p.stdout) | ||
self.assertIn("hard nofile limit: 1003", p.stdout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM busybox | ||
|
||
COPY ./ulimit.sh /bin/ulimit.sh | ||
|
||
RUN /bin/ulimit.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: "3" | ||
services: | ||
ulimit1: | ||
image: ulimit_build_test | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
ulimits: nofile=1001 | ||
ulimit2: | ||
image: ulimit_build_test | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
ulimits: | ||
- nproc=1002:2002 | ||
- nofile=1002 | ||
ulimit3: | ||
image: ulimit_build_test | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
ulimits: | ||
nofile: 1003 | ||
nproc: | ||
soft: 1003 | ||
hard: 2003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
echo "soft process limit:" $(ulimit -S -u) | ||
echo "hard process limit:" $(ulimit -H -u) | ||
echo "soft nofile limit:" $(ulimit -S -n) | ||
echo "hard nofile limit:" $(ulimit -H -n) |