From 2901dae9484e5311e68517016ddfe57f257734df Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 22 Nov 2019 12:04:09 -0800 Subject: [PATCH] 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. --- plugins/providers/docker/driver.rb | 7 ++++--- plugins/providers/docker/executor/local.rb | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index f2b382fc3..8932c74a2 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -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 (?.+)$/i) if !matches # Check for the new output format 'writing image sha256...' diff --git a/plugins/providers/docker/executor/local.rb b/plugins/providers/docker/executor/local.rb index f99c4f929..7825a0292 100644 --- a/plugins/providers/docker/executor/local.rb +++ b/plugins/providers/docker/executor/local.rb @@ -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