Merge pull request #9761 from briancain/FIX-DOCKER-EXEC
Use Util::SafeExec if docker-exec is run with `-t` option
This commit is contained in:
commit
e1129d27f9
|
@ -1,3 +1,5 @@
|
|||
require 'vagrant/util/safe_exec'
|
||||
|
||||
module VagrantPlugins
|
||||
module DockerProvider
|
||||
module Command
|
||||
|
@ -84,18 +86,21 @@ module VagrantPlugins
|
|||
|
||||
# Run this interactively if asked.
|
||||
exec_options = options
|
||||
exec_options[:stdin] = true if options[:pty]
|
||||
|
||||
output = ""
|
||||
machine.provider.driver.execute(*exec_cmd, exec_options) do |type, data|
|
||||
output += data
|
||||
end
|
||||
if options[:pty]
|
||||
Vagrant::Util::SafeExec.exec(exec_cmd[0], *exec_cmd[1..-1])
|
||||
else
|
||||
output = ""
|
||||
machine.provider.driver.execute(*exec_cmd, exec_options) do |type, data|
|
||||
output += data
|
||||
end
|
||||
|
||||
output_options = {}
|
||||
output_options[:prefix] = false if !options[:prefix]
|
||||
output_options = {}
|
||||
output_options[:prefix] = false if !options[:prefix]
|
||||
|
||||
if !output.empty?
|
||||
machine.ui.output(output.chomp, **output_options)
|
||||
if !output.empty?
|
||||
machine.ui.output(output.chomp, **output_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,14 +5,30 @@ describe VagrantPlugins::DockerProvider::Command::Exec do
|
|||
include_context "unit"
|
||||
include_context "command plugin helpers"
|
||||
|
||||
let(:sandbox) do
|
||||
isolated_environment
|
||||
let(:env) { {
|
||||
action_runner: action_runner,
|
||||
machine: machine,
|
||||
ui: Vagrant::UI::Silent.new,
|
||||
} }
|
||||
|
||||
subject { described_class.new(app, env) }
|
||||
let(:argv) { [] }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
isolated_environment.tap do |env|
|
||||
env.vagrantfile("")
|
||||
end
|
||||
end
|
||||
|
||||
let(:argv) { [] }
|
||||
let(:env) { sandbox.create_vagrant_env }
|
||||
let(:iso_vagrant_env) { iso_env.create_vagrant_env }
|
||||
|
||||
let(:vagrantfile_path) { File.join(env.cwd, "Vagrantfile") }
|
||||
let(:action_runner) { double("action_runner") }
|
||||
let(:box) do
|
||||
box_dir = iso_env.box3("foo", "1.0", :virtualbox)
|
||||
Vagrant::Box.new("foo", :virtualbox, "1.0", box_dir)
|
||||
end
|
||||
let(:machine) { iso_vagrant_env.machine(iso_vagrant_env.machine_names[0], :dummy) }
|
||||
|
||||
subject { described_class.new(argv, env) }
|
||||
|
||||
|
@ -23,14 +39,19 @@ describe VagrantPlugins::DockerProvider::Command::Exec do
|
|||
|
||||
before do
|
||||
allow(Vagrant.plugin("2").manager).to receive(:commands).and_return({})
|
||||
allow(subject).to receive(:exec_command)
|
||||
end
|
||||
|
||||
after do
|
||||
sandbox.close
|
||||
end
|
||||
describe "#exec_command" do
|
||||
describe "with -t option" do
|
||||
let(:command) { ["/bin/bash"] }
|
||||
let(:options) { {pty: "true"} }
|
||||
|
||||
describe "#execute" do
|
||||
it "calls Safe Exec" do
|
||||
allow(Kernel).to receive(:exec).and_return(true)
|
||||
expect(Vagrant::Util::SafeExec).to receive(:exec).with("docker", "exec", "-t", anything, "/bin/bash")
|
||||
subject.exec_command(machine, command, options)
|
||||
end
|
||||
end
|
||||
describe "without a command" do
|
||||
let(:argv) { [] }
|
||||
|
||||
|
|
Loading…
Reference in New Issue