Skip to content

Instantly share code, notes, and snippets.

@maoo
Last active November 19, 2019 18:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maoo/3262589c9db989c6e948 to your computer and use it in GitHub Desktop.
Save maoo/3262589c9db989c6e948 to your computer and use it in GitHub Desktop.
Setting up polipo with Kitchen on OSX

How To setup polipo on OSX

  • Install polipo with brew install polipo

  • Edit your ~/.bashrc or ~/.zshrc and include

$PLIST_FILE=~/opt/homebrew.mxcl.polipo.plist
alias launch-polipo='launchctl load $PLIST_FILE'
alias stop-polipo='launchctl load $PLIST_FILE'
  • Add $PLIST_FILE with the following contents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.polipo</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
      <string>/path/to/opt/start-polipo.sh</string>
    </array>
  </dict>
</plist>
  • Add /path/to/opt/start-polipo.sh with the following contents
#! /bin/bash

POLIPO_CACHE=~/.polipo-cache

mkdir -p $POLIPO_CACHE

/usr/local/opt/polipo/bin/polipo proxyAddress='0.0.0.0' disableIndexing='false' disableServersList='false' allowedClients='0.0.0.0/0' diskCacheRoot='$POLIPO_CACHE'

How to configure Kitchen to use polipo

  • Add/edit ~/.kitchen/config.yml with the following contents
<%
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 %>

Original gist - Auto-enable Local HTTP Caching in Test Kitchen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment