Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions webhook_server_container/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def _run_build_container(
tag_name=tag,
clone_repo_dir=clone_repo_dir,
):
build_rc, build_out, build_err = self.run_podman_command(command=podman_build_cmd)
build_rc, build_out, build_err = self.run_podman_command(command=podman_build_cmd, pipe=True)
output: Dict[str, str] = {
"title": "Build container",
"summary": "",
Expand Down Expand Up @@ -2065,13 +2065,13 @@ def fix_podman_bug(self) -> None:
shutil.rmtree("/tmp/storage-run-1000/containers", ignore_errors=True)
shutil.rmtree("/tmp/storage-run-1000/libpod/tmp", ignore_errors=True)

def run_podman_command(self, command: str) -> Tuple[bool, str, str]:
rc, out, err = run_command(command=command, log_prefix=self.log_prefix)
def run_podman_command(self, command: str, pipe: bool = False) -> Tuple[bool, str, str]:
rc, out, err = run_command(command=command, log_prefix=self.log_prefix, pipe=pipe)
if rc:
return rc, out, err

if self.is_podman_bug(err=err):
self.fix_podman_bug()
return run_command(command=command, log_prefix=self.log_prefix)
return run_command(command=command, log_prefix=self.log_prefix, pipe=pipe)

return rc, out, err
15 changes: 12 additions & 3 deletions webhook_server_container/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def run_command(
timeout: Optional[int] = None,
capture_output: bool = True,
check: bool = False,
pipe: bool = False,
**kwargs: Any,
) -> Tuple[bool, str, str]:
"""
Expand All @@ -81,24 +82,32 @@ def run_command(
shell (bool, default False): run subprocess with shell toggle
timeout (int, optional): Command wait timeout
capture_output (bool, default True): Capture command output
check (boot, default False): If check is True and the exit code was non-zero, it raises a
check (bool, default False): If check is True and the exit code was non-zero, it raises a
CalledProcessError
pipe (bool, default False): If pipe is True, text and capture_output would be set to False. stdout and
stderr, would be set to subprocess.PIPE and passed to subprocess.run call


Returns:
tuple: True, out if command succeeded, False, err otherwise.
"""
logger = get_logger_with_params(name="helpers")

text = True
out_decoded: str = ""
err_decoded: str = ""
if pipe:
capture_output = False
text = False
kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.PIPE
try:
logger.debug(f"{log_prefix} Running '{command}' command")
sub_process = subprocess.run(
shlex.split(command),
capture_output=capture_output,
check=check,
shell=shell,
text=True,
text=text,
timeout=timeout,
**kwargs,
)
Expand Down