providers/docker: stream data for run

This commit is contained in:
Mitchell Hashimoto 2014-04-27 18:23:31 -07:00
parent 68fe0b4258
commit f1e1617cfd
3 changed files with 17 additions and 6 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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.