Skip to content

Instantly share code, notes, and snippets.

@fnichol
Created February 5, 2012 20:50
Show Gist options
  • Save fnichol/1747868 to your computer and use it in GitHub Desktop.
Save fnichol/1747868 to your computer and use it in GitHub Desktop.
Vagrant apt-cacher-ng

Vagrant apt-cacher-ng Box

Simple and easy, just:

mkdir apt-cacher-ng && cd apt-cacher-ng
curl -LO https://raw.github.com/gist/1747868/Vagrantfile
vagrant up

Tail the logs perhaps?

vagrant ssh
sudo tail -f /var/log/apt-cacher-ng/apt-cacher.*

To use the caching box, determine your workstation's IP address and run the following on your Ubuntu/Debian node:

workstation_ip="xxx.xxx.xxx.xxx"
cat <<PROXY > /etc/apt/apt.conf.d/01proxy
Acquire::http::Proxy "http://${workstation_ip}:3142";
PROXY
#!/usr/bin/env ruby
# coding: utf-8
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.customize ["modifyvm", :id, "--memory", "128"]
config.vm.forward_port 3142, 3142
config.vm.provision :shell do |shell|
shell.inline = "apt-get update && apt-get install -y apt-cacher-ng"
end
end
@Ghoughpteighbteau
Copy link

quick update for the new version of vagrant

# -*- mode: ruby -*-
# vi: set ft=ruby sw=2 ts=2:

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, 
                 "--memory", "128",
                "--cpus", "1"
      ]
    end
    config.vm.network "forwarded_port", guest: 3142, host: 3142

  config.vm.provision :shell do |shell|
    shell.inline = "apt-get update && apt-get install -y apt-cacher-ng"
  end
end

I also use this in my bootstrap script

#section "checking for apt-cacher proxy"
if nc -z "$aptProxy" 3142 -w 5; then
  echo "using apt-cacher proxy!"
  echo "Acquire::http::proxy \"http://$aptProxy:3142\";" > /etc/apt/apt.conf.d/01proxy
else
  echo "Could not find a local apt-get proxy or itel mirror. not good"
fi

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