Collection of recipes for various Ruby On Rails deployment setups
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Rails Deployment Alternatives

This repository contains configuration files for installing couple of alternatives for Ruby On Rails deployment.

It's purpose is mainly didatic, since I use it at workshops teaching Rails deployment, hosting, infrastructure, provisioning and automation.

It can be quite well used to test and demonstrate automated provisioning of a clean machine with infrastructure for running Ruby web applications.

There are three recipes for the Sprinkle server provisioning tool, showing the dominant setups for deploying Rack-based applications as of today:

1. Apache as a Reverse Proxy for Mongrel

This is historically one of the first “real” setups for deploying Rails (ignoring FastCGI setups).

This setup is installed with the following command:

$ sprinkle --script=1-rails-stack-apache-mongrel.rb --verbose

and the web server configuration for this setup is in the configurations/mongrel.conf file.

In 2006, Zed Shaw wrote Mongrel, a Ruby webserver, which could be easily proxied to a full-fledged webserver, such as Apache.

This way, multiple Mongrel instances can be launched, running on different ports, and the front-end web server load balances between them, serving as a reverse proxy. It also serves static assets (stylesheets, images, etc). This setup is still widely used with different, modern Ruby application servers such as Unicorn or Thin.

You launch the application by running this command in the application folder:

  $ rails server mongrel --environment production

In real life, there would be more than one application server instance running.

2. Nginx as a Reverse Proxy for Thin

A variation on this old school setup is to use the Nginx web server as a reverse proxy / load balancer for a cluster of Thin servers.

This setup is installed with the following command:

$ sprinkle --script=2-rails-stack-nginx-thin.rb --verbose

and the web server configuration for this setup is in the configurations/thin.conf file.

In this setup, Thin is connected to Nginx via UNIX domain sockets (see article), offering more power then connecting via TCP.

You launch the application by running this command in the application folder:

  $ thin --socket /tmp/thin.sock --server 3 --environment production --tag demoapp --rackup start

A variation on this setup would be to use eg. the Unicorn webserver instead of Thin.

Notice the nginx_configuration package contains a number of tricks how to speed up serving static assets with Nginx.

3. Phusion Passenger (mod_rails)

The latest, and most convenient alternative is the Phusion Passenger module for Apache or Nginx web servers. In fact, it is currently the recommended setup for deploying Rails applications.

This setup is installed with the following command:

$ sprinkle --script=3-rails-stack-passenger.rb --verbose

and the web server configuration for this setup is in the configurations/passenger.conf file.

Phusion Passenger is distributed and installed as a Rubygem. The gem package includes a installer script which checks dependencies and builds/installs the module into the web server. The script also displays information how to configure your web server and application for deployment.

The application is started “automagically”, and restarted by running this command in the application folder:

  $ touch tmp/restart.txt

Installation and Usage

This repository contains definitions for installing and configuring various software via the Sprinkle and Capistrano tools.

See packages and configurations directories for details.

You run the commands locally, and they are being run on the remote machine via Capistrano.

First, you'll need a Ubuntu server reachable by SSH.

The repository contains a configuration file for the Vagrant utility, which allows you to create virtual servers on your own machine via VirtualBox. Follow the installation instructions on the Vagrant website and then run these commands to launch a new server:

$ vagrant box add ubuntu
$ vagrant up

You may of course use any other virtualization technology or use a “live” virtual server in the network. The Rakefile included with the repository allows you to automatically create a new Ubuntu server in the Amazon Elastic Compute Cloud.

To install one of the provided stacks to the server, install the [Sprinkle] gem first:

$ gem install sprinkle

Copy the deploy.example.rb file and customize it with the connection details to your server (SSH user, server IP, etc):

$ cp deploy.example.rb deploy.rb

Now, you can setup a server by passing a recipe to the sprinkle tool:

$ sprinkle --script=3-rails-stack-passenger.rb --verbose

The installation of an Apache/Passenger stack takes about 13 minutes on a Ubuntu 10.04 Server running inside VMWare (1 core, 256MB RAM, 2GB HDD) on a 2011 Mac Book Air.

You can also preview packages, their dependencies and verifications by running this command:

$ sprinkle --test --cloud --verbose --script=3-rails-stack-passenger.rb


For more information, please see the Sprinkle readme.

The recipes and configurations were adapted from these sources:

Karel Minarik