2014-04-16 02:58:28 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Action
|
|
|
|
class PrepareSSH
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
# If we aren't using a host VM, then don't worry about it
|
|
|
|
return @app.call(env) if !env[:machine].provider.host_vm?
|
|
|
|
|
2014-04-16 03:02:19 +00:00
|
|
|
env[:machine].ui.output(I18n.t(
|
|
|
|
"docker_provider.ssh_through_host_vm"))
|
|
|
|
|
2014-04-16 02:58:28 +00:00
|
|
|
# Modify the SSH info to be the host VM's info
|
|
|
|
env[:ssh_info] = env[:machine].provider.host_vm.ssh_info
|
|
|
|
|
|
|
|
# Modify the SSH options for when we `vagrant ssh`...
|
|
|
|
ssh_opts = env[:ssh_opts] || {}
|
|
|
|
|
2014-12-07 10:02:50 +00:00
|
|
|
# Build the command we'll execute within the Docker host machine:
|
2014-08-29 18:11:53 +00:00
|
|
|
ssh_command = env[:machine].communicate.container_ssh_command
|
|
|
|
if !Array(ssh_opts[:extra_args]).empty?
|
|
|
|
ssh_command << " #{Array(ssh_opts[:extra_args]).join(" ")}"
|
|
|
|
end
|
2014-04-16 02:58:28 +00:00
|
|
|
|
2014-12-07 10:02:50 +00:00
|
|
|
# Modify the SSH options for the original command:
|
2014-08-29 18:11:53 +00:00
|
|
|
# Append "-t" to force a TTY allocation
|
|
|
|
ssh_opts[:extra_args] = ["-t"]
|
2014-12-07 10:02:50 +00:00
|
|
|
# Enable Agent forwarding when requested for the target VM
|
|
|
|
if env[:machine].ssh_info[:forward_agent]
|
|
|
|
ssh_opts[:extra_args] << "-o ForwardAgent=yes"
|
|
|
|
end
|
2014-08-29 18:11:53 +00:00
|
|
|
ssh_opts[:extra_args] << ssh_command
|
2014-04-16 02:58:28 +00:00
|
|
|
|
|
|
|
# Set the opts
|
|
|
|
env[:ssh_opts] = ssh_opts
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|