tmatilai / vagrant-proxyconf

Vagrant plugin that configures the virtual machine to use proxies
MIT License
531 stars 74 forks source link

Explicitly disable a specific proxy, eg docker. #85

Closed jperville closed 9 years ago

jperville commented 9 years ago

I investigated why my chef-solo provisioned Vagrant box was restarting the docker daemon at every vagrant provision until I found out about the docker support in vagrant-proxyconf (see #69).

Here is what happened:

  1. vagrant provision is invoked by the user
  2. vagrant-proxyconf injects the http_proxy and no_proxy lines at the end of /etc/default/docker
  3. chef runs the docker::default recipe (from https://github.com/bflad/chef-docker) which detects that the /etc/default/docker file has changed, restores it to its original state (according to the attributes I have set) and restarts the docker daemon
  4. since docker is not very bright at restarting tens of containers at the same time, I lose half of my containers..

To avoid this situation, I would like to have an option to explicitly disable the docker proxy feature of vagrant-proxyconf, while keeping all the others working (apt, chef file cache etc). I through, after reading the code, that setting something like config.docker_proxy.http = false in my Vagrantfile would work, but it does not since the docker plugin uses the generic config.proxy.http which I don't want to disable.

My vagrant plugin skills (and my free time for now) are quite limited, so as a workaround I reverted my vagrant-proxyconf plugin to version 1.3.2, but in the long run I'd love to be able to disable a proxy explicitly without affecting the others.

otahi commented 9 years ago

Hi, @jperville Thank you for reporting with your use case. I will check it and try to find ways to solve it.

jperville commented 9 years ago

Thank you very much @otahi

tmatilai commented 9 years ago

Yeah, I like to avoid too many configuration options, but maybe we really need one here. Should be straightforward to add one.

otahi commented 9 years ago

I think disabling function is needed in these cases.

@tmatilai How about adding disabling function selection toconfig.proxy.enabled like this? Or adding new options or any ideas?

Now

Disabling the plugin

The plugin can be totally skipped by setting config.proxy.enabled to false or empty string (""). This can be useful to for example disable it for some provider.

Example Vagrantfile

Vagrant.configure("2") do |config|
  config.proxy.http = "http://192.168.0.2:3128/"

  config.vm.provider :my_cloud do |cloud, override|
    override.proxy.enabled = false
  end
  # ... other stuff
end

Then

Disabling the plugin

The plugin can be totally skipped by setting config.proxy.enabled to false or empty string (""). This can be useful to for example disable it for some provider. You can also specify disabling applications.

Example Vagrantfile

Vagrant.configure("2") do |config|
  config.proxy.http = "http://192.168.0.2:3128/"

  config.vm.provider :my_cloud do |cloud, override|
    override.proxy.enabled = false
  end
  config.vm.provider :my_company do |cloud, override|
    override.proxy.enabled = { docker: false }
  end
  # ... other stuff
end
otahi commented 9 years ago

Hi @jperville,

I'm sorry that I don't have enough time to realize above solution. Because there are lots of configuration for lots of functions. Now, I'm thinking about this problem again. This problem is caused by restarting docker. But this restarting is not necessary if there is no difference between old configuration and new one. So it can be inhibited when no difference. If it can be a solution, I want to make this change first. (I have not tried..)

https://github.com/tmatilai/vagrant-proxyconf/blob/master/lib/vagrant-proxyconf/action/configure_docker_proxy.rb#L52

How about this kind of modification:

            comm.sudo("mv #{path}.new #{path}")
            comm.sudo("rm #{tmp}")
            comm.sudo(service_restart_command)

:arrow_down:

            comm.sudo("diff #{path}.new #{path} > /dev/null || (mv #{path}.new #{path} ; #{service_restart_command})")
            comm.sudo("rm #{tmp}")
jperville commented 9 years ago

Hi @otahi,

Your proposal would prevent the docker daemon from restarting if the daemon is already running and the /etc/default/docker file is altered by the vagrant proxyconf plugin.

However, it would still be broken in my case, because the problem is not that the vagrant-proxyconf plugin explicitly restarts or not the docker daemon, but rather that it adds extra text in a configuration file (/etc/default/docker) that I am managing with my own provisioner (chef).

Since the file is modified to add the proxy lines just before the provisioner (chef) starts, the provisioner will always think that the file has changed, overwrite its contents with the managed content (without the proxy exports) and restart the docker daemon, which breaks my containers.

I don't see any better way than allowing to disable the docker proxies in vagrant proxyconf, or (if not possible) stick to version 1.3.2 which does not support docker proxies.

Thank you very much for caring about my issue.

otahi commented 9 years ago

Hi @jperville,

I understand the above solution is not enough for you. But I think it should be modified. Anyway, I will continue to think with disabling functions.

Thank you.

jperville commented 9 years ago

Hi @otahi, go for it, your proposal is useful, just not enough me for as you said. Thank you very much!

tmatilai commented 9 years ago

Closed by #92 and #93.