Created
March 1, 2025 23:17
-
-
Save BakedCookie/8ed36769b8528c3fbb77f2efc25a211a to your computer and use it in GitHub Desktop.
2 Implementation
This file contains hidden or 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
def run_bash_show_output(command: str): | |
process = sub.Popen( | |
command.strip(), | |
stdout=sub.PIPE, | |
stderr=sub.STDOUT, | |
shell=True, | |
encoding='utf-8', | |
errors='replace' | |
) | |
while True: | |
realtime_output = process.stdout.readline() # type: ignore | |
if realtime_output == '' and process.poll() is not None: | |
break | |
if realtime_output: | |
print(realtime_output.strip(), flush=True) | |
return process | |
------------------------------------------------------------------------------ | |
bash_nerdctl_build = com.run_bash_show_output( | |
f''' | |
nerdctl build -f Dockerfile --address=/run/k3s/containerd/containerd.sock --namespace k8s.io -t "nexus.seicdevops.com/docker-dev-share/noms/{self.service_name}:{self.build_tag}" . | |
''' | |
) | |
if bash_nerdctl_build.returncode: | |
print("build error, stderr output:") | |
print(f"{bash_nerdctl_build.stderr}") | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure what specific case you have here, but if you just want to trigger the build to run and present the output to the user, then you could do it with
sub.run()
and not capture the output. It would allow the build output to flow naturally in the terminal.