From b656bf4ae53fbeefe3751e3f41e3b8a3decf899d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 23 Oct 2014 15:02:46 -0700 Subject: [PATCH] providers/docker: build output [GH-3739] --- CHANGELOG.md | 1 + plugins/providers/docker/action/build.rb | 14 +++++++++++--- plugins/providers/docker/driver.rb | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf06574b..2fbac3d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ IMPROVEMENTS: - guests/suse: Support NFS client install, rsync setup. [GH-4492] - guests/tinycore: Support changing host names. [GH-4469] - guests/windows: Hostname can be set without reboot. [GH-4687] + - providers/docker: Build output is now shown. [GH-3739] - providers/docker: Can now start containers from private repositories more easily. Vagrant will login for you if you specify auth. [GH-4042] - providers/docker: `stop_timeout` can be used to modify the `docker stop` diff --git a/plugins/providers/docker/action/build.rb b/plugins/providers/docker/action/build.rb index 61cbcb8a6..ddc96084c 100644 --- a/plugins/providers/docker/action/build.rb +++ b/plugins/providers/docker/action/build.rb @@ -1,9 +1,13 @@ require "log4r" +require "vagrant/util/ansi_escape_code_remover" + module VagrantPlugins module DockerProvider module Action class Build + include Vagrant::Util::ANSIEscapeCodeRemover + def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::docker::build") @@ -37,9 +41,13 @@ module VagrantPlugins machine.ui.output(I18n.t("docker_provider.building")) image = machine.provider.driver.build( build_dir, - extra_args: machine.provider_config.build_args, - ) - machine.ui.detail("Image: #{image}") + extra_args: machine.provider_config.build_args) do |type, data| + data = remove_ansi_escape_codes(data.chomp).chomp + env[:ui].detail(data) if data != "" + end + + # Output the final image + machine.ui.detail("\nImage: #{image}") # Store the image ID image_file.open("w") do |f| diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 080b5d0f3..3ce34dc6e 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -14,10 +14,10 @@ module VagrantPlugins @executor = Executor::Local.new end - def build(dir, **opts) + def build(dir, **opts, &block) args = Array(opts[:extra_args]) args << dir - result = execute('docker', 'build', *args) + result = execute('docker', 'build', *args, &block) matches = result.scan(/Successfully built (.+)$/i) if matches.empty? # This will cause a stack trace in Vagrant, but it is a bug