dotcloud/docker — pull request #2038 by tianon (2013-09-28 13:07:00+00:00)
Title: Fix contrib/mkimage-debian.sh apt caching prevention

With many thanks to @paulepanter for pointing it out and @dsissitka for helping me test (especially with an SSD and a nice visualization environment to help verify the validity and impact of "force-unsafe-io" - http://imgur.com/abRh5qD).

I added another comment to the force-unsafe-io line to reflect our testing (since my 7200rpm spinning disk workstation was pretty dramatic - python went from 30s down to 12s, and xorg went from 3m down to 2m, and as you can see from @dsissitka's screenshot above, the impact to faster disks is nonexistent, as expected).

To fix the automatic "apt-get clean" issue (that we thought "No-Cache=true" meant), we tested by running "apt-get clean; find / -name '*.deb'; apt-get install -y python; find / -name '*.deb'" with each solution, and here's the ones we tried:
* obviously `No-Cache=True;` - only applies to proxies
* `Clean-Installed=True;` - is already on by default and doesn't actually apply to what we're trying to do (see `man apt.conf`)
* `Max-Age=0` - just makes sure that we redownload for every install, but doesn't delete files after install
* `Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";` - doesn't apply to the archive files, so doesn't correspond to "apt-get clean after every install"
* `Dir::Cache::archives "/tmp";` - we don't ever clear out /tmp or use tmpfs for it (at least not automatically), so this doesn't help much; it just moves the files elsewhere in the image
* finally, `DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb || true";};` which just deletes all the archives as soon as install is finished, and actually does what we want :+1:

(final thanks goes out to http://askubuntu.com/a/81211/89630)

/cc @jpetazzo since we both should've tested these two more thoroughly on #1883 :)