From f4939ee26a8aca85a03fd4044259e3e71ace9e4c Mon Sep 17 00:00:00 2001 From: Matt Brictson Date: Thu, 20 Jun 2024 17:06:06 -0700 Subject: [PATCH] Stream docker compose output while building image --- test/support/docker_wrapper.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/support/docker_wrapper.rb b/test/support/docker_wrapper.rb index 16f09672..cb63d30d 100644 --- a/test/support/docker_wrapper.rb +++ b/test/support/docker_wrapper.rb @@ -31,12 +31,20 @@ def stop def run_compose_command(command, echo=true) $stderr.puts "[docker compose] #{command}" if echo - stdout, stderr, status = Open3.capture3("docker compose #{command}") - - output = stdout + stderr - output.each_line { |line| $stderr.puts "[docker compose] #{line}" } if echo + Open3.popen2e("docker compose #{command}") do |stdin, outerr, wait_thread| + stdin.close + output = Thread.new { capture_stream(outerr, echo) } + [output.value, wait_thread.value] + end + end - [output, status] + def capture_stream(stream, echo=true) + buffer = +'' + while line = stream.gets + buffer << line + $stderr.puts("[docker compose] #{line}") if echo + end + buffer end def host_verify_options