Following a little research I summarised in test-kitchen/kitchen-vagrant#90, here are the file that could be added to a repo to get some caching...
I will not add the polipo related files that can be found in https://gist.github.com/fnichol/7551540.
Since the code is added only when a running polipo
is found, this should not affect people who donnot have one running.
-
-
Save esciara/053d346c3caaa662d6dc to your computer and use it in GitHub Desktop.
Caching for a test-kitchen environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
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'" | |
vagrantfile_erb: Vagrantfile.erb | |
provisioner: | |
chef_omnibus_url: http://www.getchef.com/chef/install.sh | |
solo_rb: | |
http_proxy: <%= http_proxy_url %> | |
https_proxy: <%= http_proxy_url %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |c| | |
c.vm.box = "<%= config[:box] %>" | |
c.vm.box_url = "<%= config[:box_url] %>" | |
puts "http_proxy=<%= config[:http_proxy] %>" | |
puts "Using the Vagrantfile.erb file." | |
<% if config[:http_proxy] %> | |
if Vagrant.has_plugin?("vagrant-cachier") | |
# Configure cached packages to be shared between instances of the same base box. | |
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage | |
c.cache.scope = :box | |
end | |
<% end %> | |
<% if config[:vm_hostname] %> | |
c.vm.hostname = "<%= config[:vm_hostname] %>" | |
<% end %> | |
<% if config[:guest] %> | |
c.vm.guest = <%= config[:guest] %> | |
<% end %> | |
<% if config[:username] %> | |
c.ssh.username = "<%= config[:username] %>" | |
<% end %> | |
<% if config[:ssh_key] %> | |
c.ssh.private_key_path = "<%= config[:ssh_key] %>" | |
<% end %> | |
<% Array(config[:network]).each do |opts| %> | |
c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>) | |
<% end %> | |
c.vm.synced_folder ".", "/vagrant", disabled: true | |
<% config[:synced_folders].each do |source, destination, options| %> | |
c.vm.synced_folder "<%= source %>", "<%= destination %>", <%= options %> | |
<% end %> | |
c.vm.provider :<%= config[:provider] %> do |p| | |
<% config[:customize].each do |key, value| %> | |
<% case config[:provider] | |
when "virtualbox" %> | |
p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"] | |
<% when "rackspace", "softlayer" %> | |
p.<%= key %> = "<%= value%>" | |
<% when /^vmware_/ %> | |
<% if key == :memory %> | |
<% unless config[:customize].include?(:memsize) %> | |
p.vmx["memsize"] = "<%= value %>" | |
<% end %> | |
<% else %> | |
p.vmx["<%= key %>"] = "<%= value %>" | |
<% end %> | |
<% end %> | |
<% end %> | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment