winchman/builder-core — pull request #22 by rafecolton (2014-12-23 04:10:55+00:00)
Title: Add image squashing

This adds the experimental squashing feature, which will soon be integrated into `docker-builder` (also experimental). This allows images to be "squashed" after building and before tagging.

So why do this? Squashing images allows you to drastically optimize the size of your final image while still utilizing the `Dockerfile` build cache. An example workflow might go as follows:

* daily
- build your base image
- squash after building (optimize for size)
- tag with date (i.e. `:yyyy-mm-dd`)
* as needed
- use your base image (`FROM registry/project:{{ date "2006-01-02" }}`) (_\*coming soon\*_)
- run your build
* this will add a few more layers but not many
* commands like `bundle install` will be fast because they have already run and cached a result in the filesystem of your base (daily) layer
- if desired, squash this build too - the trade off is that it will make builds slower (time spent squashing) but pushes and pulls faster (smaller image to push/pull)
* include destructive commands in your `Dockerfile` (e.g. `RUN rm -rf /some/directory/that/is/not/completely/necessary`)
* the squash will remove those files from the image, optimizing for space

/cc @alexschlessinger

/cc @burke @Sirupsen the addition of this feature may make this close to addressing Shopify's use case

**NOTE:** This feature still needs a little work - currently, it uses quite a bit of memory while running.