-
-
Save fnichol/7551540 to your computer and use it in GitHub Desktop.
<% | |
require 'socket' | |
def local_ip | |
@local_ip ||= begin | |
# turn off reverse DNS resolution temporarily | |
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true | |
UDPSocket.open do |s| | |
s.connect '64.233.187.99', 1 | |
s.addr.last | |
end | |
ensure | |
Socket.do_not_reverse_lookup = orig | |
end | |
end | |
def local_port ; 8123 ; end | |
def http_proxy_url ; "http://#{local_ip}:#{local_port}" ; end | |
def proxy_running? | |
socket = TCPSocket.new(local_ip, local_port) | |
true | |
rescue SocketError, Errno::ECONNREFUSED, | |
Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError | |
false | |
rescue Errno::EPERM, Errno::ETIMEDOUT | |
false | |
ensure | |
socket && socket.close | |
end | |
%> | |
--- | |
<% if proxy_running? %> | |
driver_config: | |
http_proxy: <%= http_proxy_url %> | |
https_proxy: <%= http_proxy_url %> | |
chef_omnibus_url: http://www.opscode.com/chef/install.sh | |
provision_command: "env http_proxy=<%= http_proxy_url %> bash -c 'curl -L http://www.opscode.com/chef/install.sh | bash'" | |
<% end %> |
#!/usr/bin/env bash | |
set -e | |
[ -n "$DEBUG" ] && set -x | |
if ! command -v lynx >/dev/null ; then | |
echo "$(basename $0) - lynx command not found, please install and retry" | |
exit 10 | |
fi | |
exec lynx "http://127.0.0.1:8123" |
#!/usr/bin/env bash | |
set -e | |
[ -n "$DEBUG" ] && set -x | |
if ! command -v polipo >/dev/null ; then | |
echo "$(basename $0) - polipo command not found, please install and retry" | |
exit 10 | |
fi | |
mkdir -p "$HOME/.polipo-cache" | |
exec polipo \ | |
proxyAddress='0.0.0.0' \ | |
disableIndexing='false' \ | |
disableServersList='false' \ | |
allowedClients='0.0.0.0/0' \ | |
diskCacheRoot='~/.polipo-cache' |
With reference to test-kitchen/kitchen-vagrant#90: remote_file
is not always cached with spike as is. Need to add the following to .kitchen.local.yml
:
provisioner:
chef_omnibus_url: http://www.getchef.com/chef/install.sh
solo_rb:
http_proxy: <%= http_proxy_url %>
https_proxy: <%= http_proxy_url %>
Even with this, it seems that some apt
calls are not cached. (see issue link for more details)
Thanks so much!
I had an issue with Polipo 1.0.4.1 from homebrew on OSX 10.9.2., random seg faults. The 1.1.0 works much better so I put in a PR to homebrew.
kitchen list --debug
is depreciated. Use kitchen diagnose
to examine your configuration.
I suggest using https://www.getchef.com
instead of http://www.getchef.com
.
@slyness You're totally right, updated the README, thanks!
@pmocek Yes, you're right about highly preferring the HTTPS URL over the HTTP one, but I'm majorly cheating here in this testing context to get faster cached packages. Easily something you might want to change in your version. I've updated the YAML with a comment that I hope is slightly clearer.
@fnichol Works like a charm, cheers. I had huge issues with Polipo. First segfaults with the MacPorts version and then proxy issues with the latest release from GitHub. apt-get update
would only return Ignore ...
or 404
. Looks like the proxy implementation might be faulty in some ways.
I'm using SquidMan now and it works without any problems so far.
@fnichol Just took your snippet and used it for vagrant-proxyconf
. Works great.
The only chef_omnibus_url that still works with a HTTP proxy cache is http://www.opscode.com/chef/install.sh I'm afraid. The rest (http://www.getchef.com/chef/install.sh, http://www.chef.io/chef/install.sh) send the request to omnitruck-direct.chef.io over HTTPS and the S3 URL is over HTTPS as well.
Tested with Ubuntu 15.04:
root@9c04906b5ba8:~# curl -L http://www.opscode.com/chef/install.sh -o /tmp/install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19970 100 19970 0 0 39383 0 --:--:-- --:--:-- --:--:-- 39466
root@9c04906b5ba8:~# bash /tmp/install.sh -v 12.5.1
Getting information for chef stable 12.5.1 for ubuntu...
downloading http://omnitruck-direct.chef.io/stable/chef/metadata?v=12.5.1&p=ubuntu&pv=15.04&m=x86_64
to file /tmp/install.sh.105/metadata.txt
trying curl...
url http://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.5.1-1_amd64.deb
md5 d8fec2da288e94a7e2d649803a9d70f4
sha256 656a4c4a8fd64d74d1d970fb0d07076d6f1d8230d37d751f2c3698a52d82c070
version 12.5.1downloaded metadata file looks valid...
downloading http://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.5.1-1_amd64.deb
to file /tmp/install.sh.105/chef_12.5.1-1_amd64.deb
trying curl...
Comparing checksum with sha256sum...
Installing chef 12.5.1
installing with dpkg...
(Reading database ... 26118 files and directories currently installed.)
Preparing to unpack .../chef_12.5.1-1_amd64.deb ...
Unpacking chef (12.5.1-1) over (12.5.1-1) ...
Setting up chef (12.5.1-1) ...
Thank you for installing Chef!
root@9c04906b5ba8:~# curl -L http://www.chef.io/chef/install.sh -o /tmp/install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19957 100 19957 0 0 42416 0 --:--:-- --:--:-- --:--:-- 42371
root@9c04906b5ba8:~# bash /tmp/install.sh -v 12.5.1
Getting information for chef stable 12.5.1 for ubuntu...
downloading http://www.chef.io/stable/chef/metadata?v=12.5.1&p=ubuntu&pv=15.04&m=x86_64
to file /tmp/install.sh.12/metadata.txt
trying curl...
url https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.5.1-1_amd64.deb
md5 d8fec2da288e94a7e2d649803a9d70f4
sha256 656a4c4a8fd64d74d1d970fb0d07076d6f1d8230d37d751f2c3698a52d82c070
version 12.5.1downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.5.1-1_amd64.deb
to file /tmp/install.sh.12/chef_12.5.1-1_amd64.deb
trying curl...
Comparing checksum with sha256sum...
Installing chef 12.5.1
installing with dpkg...
(Reading database ... 26118 files and directories currently installed.)
Preparing to unpack .../chef_12.5.1-1_amd64.deb ...
Unpacking chef (12.5.1-1) over (12.5.1-1) ...
Setting up chef (12.5.1-1) ...
Thank you for installing Chef!
root@9c04906b5ba8:~# curl -L http://www.getchef.com/chef/install.sh -o /tmp/install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 19971 100 19971 0 0 91830 0 --:--:-- --:--:-- --:--:-- 91830
root@9c04906b5ba8:~# bash /tmp/install.sh -v 12.5.1
Getting information for chef stable 12.5.1 for ubuntu...
downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=12.5.1&p=ubuntu&pv=15.04&m=x86_64
to file /tmp/install.sh.198/metadata.txt
trying curl...
url https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.5.1-1_amd64.deb
md5 d8fec2da288e94a7e2d649803a9d70f4
sha256 656a4c4a8fd64d74d1d970fb0d07076d6f1d8230d37d751f2c3698a52d82c070
version 12.5.1downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.5.1-1_amd64.deb
to file /tmp/install.sh.198/chef_12.5.1-1_amd64.deb
trying curl...
Comparing checksum with sha256sum...
Installing chef 12.5.1
installing with dpkg...
(Reading database ... 26118 files and directories currently installed.)
Preparing to unpack .../chef_12.5.1-1_amd64.deb ...
Unpacking chef (12.5.1-1) over (12.5.1-1) ...
Setting up chef (12.5.1-1) ...
Thank you for installing Chef!
Would be great if the proxy_running can exit in a quick way when polipo is not running otherwise it crawls every kitchen command.
Noticing that you catch Errno::ETIMEDOUT
here but without doing anything to enforce a meaningful timeout on TCPSocket.new
. By default it's 75 seconds which makes most kitchen commands unusable in the event that this gets triggered.
Awesome! Must try this.