Quick Start - 5 Minute Server - Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)

Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)

4.0 - Quick Start - 5 Minute Server

Overview

This section provides a very brief overview of how to use the sample Chef repository to provision a server. If you’re the type of person who opens the box, has a go and then reads the instructions afterwards, this section is for you. Otherwise feel free to start from the next section then use this as a quick reference for provisioning servers in future.

The Stack

· Ruby 1.9.3+ (this can be selected)

· Postgres

· Redis

Steps

Install Tools

Begin by cloning the example repository

1 git clone git@github.com:TalkingQuickly/rails-server-template.git

and then running

1 bundle install

To install chef, berkshelf, knife-solo and other supporting gems. All three of these key gems are evolving quickly so it’s important to always use the Gemfile and bundle exec when working with them to ensure we’re using a version which has been tested with this book.

Define the server

Next we need to define users, inside data_bags/users copy the file deploy.json.example to deploy.json.

Generate a password for your deploy user with the command:

1 openssl passwd -1 "plaintextpassword"

And update deploy.json accordingly. Also copy your SSH public key (cat ~/.ssh/id_rsa.pub) into the public keys array.

Download Cookbooks

Berkshelf is like Bundler for Chef, this command fetches the cookbooks we need and their dependencies:

1 mkdir cookbooks

2 bundle exec berks install

Setup a VPS

This setup is designed to work on any Ubuntu 12.04 VPS, it has been tested on Linode, Rackspace and Digital Ocean. For initial experimentation I’d recommend Digital Ocean or for critical applications where support is key, Linode.

Once your VPS is up and running, copy your SSH key across:

1 ssh-copy-id root@yourserverip

Provision the server

Begin by installing chef on the remote machine:

1 bundle exec knife solo prepare root@yourserverip

This will generate a file nodes/yourserverip.json. Copy the contents of nodes/rails_postgres_redis.json.example to this file and change the username and password for monit.

Use the same command as before openssl passwd -1 “plaintextpassword to generate a password for postgresql and add this to the node definition file.

Now run:

1 bundle exec knife solo cook root@yourserverip

Sit back, relax and enjoy. This process takes quite a while and once it’s completed, you’ve got a server ready for a Rails + Postgres + Redis app.

warning

Berksfile.lock

When troubleshooting a provisioning failure, a lot of forums will contain advice along the lines of “try just deleting your Berksfile.lock”. This is generally a really bad idea and will almost always break more than it fixes. Section 6.1 goes into more detail on the function of Berksfile.lock

Next Steps

You’ve now got a completed single box Rails Server running Nginx, Postgresql & Redis.

Part 2 of this book - Capistrano covers how to deploy to such a server.

The rest of this book explains the workings of this configuration and how to customise it to your own needs or construct your own from scratch.