Apt-Cacher NG For Fast Package Installation

Tags: devops

Disposable systems eliminate the variability and cruft that accumulates over time. I look at some of the long lived dev and test systems at work, and I cringe because a parade of developers has each left their mark, and each special touch pushes those environments further from production. I did it too, and we’re making things better. Please don’t throw stones at my glass house.

CERN’s Tim Bell put it best when he compared long lived systems to pets and disposable systems to cattle.

To make the disposable cattle model work, the orchestration system must create and configure new systems in less time than it’d take to retrofit a long lived pet machine. We won’t wait for new machines just like we won’t wait for a slow unit test suite to run.

Apt-Cacher NG sits on the local network and silently proxies and caches requests for Debian or Ubuntu packages. The first installation of a package will go as quickly as the Apt-Cacher’s connection to the upstream mirror, but subsequent installations will run as quickly as the local network link. That’s typically an order of magnitude or three in throughput.

Apt-Cacher NG is included in the default repositories for Ubuntu, and installation is ridiculously easy. Once it is running, client configuration is also ridiculously easy.

People who use preseed.cfg files (VeeWee, Foreman, or other automatic system provisioning tools) should add or update the following line:

choose-mirror-bin mirror/http/proxy string http://<your_apt_cacher_ng_server:3142/

If an existing system nees to be reconfigured, place the following in /etc/apt/apt.conf.d/01proxy:

Acquire::http::Proxy "http://<your_apth_cacher_ng_server>:3142";

Two notes on alternatives:

I did not pick Apt-Cacher NG over Apt-Cacher just because of the NG designation. My first cache server attempt was Apt-Cacher as laid out in the Ubuntu community docs. It installed easily, but it locked up hard when I tried to run apt-get update against it.

I knew of but chose to ignore apt-mirror because I use a very tiny subset of packages. Apt-mirror may be the way to go if you’re supporting a wide range of systems and use cases.