chef-repo

by intercity

intercity / chef-repo

Set up your server to host Ruby on Rails apps. - Follow us on Twitter: @intercityup

427 Stars 87 Forks Last release: over 5 years ago (v2.5.0) MIT License 600 Commits 26 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Intercity Chef Recipes

Codeship Status for intercity/chef-repo

This Chef repository aims at being the easiest way set up and configure your own Rails server to host one or more Ruby on Rails applications using best practices from our community.

The configuration is heavily inspired by blog posts and chef recipes from 37signals and the Opscode Community Cookbooks.

Features

Takes care of automatic installation and configuration of the following software on a single server or multiple servers:

  • nginx webserver
  • Passenger or Unicorn for running Ruby on Rails
  • Multiple apps on one server
  • Database creation and password generation
  • Easy SSL configuration
  • Deployment with Capistrano
  • Configure ENV variables
  • Easy backup scheduling

Supported OSes

  • Ubuntu 12.04 LTS
  • Ubuntu 14.04 LTS

Databases

  • MySQL
  • PostgreSQL

Getting started

The following paragraphs will guide you to set up your own server to host Ruby on Rails applications.

1. Set up this repository

Clone the repository onto your own workstation. For example in your

~/Code
directory:
$ cd ~/Code
$ git clone git://github.com/intercity/chef-repo.git chef_repo

Run bundle:

$ bundle install

Run Librarian install:

$ librarian-chef install

2. Install your server

Use the following command to install Chef on your server and prepare it to be installed by these cookbooks:

bundle exec knife solo prepare @

This will create a file

nodes/.json

Now copy the the contents from the

nodes/sample_host.json
from this repository into this new file. Replace the sample values between
< >
with the values for your server and applications.

When this is done. Run the following command to start the full installation of your server:

bundle exec knife solo cook @

3. Deploy your application

You can deploy your applications with Capistrano.

Add the Capistrano gem to your Gemfile:

# your other gems..

gem 'capistrano', '> 3.2.1' gem 'capistrano-rails', '> 1.1'

And run bundle to install it:

bundle

Now generate configuration files for Capistrano:

bundle exec cap install

This command will generate the following files in your application:

Capfile
config/deploy.rb
config/deploy/production.rb
config/deploy/staging.rb

Edit the file

Capfile
and change it's contents to:
# Load DSL and Setup Up Stages
require 'capistrano/setup'

Includes default deployment tasks

require 'capistrano/deploy'

require 'capistrano/rails'

Loads custom tasks from `lib/capistrano/tasks' if you have any defined.

Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

Then edit

config/deploy.rb
and change it to the sample below. Replace
>> your git repo_url <<
with the SSH clone URL of your repository:
# config valid only for Capistrano 3.2.1
lock '3.2.1'

set :application, '>> your_application_name <> your git repo_url <> your_application_name <<_production use agent forwarding for ssh so you can deploy with the key on your workstation. set :ssh_options forward_agent: true default value :pty is false :linked_files .rbenv-vars .ruby-version :linked_dirs tmp vendor public :default_env path: :keep_releases namespace :deploy do desc application task :restart roles in: :sequence wait: execute :touch release_path.join end after :publishing>

Replace the contents of

config/deploy/production.rb
with
server '>> your server address <

Replace

>> your server address <<
with the domain name or ip address of your server.

To verify that everything is set up correctly run:

bundle exec cap production deploy:check

Finally to deploy, run:

bundle exec cap production deploy

This will deploy your app and run your database migrations.

Congratulations! You've now deployed your application. Browse to your application in your webbrowser and everything should work!

Try these cookbooks with Vagrant

You can use Vagrant to experience how easy it is to install your servers with this repository.

First, install Vagrant from http://vagrantup.com. Then install the following two Vagrant plugins:

Make sure you have Vagrant version 1.6.5 or higher installed.

vagrant plugin install vagrant-librarian-chef
vagrant plugin install vagrant-omnibus

Finally, start a Vagrant machine with a sample server configuration:

vagrant up mysql

This will boot a local Ubuntu virtual machine and install it so you can deploy Ruby on Rails applications that use MySQL as the database.

You can check out the sample configuration in file

Vagrantfile

When you run into problems:

These steps should let you set up or test your own Rails infrastructure in 5 - 10 minutes. If something doesn't work or you need more instructions:

Please! Open an issue or email [email protected].

Testing with test-kitchen

CI testing

Test-kitchen is a tool where you can automatically provision a server with these cookbooks and run the tests for them. The configuration in

.kitchen.yml
works with DigitalOcean.

First you need to obtain a DigitalOcean access token here: https://cloud.digitalocean.com/settings/applications. Then you need to find IDs of the SSH keys you added to your account: https://cloud.digitalocean.com/ssh_keys. You can obtain these IDs with the following command:

$ curl -X GET https://api.digitalocean.com/v2/account/keys -H "Authorization: Bearer "

When you've obtained both your access token and your key IDs you can run the tests like this:

$ export DIGITALOCEAN_ACCESS_TOKEN=
$ export DIGITALOCEAN_SSH_KEY_IDS=
$ bin/kitchen test

This command boots up a Droplet in your DigitalOcean account, provisions it with Chef, runs the tests and destroys the Droplet.

Testing while developing

If you want to keep the Droplet running and do testing while making changes you can use the

kitchen verify
command instead of the
kitchen test
command to verify your changes:
$ bin/kitchen verify

Resources and original authors

  • Most of the cookbooks that are used in this repository are installed from the Opscode Community Cookbooks.
  • The
    rails
    and
    bluepill
    configuration is based off the cookbooks by jsierles at https://github.com/jsierles/chef_cookbooks

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.