mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-08 18:44:06 +00:00
Make run_simple_command part of DockerRunner
This commit is contained in:
@@ -28,8 +28,8 @@ class DockerRunner:
|
|||||||
self.container.remove(force=True)
|
self.container.remove(force=True)
|
||||||
logger.info(f"Container {self.container.name} removed")
|
logger.info(f"Container {self.container.name} removed")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def run_simple_command(container, cmd, print_result=True):
|
def run_simple_command(container, cmd, print_result=True):
|
||||||
logger.info(f"Running cmd: '{cmd}' on container: {container}")
|
logger.info(f"Running cmd: '{cmd}' on container: {container}")
|
||||||
out = container.exec_run(cmd)
|
out = container.exec_run(cmd)
|
||||||
assert out.exit_code == 0, f"Command: {cmd} failed"
|
assert out.exit_code == 0, f"Command: {cmd} failed"
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import logging
|
import logging
|
||||||
from plumbum.cmd import docker
|
from plumbum.cmd import docker
|
||||||
from .docker_runner import run_simple_command
|
from .docker_runner import DockerRunner
|
||||||
from .git_helper import GitHelper
|
from .git_helper import GitHelper
|
||||||
|
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
|
|||||||
def quoted_output(container, cmd: str) -> str:
|
def quoted_output(container, cmd: str) -> str:
|
||||||
return "\n".join([
|
return "\n".join([
|
||||||
"```",
|
"```",
|
||||||
run_simple_command(container, cmd, print_result=False),
|
DockerRunner.run_simple_command(container, cmd, print_result=False),
|
||||||
"```"
|
"```"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@@ -2,18 +2,22 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import logging
|
import logging
|
||||||
from .git_helper import GitHelper
|
from .git_helper import GitHelper
|
||||||
from .docker_runner import run_simple_command
|
from .docker_runner import DockerRunner
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _get_program_version(container, program):
|
def _get_program_version(container, program):
|
||||||
return run_simple_command(container, cmd=f"{program} --version")
|
return DockerRunner.run_simple_command(container, cmd=f"{program} --version")
|
||||||
|
|
||||||
|
|
||||||
def _get_env_variable(container, variable):
|
def _get_env_variable(container, variable):
|
||||||
env = run_simple_command(container, cmd="env", print_result=False).split()
|
env = DockerRunner.run_simple_command(
|
||||||
|
container,
|
||||||
|
cmd="env",
|
||||||
|
print_result=False
|
||||||
|
).split()
|
||||||
for env_entry in env:
|
for env_entry in env:
|
||||||
if env_entry.startswith(variable):
|
if env_entry.startswith(variable):
|
||||||
return env_entry[len(variable) + 1:]
|
return env_entry[len(variable) + 1:]
|
||||||
@@ -22,7 +26,11 @@ def _get_env_variable(container, variable):
|
|||||||
|
|
||||||
def _get_pip_package_version(container, package):
|
def _get_pip_package_version(container, package):
|
||||||
VERSION_PREFIX = "Version: "
|
VERSION_PREFIX = "Version: "
|
||||||
package_info = run_simple_command(container, cmd=f"pip show {package}", print_result=False)
|
package_info = DockerRunner.run_simple_command(
|
||||||
|
container,
|
||||||
|
cmd=f"pip show {package}",
|
||||||
|
print_result=False
|
||||||
|
)
|
||||||
version_line = package_info.split("\n")[1]
|
version_line = package_info.split("\n")[1]
|
||||||
assert version_line.startswith(VERSION_PREFIX)
|
assert version_line.startswith(VERSION_PREFIX)
|
||||||
return version_line[len(VERSION_PREFIX):]
|
return version_line[len(VERSION_PREFIX):]
|
||||||
@@ -44,7 +52,7 @@ class SHATagger(TaggerInterface):
|
|||||||
class UbuntuVersionTagger(TaggerInterface):
|
class UbuntuVersionTagger(TaggerInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def tag_value(container):
|
def tag_value(container):
|
||||||
os_release = run_simple_command(container, "cat /etc/os-release").split("\n")
|
os_release = DockerRunner.run_simple_command(container, "cat /etc/os-release").split("\n")
|
||||||
for line in os_release:
|
for line in os_release:
|
||||||
if line.startswith("VERSION_ID"):
|
if line.startswith("VERSION_ID"):
|
||||||
return "ubuntu-" + line.split("=")[1].strip('"')
|
return "ubuntu-" + line.split("=")[1].strip('"')
|
||||||
|
Reference in New Issue
Block a user