Skip to content

Instantly share code, notes, and snippets.

@fnichol
Last active April 27, 2023 15:24

Revisions

  1. fnichol revised this gist Mar 6, 2015. 2 changed files with 30 additions and 5 deletions.
    18 changes: 17 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,20 @@

    ## 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.
    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 diagnose` and look for the `http_proxy` and `chef_omnibus_url` config options, like in this abbreviated example output:

    ```
    ---
    timestamp: 2015-03-06 19:27:56 UTC
    kitchen_version: 1.3.1
    instances:
    default-ubuntu-1204:
    state_file: {}
    driver:
    http_proxy: http://10.0.10.20:8123
    https_proxy: http://10.0.10.20:8123
    provision_command: env http_proxy=http://10.0.10.20:8123 bash -c 'curl -L
    http://www.chef.io/chef/install.sh | bash'
    provisioner:
    chef_omnibus_url: http://www.chef.io/chef/install.sh
    ```
    17 changes: 13 additions & 4 deletions kitchen.local.yml
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,28 @@
    <%
    require 'socket'
    # @return [String] public IP address of workstation used for egress traffic
    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.connect '64.233.187.99', 1 # a google IP, does not hit network
    s.addr.last
    end
    ensure
    Socket.do_not_reverse_lookup = orig
    end
    end
    # @return [Integer] default polipo listening port
    def local_port ; 8123 ; end
    # @return [String] the polipo proxy URL
    def http_proxy_url ; "http://#{local_ip}:#{local_port}" ; end
    # @return [TrueClass,FalseClass] whether or not the polipo port is listening
    def proxy_running?
    socket = TCPSocket.new(local_ip, local_port)
    true
    @@ -35,8 +40,12 @@ end
    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'"
    # used in kitchen-docker to pre-install/cache a Chef Ommnibus package in a
    # layer before booting containers
    provision_command: "env http_proxy=<%= http_proxy_url %> bash -c 'curl -L http://www.chef.io/chef/install.sh | bash'"

    provisioner:
    chef_omnibus_url: http://www.getchef.com/chef/install.sh
    <% end %>
    # installs from an http:// source to enable better caching through
    # http_proxy, and yes, this is a bit evil
    chef_omnibus_url: http://www.chef.io/chef/install.sh
    <% end %>
  2. fnichol revised this gist Jan 8, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kitchen.local.yml
    Original file line number Diff line number Diff line change
    @@ -35,8 +35,8 @@ end
    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.opscode.com/chef/install.sh | bash'"
    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.opscode.com/chef/install.sh
    chef_omnibus_url: http://www.getchef.com/chef/install.sh
    <% end %>
  3. fnichol revised this gist Jan 8, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions kitchen.local.yml
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,11 @@ end
    %>
    ---
    <% if proxy_running? %>
    driver_config:
    driver:
    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'"

    provisioner:
    chef_omnibus_url: http://www.opscode.com/chef/install.sh
    <% end %>
  4. fnichol revised this gist Nov 19, 2013. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # 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](http://www.pps.univ-paris-diderot.fr/~jch/software/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.
  5. fnichol renamed this gist Nov 19, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. fnichol revised this gist Nov 19, 2013. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/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"
  7. fnichol revised this gist Nov 19, 2013. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions polipo-start
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/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'
  8. fnichol created this gist Nov 19, 2013.
    40 changes: 40 additions & 0 deletions kitchen.local.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <%
    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 %>