Skip to content

Commit

Permalink
feat: get rid of is_docker_rootless template filter
Browse files Browse the repository at this point in the history
This filter was used only by Elasticsearch, so we no longer need to
include it in Tutor.
  • Loading branch information
regisb authored and DawoudSheraz committed Dec 4, 2024
1 parent a7fa473 commit 17dee9a
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 💥[Improvement] Get rid of the `is_docker_rootless` template filter, which was used only by Elasticsearch. (by @regisb)
19 changes: 0 additions & 19 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,25 +242,6 @@ def test_is_http(self) -> None:
self.assertFalse(utils.is_http("home/user/"))
self.assertFalse(utils.is_http("http-home/user/"))

@patch("subprocess.run")
def test_is_docker_rootless(self, mock_run: MagicMock) -> None:
# Mock rootless `docker info` output
utils.is_docker_rootless.cache_clear()
mock_run.return_value.stdout = "some prefix\n rootless foo bar".encode("utf-8")
self.assertTrue(utils.is_docker_rootless())

# Mock regular `docker info` output
utils.is_docker_rootless.cache_clear()
mock_run.return_value.stdout = "some prefix, regular docker".encode("utf-8")
self.assertFalse(utils.is_docker_rootless())

@patch("subprocess.run")
def test_is_docker_rootless_podman(self, mock_run: MagicMock) -> None:
"""Test the `is_docker_rootless` when podman is used or any other error with `docker info`"""
utils.is_docker_rootless.cache_clear()
mock_run.side_effect = subprocess.CalledProcessError(1, "docker info")
self.assertFalse(utils.is_docker_rootless())

def test_format_table(self) -> None:
rows: List[Tuple[str, ...]] = [
("a", "xyz", "value 1"),
Expand Down
1 change: 0 additions & 1 deletion tutor/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def _prepare_environment() -> None:
("TUTOR_APP", __app__.replace("-", "_")),
("TUTOR_VERSION", __version__),
("TUTOR_BRANCH_IS_MAIN", __version_suffix__ == "main"),
("is_docker_rootless", utils.is_docker_rootless),
],
)

Expand Down
14 changes: 0 additions & 14 deletions tutor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,6 @@ def docker(*command: str) -> int:
return execute("docker", *command)


@lru_cache(maxsize=None)
def is_docker_rootless() -> bool:
"""
A helper function to determine if Docker is running in rootless mode.
- https://docs.docker.com/engine/security/rootless/
"""
try:
results = subprocess.run(["docker", "info"], capture_output=True, check=True)
return "rootless" in results.stdout.decode()
except subprocess.CalledProcessError:
return False


def docker_compose(*command: str) -> int:
return execute("docker", "compose", *command)

Expand Down

0 comments on commit 17dee9a

Please sign in to comment.