tmatilai / vagrant-proxyconf

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

Docker proxy config doesn't work on Ubuntu 15.04 #133

Closed mrsheepuk closed 9 years ago

mrsheepuk commented 9 years ago

With the introduction of systemd, an extra step is required to make the proxy configuration work - analogous to the handling used for CoreOS whereby the systemd service unit is updated to pull in the environment from /etc/default/docker. I'm not experienced with Ruby so I may have made some large errors here, but this now works on my local environment against a ubuntu/vivid image.

mrsheepuk commented 9 years ago

Well that totally failed :) I've no idea how to update the tests but I'll give it a go.

mrsheepuk commented 9 years ago

Sorry I'm not sure how to fix this up - it looks like it's failed on a code complexity check rather than the tests as such, and I'm not sure how best to address this. If someone can point me in the right direction it would be appreciated!

otahi commented 9 years ago

@mrsheepuk Thank you for your trying a pull request!! It is very welcome!! I will check it later. I feel it could be more simple, please give me time to check with ubuntu/vivid image.

otahi commented 9 years ago

@mrsheepuk I cannot reproduce the problem you indicated.. It means no problem for my proxy configuration with Docker on ubuntu/vivid.

I did vagrant up with ubuntu/vivid64, next installed dcoker.io, then did vagrant reload. That seems OK. What is the difference?

Vagrant and Vagrant-proxyconf version.

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant -v
Vagrant 1.7.4
[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant plugin list | grep -i vagrant-proxyconf
vagrant-proxyconf (1.5.1)
[otahi@otahiair vagrant-proxyconf-issue-133]$

My vagrant file

[otahi@otahiair vagrant-proxyconf-issue-133]$ cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/vivid64"
  config.vbguest.auto_update = false
  config.vm.provider 'virtualbox' do |v|
    v.customize ['modifyvm', :id, '--memory', '256']
  end
  config.proxy.http     = "http://user:pass@proxy.example.com:8080"
  config.proxy.https    = "http://user:pass@proxy.example.com:8080"
  config.proxy.no_proxy = "/var/run/docker.sock"
end

vagrant reload log

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'ubuntu/vivid64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Configuring proxy for Apt...
==> default: Configuring proxy for Docker...
==> default: Configuring proxy environment variables...
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/otahi/tmp/vagrant-proxyconf-issue-133
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
[otahi@otahiair vagrant-proxyconf-issue-133]$

Check proxy related environment variables.

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant ssh -c 'sudo strings /proc/`sudo pgrep docker|head -n1`/environ | grep -i proxy '
HTTP_PROXY=http://user:pass@proxy.example.com:8080
NO_PROXY=/var/run/docker.sock
http_proxy=http://user:pass@proxy.example.com:8080
no_proxy=/var/run/docker.sock
Connection to 127.0.0.1 closed.
[otahi@otahiair vagrant-proxyconf-issue-133]$

And I checked systemd exists.

[otahi@otahiair vagrant-proxyconf-issue-133]$ vagrant ssh -c 'ps -p1 | grep systemd'    1 ?        00:00:01 systemd
Connection to 127.0.0.1 closed.
[otahi@otahiair vagrant-proxyconf-issue-133]$
mrsheepuk commented 9 years ago

@otahi Interesting - I'm using an ansible role https://github.com/angstwad/docker.ubuntu which installs the docker-engine package from the official docker repo, instead of the docker.io package from the ubuntu repos.

docker-engine is the package which the supported install process for ubuntu (https://docs.docker.com/installation/ubuntulinux/) - i.e. what you get if you run curl -sSL https://get.docker.com/ | sh

mrsheepuk commented 9 years ago

@otahi Here's the steps to reproduce:

vagrant init ubuntu/vivid64
# add proxy config to vagrant file if needed.
vagrant up
vagrant ssh

On the ssh term:

curl -sSL https://get.docker.com/ | sh
exit

Then do the vagrant reload. I've just tried this and the proxy config does not work. Retrying this process with my pull request in place correctly configures it - although I don't know whether it's the "best" way to configure it, it does work.

It's also possible to specify the proxy in a [Service] section in a .conf file in /etc/systemd/system/docker.service.d/ which provides a side-load extra piece of config for the service - e.g. in /etc/systemd/system/docker.service.d/http-proxy.conf this works:

[Service]
Environment="HTTP_PROXY=http://10.0.0.10:8080/" "HTTPS_PROXY=http://10.0.0.10:8080/"

I don't know how such a file would get created, but it's a very clean way of configuring the proxy as it doesn't involve any assumptions about the current configuration file for the systemd service.

otahi commented 9 years ago

@mrsheepuk Thank you for your quick response.

Now, I understand the installed docker package is different. I found the docker.io package reads /etc/default/docker in /lib/systemd/system/docker.service.

I will recheck with your steps.

otahi commented 9 years ago

@mrsheepuk I have added lib/vagrant-proxyconf/cap/debian/docker_proxy_conf.rb for Docker official package on Debian/Ubuntu. See https://github.com/otahi/vagrant-proxyconf/commit/b4f8689100fc8cdfe814e2acf71b8e8a054228e9 on https://github.com/otahi/vagrant-proxyconf/tree/fix_ubuntu_docker. Can you check it?

mrsheepuk commented 9 years ago

I'll check it in a couple of hours time - thanks!

mrsheepuk commented 9 years ago

@otahi Thanks for this - I've just tested and it works fine on 15.04 with the official docker docker package now - however this will also apply to all versions of Debian / Ubuntu rather than just those using systemd (i.e. 15.04 onwards in Ubuntu, not sure about Debian versions but assume a similar situation there).

I've just spun up a 15.04 and 14.04 image, installed docker then done a vagrant reload - on 14.04 you now get the following error on the reload:

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

systemctl daemon-reload

Stdout from the command:

Stderr from the command:

stdin: is not a tty
bash: line 2: systemctl: command not found

In my pull request, I was guarding against this using this line:

elsif machine.communicate.test('ps -p1 | grep systemd')

... although that's not bullet-proof, it should catch the vast majority of cases.

otahi commented 9 years ago

@mrsheepuk Thank you for your indication. Yes, your are right. I was missing that. I think following matrix should be tested. I am trying to coding and testing to fill this matrix.

Guest OS \ Package docker.io package docker official package
Debian/Ubuntu systemd
Debian/Ubuntu none systemd
otahi commented 9 years ago

@mrsheepuk I have implemented and tested partially.

Guest OS \ Package docker.io package docker official package
Debian/Ubuntu systemd Ubuntu 15.04 :white_check_mark:
Debian/Ubuntu none systemd Ubuntu 14.04 :white_check_mark:

I have not tested on none systemd systems. If you are OK, please replace your commit to my commits with my PR https://github.com/mrsheepuk/vagrant-proxyconf/pull/1.

I will test it on none systemd systems in few days. I will test missing part of the matrix in a few days.

I had misunderstood Ubuntu 14.04 systemd condition, so I changed some description.

otahi commented 9 years ago

@mrsheepuk I have tested the matrix. And all tests are OK.

Guest OS \ Package docker.io package docker official package
Debian/Ubuntu systemd Ubuntu 15.04 :white_check_mark: Ubuntu 15.04 :white_check_mark:
Debian/Ubuntu none systemd Ubuntu 14.04 :white_check_mark: Ubuntu 14.04 :white_check_mark:
mrsheepuk commented 9 years ago

@otahi Great, thanks - I'll pull in your commits and update the pull request.

otahi commented 9 years ago

@mrsheepuk Thank you so much! I appreciate your pull request!

mrsheepuk commented 9 years ago

@otahi no problem, thanks for doing the actual work to integrate it successfully!