Skip to content

Instantly share code, notes, and snippets.

@obazoud
Forked from fnichol/README.md
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obazoud/3973d7320d00393ba3e0 to your computer and use it in GitHub Desktop.
Save obazoud/3973d7320d00393ba3e0 to your computer and use it in GitHub Desktop.

Auto-enable Local HTTP Caching in Test Kitchen

Note: total experiment and hack, looks nasty, could be awesome:

Setup

  • Drop the kitchen.local.yml into $HOME/.kitchen/config.yml
  • Install polipo (with Mac: brew install polipo, with Ubuntu: apt-get install polipo)
  • Drop polipo-start and polipo-console somewhere useful (perhaps $HOME/bin?)

Run with HTTP Caching Proxy

Simply start up polipo in the foreground in a terminal/tmux/screen session with: ~/bin/polipo-start. In your Test Kitchen project verify that caching is enabled by running kitchen list --debug and look for the http_proxy and chef_omnibus_url config options.

<%
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:
http_proxy: <%= http_proxy_url %>
https_proxy: <%= http_proxy_url %>
provision_command: "env http_proxy=<%= http_proxy_url %> bash -c 'curl -L http://www.getchef.com/chef/install.sh | bash'"
provisioner:
chef_omnibus_url: http://www.getchef.com/chef/install.sh
<% 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment