projectatomic/docker-image-examples — pull request #32 by mfojtik (2014-05-06 11:23:36+00:00)
Title: Initial implementation of incremental build in self-contained ruby builder image

This is a demo of incremental build using plain docker. The basic workflow is following:

```
git clone https://github.com/mfojtik/sinatra-app-example && cd sinatra-app-example

# First do the 'clean' build
docker run --cidfile="cid" -v $(pwd):/tmp/src openshift/centos-ruby-builder

# ---> Installing application source
# ---> Building your Ruby application from source
# ---> Installing dependencies using Bundler
# Fetching gem metadata from https://rubygems.org/..........
# Fetching gem metadata from https://rubygems.org/..
# Installing rack (1.5.2)
# Installing puma (2.8.1) with native extensions
# Installing rack-protection (1.5.2)
# Installing tilt (1.4.1)
# Installing sinatra (1.4.4)
# Using bundler (1.1.4)
# Your bundle is complete! It was installed into /opt/ruby/bundle
# ---> Build successful. Commit this image with: docker commit be13bb030ef0 ruby-app

docker commit $(cat cid) ruby-app

# 2bc107b097110000b96fbff05dbbbaa4053e34f8c875725c02c10d499e386f3e

rm -f cid

# Save artifacts
docker run --rm --entrypoint="/opt/ruby/bin/save-artifacts" ruby-app > artifacts.tar

# tar: Removing leading `/' from member names

# Incremental build
cat artifacts.tar | docker run --cidfile="cid" -v $(pwd):/tmp/src -i openshift/centos-ruby-builder

# ---> Restoring artifacts from STDIN
# ---> Installing application source
# ---> Building your Ruby application from source
# ---> Installing dependencies using Bundler
# Using rack (1.5.2)
# Using puma (2.8.1)
# Using rack-protection (1.5.2)
# Using tilt (1.4.1)
# Using sinatra (1.4.4)
# Using bundler (1.1.4)
# Your bundle is complete! It was installed into /opt/ruby/bundle
# ---> Build successful. Commit this image with: docker commit d6a664fb4058 ruby-app

docker commit $(cat cid) ruby-app

# Alternatively, you can execute this in one long shot:

docker run --rm --entrypoint="/opt/ruby/bin/save-artifacts" ruby-app | docker run --cidfile="cid" -v $(pwd):/tmp/src -i openshift/centos-ruby-builder
docker commit $(cat cid) ruby-app

```