Create virtual machines faster by caching deb packages.
Use squid-deb-proxy on host OS, then add an apt.conf.d/ config file to make guest OS apt-get use your proxy.
Following these notes requires fluency with command line, sudo, daemons and vagrant.
I have written these short notes from memory, and it’s not a complete tutorial.
Host OS: squid-deb-proxy
$ sudo apt-get update $ sudo apt-get -y install squid-deb-proxy
I also added “archive.ubuntu.com” to /etc/squid-deb-proxy/mirror-dstdomain.acl and ‘sudo systemctl reload squid’, but I didn’t verify if this change is really necessary.
Vagrantfile
You must update your own host OS IP address to Vagrantfile.
# Copyright 2017 Tero Karvinen http://TeroKarvinen.com $tscript = <<TSCRIPT set -o verbose echo -e 'Acquire::http::proxy "http://192.168.10.41:8000";\nAcquire::https::proxy "http://192.168.10.41:8000";' \ > '/etc/apt/apt.conf.d/30proxy' cat /etc/apt/apt.conf.d/30proxy apt-get update apt-get -y install puppet ipython3 tree curl wget bash-completion postgresql echo "See you on http://TeroKarvinen.com" TSCRIPT Vagrant.configure(2) do |config| config.vm.box = "bento/ubuntu-16.04" config.vm.provision "shell", inline: $tscript config.vm.define "tero" do |tero| tero.vm.hostname = "tero" tero.vm.network "forwarded_port", guest: 80, host: 12080 end end
Provisioning the Guest
$ vagrant up $ vagrant ssh
The first time the machine is provisioned the package download takes normal time. After that, packages are downloaded from the host OS proxy and provisioning is much faster.
$ vagrant destroy; time vagrant up && vagrant ssh
Solutions to Common Problems
Are my packages really cached?
$ sudo tail /var/log/squid-deb-proxy/access.log
Should contain lines with TCP_MEM_HIT/200, which means a file was served from Squid cache.
Apt complains: “Extra junk at end of file”?
Quotes and semicolons are required, for example:
$ cat /etc/apt/apt.conf.d/30proxy Acquire::http::proxy "http://192.168.10.41:8000"; Acquire::https::proxy "http://192.168.10.41:8000";
Conclusion
The speed benefit would be especially large when installing a lot of packages on provisioning or automatically building and destroying vagrant guests multiple times (e.g automatic testing).
Adminstrivia
Update: removed the percentages and minutes, because the tests were not done very carefully.