projectatomic/docker-image-examples — pull request #23 by mfojtik (2014-04-29 22:24:29+00:00)
Title: Added self-contained Ruby builder image

This patch allow users to use `openshift/centos-ruby-builder` image as a self-contained Ruby applications builder. Developers don't need to install any additional tooling, all that is needed to be installed is a Docker image:

```
$ docker pull openshift/centos-ruby-builder
```

The basic building functionality this image provides, allow developers to transform their source code into fully functional Ruby application container. To get this done, users need to invoke:

```
$ docker run -v /path/to/source:/tmp/src openshift/centos-ruby-builder
--> Installing application source
---> Building your Ruby application from source
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 e708e53c4c05 ruby-app
```

This command mount the local directory with sources into the builder image, where the sources are first installed into the 'application runtime' directory where as part of the building process, the Bundler is used to install all dependencies from `Gemfile`.

The builder image Dockerfile specify `ENTRYPOINT ["/opt/ruby/bin/deploy"]`. This script, initially points to a `build` script. After the `build` script finishes its job, then the `/opt/ruby/bin/deploy` is replaced by the `run` command and the builder image exists to shell. This command will be used later to start the Ruby application server. The last line of the `build` script is suggesting to developer to commit the resulting container (CID is provided):

```
$ docker commit e708e53c4c05 ruby-app
bb0079295518725a817bbf0d9400a400516c38571bb0fc3a77c1a17e6d91846a
```

After commit, the container is converted to a runnable image. The `ENTRYPOINT` now points to `run` command. To start the application, developer just need to run:

```
$ docker run --rm -p 9292:9292 ruby-app
Puma starting in single mode...
* Version 2.8.1 (ruby 1.9.3-p448), codename: Sir Edmund Percival Hillary
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop
```

The `puma` process parent is the docker process itself, so after pressing Ctrl-C, the puma shutdown and the container is stopped.