From f1e1617cfd89cafcdbc3e9a3d7f8d029bca70770 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 27 Apr 2014 18:23:31 -0700 Subject: [PATCH] providers/docker: stream data for run --- plugins/providers/docker/action/create.rb | 13 ++++++++++--- plugins/providers/docker/driver.rb | 6 +++--- templates/locales/providers_docker.yml | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/providers/docker/action/create.rb b/plugins/providers/docker/action/create.rb index 381eee7f7..abd4ce152 100644 --- a/plugins/providers/docker/action/create.rb +++ b/plugins/providers/docker/action/create.rb @@ -46,13 +46,20 @@ module VagrantPlugins env[:ui].detail(" Link: #{name}:#{other}") end - cid = @driver.create(params) - - # If this isn't just a one-off command, then save the ID if env[:machine_action] != :run_command + # For regular "ups" create it and get the CID + cid = @driver.create(params) env[:ui].detail(" \n"+I18n.t( "docker_provider.created", id: cid[0...16])) @machine.id = cid + elsif params[:detach] + env[:ui].detail(" \n"+I18n.t("docker_provider.running_detached")) + else + # For run commands, we run it and stream back the output + env[:ui].detail(" \n"+I18n.t("docker_provider.running")) + @driver.create(params) do |type, data| + env[:ui].detail(data) + end end @app.call(env) diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index c73b7f548..6cbf09060 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -25,7 +25,7 @@ module VagrantPlugins match[1] end - def create(params) + def create(params, &block) image = params.fetch(:image) links = params.fetch(:links) ports = Array(params[:ports]) @@ -34,7 +34,7 @@ module VagrantPlugins cmd = Array(params.fetch(:cmd)) env = params.fetch(:env) - run_cmd = %W(docker run --name #{name} -d) + run_cmd = %W(docker run --name #{name}) run_cmd << "-d" if params[:detach] run_cmd += env.map { |k,v| ['-e', "#{k}=#{v}"] } run_cmd += links.map { |k, v| ['--link', "#{k}:#{v}"] } @@ -45,7 +45,7 @@ module VagrantPlugins run_cmd += params[:extra_args] if params[:extra_args] run_cmd += [image, cmd] - execute(*run_cmd.flatten).chomp + execute(*run_cmd.flatten, &block).chomp end def state(cid) diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index 6ff514a17..3652d2c97 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -45,6 +45,10 @@ en: vagrant docker-run web -- rails new . + running: |- + Container is starting. Output will stream in below... + running_detached: |- + Container is started detached. ssh_through_host_vm: |- SSH will be proxied through the Docker virtual machine since we're not running Docker natively. This is just a notice, and not an error.