Brian Cain 4d70856b8a
Enhance docker build matching for determining built container ID
Prior to this commit, docker would look for a container ID based on
"Successfully built" string. This output does not exist if a user has
enabled the experimental feature buildkit. This commit updates the build
behavior to match against both kinds of outputs, and instead of using
`scan`, it uses MatchData and groups the container id with match group
name `:id` instead of making hard assumptions with the matches being
contained inside arrays from scan.
2019-11-19 10:59:28 -08:00

44 lines
1.2 KiB
Ruby

require "vagrant/util/busy"
require "vagrant/util/subprocess"
module VagrantPlugins
module DockerProvider
module Executor
# The Local executor executes a Docker client that is running
# locally.
class Local
def execute(*cmd, **opts, &block)
# Append in the options for subprocess
cmd << { notify: [:stdout, :stderr] }
interrupted = false
int_callback = ->{ interrupted = true }
result = ::Vagrant::Util::Busy.busy(int_callback) do
::Vagrant::Util::Subprocess.execute(*cmd, &block)
end
result.stderr.gsub!("\r\n", "\n")
result.stdout.gsub!("\r\n", "\n")
if result.exit_code != 0 && !interrupted
raise Errors::ExecuteError,
command: cmd.inspect,
stderr: result.stderr,
stdout: result.stdout
end
if result.stdout.to_s.strip.length == 0
result.stderr
else
result.stdout
end
end
def windows?
::Vagrant::Util::Platform.windows? || ::Vagrant::Util::Platform.wsl?
end
end
end
end
end