mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-07 01:54:04 +00:00
Refactor TrackedContainer run_detached/exec_cmd functions (#2256)
* Refactor TrackedContainer run_detached/exec_cmd functions * Add get_logs() method * Small fixes * Make get_health() a method * Remove kwargs, always print output * Small fixes
This commit is contained in:
@@ -15,7 +15,6 @@ def _get_pip_package_version(container: Container, package: str) -> str:
|
||||
package_info = DockerRunner.exec_cmd(
|
||||
container,
|
||||
cmd=f"pip show {package}",
|
||||
print_output=False,
|
||||
)
|
||||
version_line = package_info.split("\n")[1]
|
||||
assert version_line.startswith(PIP_VERSION_PREFIX)
|
||||
|
@@ -43,12 +43,11 @@ class DockerRunner:
|
||||
LOGGER.info(f"Container {self.container.name} removed")
|
||||
|
||||
@staticmethod
|
||||
def exec_cmd(container: Container, cmd: str, print_output: bool = True) -> str:
|
||||
def exec_cmd(container: Container, cmd: str) -> str:
|
||||
LOGGER.info(f"Running cmd: `{cmd}` on container: {container.name}")
|
||||
exec_result = container.exec_run(cmd)
|
||||
output = exec_result.output.decode().rstrip()
|
||||
assert isinstance(output, str)
|
||||
if print_output:
|
||||
LOGGER.info(f"Command output: {output}")
|
||||
LOGGER.info(f"Command output: {output}")
|
||||
assert exec_result.exit_code == 0, f"Command: `{cmd}` failed"
|
||||
return output
|
||||
|
@@ -8,7 +8,7 @@ from tagging.utils.docker_runner import DockerRunner
|
||||
|
||||
|
||||
def quoted_output(container: Container, cmd: str) -> str:
|
||||
cmd_output = DockerRunner.exec_cmd(container, cmd, print_output=False)
|
||||
cmd_output = DockerRunner.exec_cmd(container, cmd)
|
||||
# For example, `mamba info` adds redundant empty lines
|
||||
cmd_output = cmd_output.strip("\n")
|
||||
# For example, R packages list contains trailing backspaces
|
||||
|
Reference in New Issue
Block a user