Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)
6.0 - A Template for Rails Servers
Overview
In the previous section we’ve covered how to build a Chef cookbook from the ground up. Hopefully from this I’ve shown how simple it is to use Chef to automate, in a reusable manner, pretty much any process we would normally SSH in to complete.
One of the most important things to take from this is that there’s no “magic” involved, chef is just executing the commands we would normally execute by hand. If it can be done in the terminal, we can write a chef recipe to automate it.
We can maintain complete control of how our stack is provisioned, while at the same time maintaining the convenience of something like Heroku or pre made images which hide the process from you completely.
In addition to writing our own chef recipes, there are a wealth of pre-written community recipes available for you to make use of. These range from mainstream components like PostgreSQL or Nginx to community created recipes for installing and configuring Wordpress automatically.
While these recipes are a great resource, I strongly recommend getting comfortable writing your own recipes by hand first.
If you rely entirely on applying recipes written by other people, as soon as you come across something there isn’t a pre-made recipe for, the temptation will be to SSH in and do it manually. This is disastrous as when you next come to provision a node using your chef definition, it won’t work the same way.
The aim should be to get sufficiently comfortable throwing together a chef recipe, that it feels as easy to put together a chef recipe to complete the task as it would be to do it manually.
Secondly being comfortable with the structure of a Chef cookbook will enable to use third party ones far more efficiently. Most Ruby developers get to a point where they realise taking a quick look at the source of a troublesome gem to see what it’s doing under the hood is often better than hours on Stack Overflow.
In the same way when working with chef, being able to quickly look at the internals of a third party cookbook will usually provide an explanation for any behavior you weren’t expecting in just a few minutes and ensure you’re getting the most out of them.
The Example Configuration
In the remainder of this book we’ll take as a basis the example chef repository available at:
https://github.com/TalkingQuickly/rails-server-template
This provides example a node definition file for basic single box Rails servers using each of the following databases:
· PostgreSQL
· MySQL
· MongoDB
· Redis
Along with the cookbooks and role definitions. The cookbooks are a mixture of simple ones written specifically for this book and complex community ones we’ll use only a fraction of.
This is illustrative of how a normal chef project will look, a mixture of mainstream recipes with a few bespoke ones of your own specific to your particular setup.