Add option for docker executor to handle stderr from results

Instead of always joining stdout and stderr, only join the two if the
caller explicitly asks for it. Otherwise, only return stdout.
This commit is contained in:
Brian Cain 2019-11-22 12:04:09 -08:00
parent 1699821571
commit 2901dae948
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 10 additions and 7 deletions

View File

@ -20,9 +20,10 @@ module VagrantPlugins
#
# @return [String] id - ID matched from the docker build output.
def build(dir, **opts, &block)
args = Array(opts[:extra_args])
args << dir
result = execute('docker', 'build', *args, &block)
args = Array(opts[:extra_args])
args << dir
opts = {with_stderr: true}
result = execute('docker', 'build', *args, opts, &block)
matches = result.match(/Successfully built (?<id>.+)$/i)
if !matches
# Check for the new output format 'writing image sha256...'

View File

@ -27,10 +27,12 @@ module VagrantPlugins
stdout: result.stdout
end
if result.stdout.to_s.strip.length == 0
result.stderr
else
result.stdout
if opts
if opts[:with_stderr]
return result.stdout + " " + result.stderr
else
return result.stdout
end
end
end