From 0e29dd5668147df8064975b664d87904f0a5932b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 22 Oct 2014 16:17:13 -0700 Subject: [PATCH] commands/rsync: handle proxy machines [GH-4066] --- CHANGELOG.md | 1 + lib/vagrant/action/builtin/mixin_synced_folders.rb | 3 ++- plugins/providers/docker/cap/proxy_machine.rb | 12 ++++++++++++ plugins/providers/docker/plugin.rb | 5 +++++ plugins/synced_folders/rsync/command/rsync.rb | 14 +++++++++++++- templates/locales/en.yml | 4 ++++ 6 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 plugins/providers/docker/cap/proxy_machine.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 64aca449a..ebfc3190c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ BUG FIXES: - core: Fix cases where sometimes SSH connection would hang. - command/docker-logs: Won't crash if container is removed. [GH-3990] + - command/rsync: Sync to Docker containers properly. [GH-4066] - providers/docker: Create args works. [GH-4526] - providers/docker: Nicer error if package is called. [GH-4595] - providers/docker: Host IP restriction is forwarded through. [GH-4505] diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index b636d3526..da8437dee 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -93,11 +93,12 @@ module Vagrant config = opts[:config] config ||= machine.config.vm + config_folders = config.synced_folders folders = {} # Determine all the synced folders as well as the implementation # they're going to use. - config.synced_folders.each do |id, data| + config_folders.each do |id, data| # Ignore disabled synced folders next if data[:disabled] diff --git a/plugins/providers/docker/cap/proxy_machine.rb b/plugins/providers/docker/cap/proxy_machine.rb new file mode 100644 index 000000000..20dd487cc --- /dev/null +++ b/plugins/providers/docker/cap/proxy_machine.rb @@ -0,0 +1,12 @@ +module VagrantPlugins + module DockerProvider + module Cap + module ProxyMachine + def self.proxy_machine(machine) + return nil if !machine.provider.host_vm? + machine.provider.host_vm + end + end + end + end +end diff --git a/plugins/providers/docker/plugin.rb b/plugins/providers/docker/plugin.rb index 1558aa51d..36ab08687 100644 --- a/plugins/providers/docker/plugin.rb +++ b/plugins/providers/docker/plugin.rb @@ -56,6 +56,11 @@ module VagrantPlugins Cap::PublicAddress end + provider_capability("docker", "proxy_machine") do + require_relative "cap/proxy_machine" + Cap::ProxyMachine + end + protected def self.init! diff --git a/plugins/synced_folders/rsync/command/rsync.rb b/plugins/synced_folders/rsync/command/rsync.rb index 6703ffaaa..e2ab5988f 100644 --- a/plugins/synced_folders/rsync/command/rsync.rb +++ b/plugins/synced_folders/rsync/command/rsync.rb @@ -27,6 +27,18 @@ module VagrantPlugins # Go through each machine and perform the rsync error = false with_target_vms(argv) do |machine| + if machine.provider.capability?(:proxy_machine) + proxy = machine.provider.capability(:proxy_machine) + if proxy + machine.ui.warn(I18n.t( + "vagrant.rsync_proxy_machine", + name: machine.name.to_s, + provider: machine.provider_name.to_s)) + + machine = proxy + end + end + if !machine.communicate.ready? machine.ui.error(I18n.t("vagrant.rsync_communicator_not_ready")) error = true @@ -34,7 +46,7 @@ module VagrantPlugins end # Determine the rsync synced folders for this machine - folders = synced_folders(machine)[:rsync] + folders = synced_folders(machine, cached: true)[:rsync] next if !folders || folders.empty? # Get the SSH info for this machine so we can access it diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 19ee8131f..c2d08f187 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -195,6 +195,10 @@ en: Rsyncing folder: %{hostpath} => %{guestpath} rsync_folder_excludes: " - Exclude: %{excludes}" rsync_installing: "Installing rsync to the VM..." + rsync_proxy_machine: |- + The provider ('%{provider}') for the machine '%{name}' is + using a proxy machine. RSync will sync to this proxy + instead of directly to the environment itself. rsync_ssh_password: |- The machine you're rsyncing folders to is configured to use password-based authentication. Vagrant can't script rsync to automatically