leighmcculloch / vagrant-docker-compose

A Vagrant provisioner for docker compose.
ISC License
668 stars 72 forks source link

The plugin doesn't appear to be proxy-aware #60

Open scholarsmate opened 4 years ago

scholarsmate commented 4 years ago

Hi, I'm trying to use the docker-compose provisioner, but I need to use a proxy. I have configured the proxy settings in the VM using the vagrant proxyconf plugin.

  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "http://10.xxx.xxx.xxx:3128/"
    config.proxy.https    = "http://10.xxx.xxx.xxx:3128/"
    config.proxy.no_proxy = "localhost,127.0.0.1"
  end

The problem stems from vagrant-docker-compose-1.5.1/lib/vagrant-docker-compose/installer.rb:47:in 'fetch_file' , resulting in this error:

/opt/vagrant/embedded/lib/ruby/2.4.0/net/protocol.rb:44:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (OpenSSL::SSL::SSLError)
    from /opt/vagrant/embedded/lib/ruby/2.4.0/net/protocol.rb:44:in `ssl_socket_connect'
    from /opt/vagrant/embedded/lib/ruby/2.4.0/net/http.rb:948:in `connect'
    from /opt/vagrant/embedded/lib/ruby/2.4.0/net/http.rb:887:in `do_start'
    from /opt/vagrant/embedded/lib/ruby/2.4.0/net/http.rb:876:in `start'
    from /opt/vagrant/embedded/lib/ruby/2.4.0/net/http.rb:608:in `start'
    from /opt/vagrant/embedded/lib/ruby/2.4.0/net/http.rb:485:in `get_response'

https://stackoverflow.com/questions/15792999/how-to-set-a-proxy-in-rubys-net-http might be a useful reference in making the plugin work with the configured proxy.

leighmcculloch commented 4 years ago

Ah, so the vm config of the proxy is not impacting the download of docker-compose because the download happens on the host, not on the vm.

I think if you set this environment variable on the host Ruby should pick it up and use is for the net::http calls.

HTTP_PROXY

leighmcculloch commented 4 years ago

Please let me know if that works and we can add a note to the readme about it.

Todo:

simomat commented 4 years ago

I am behind a proxy, too and have a similar issues. I get an error where the host github.com cannot be resolved, but that's a common manifestation when we forget to set the proxy again:

   ...
 ubuntu: Downloading Docker Compose 1.24.1 for Linux x86_64
C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:906:in `rescue in block in connect': Failed to open TCP connection to github.com:443 (getaddrinfo: Der angegebene Host ist unbekannt. ) (SocketError)
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:903:in `block in connect'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/timeout.rb:93:in `block in timeout'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/timeout.rb:103:in `timeout'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:902:in `connect'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:887:in `do_start'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:876:in `start'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:608:in `start'
        from C:/Program Files (x86)/Vagrant/embedded/mingw32/lib/ruby/2.4.0/net/http.rb:485:in `get_response'
        from C:/Users/SIMONMA/.vagrant.d/gems/2.4.9/gems/vagrant-docker-compose-1.5.1/lib/vagrant-docker-compose/installer.rb:47:in `fetch_file'
...

This happens also when I set the proxy with HTTP_PROXY as env var. I tried it in lower and upper case but fails every time.

leighmcculloch commented 4 years ago

Got it, it must be the way that it is using Net::HTTP. We should be able to set the proxy based off that environment variable manually in the code. Anyone who is using a proxy and can take it and is open to making the change and opening a PR?