• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Combines Capistrano with Chef Solo

Roundsman

This is an attempt to combine the powers of Capistrano and chef-solo.

The only thing you need is SSH access and a supported OS. At this time only Ubuntu is supported.

Introduction

You can skip this if you already know about Capistrano and Chef.

Installing servers can be tedious work. Keeping your configuration in sync can be hard too. Chef is an excellent tool for managing this. It can provision your server from scratch. It can also be run again and again to check and update your configuration if needed.

Capistrano is an excellent tool for deployment. It can deploy your code on multiple machines, with clever defaults, limited downtime and the ability to quickly roll back your deployment if something has gone wrong.

Roundsman aims to integrate Capistrano and Chef. This means that with every deploy, it can check and update your configuration if needed. Are you using a new version of Ruby in your next release? It will automatically install when you deploy! Adding a new machine to your cluster? No problem! Roundsman will go from a bare bones Linux machine to a working server in minutes!

Before you can use Roundsman, you need to know how to use Capistrano and how to write Chef recipes. Here are some resources you might want to check out:

Feeling comfortable you can tackle deploying your application with Capistrano and Chef? Now you can use Roundsman to combine them.

Installing

Roundsman runs on Ruby 1.8.7 and above.

If you're using Bundler, you can add Roundsman to your Gemfile:

# Gemfile

gem 'roundsman', :require => false

Run bundle install to get it.

If you're not using Bundler, you can install Roundsman by hand:

$ gem install roundsman

And "capify" your project:

$ capify .

Next, load Roundsman in Capfile

# Capfile

require 'roundsman/capistrano'

Usage

By default, Roundsman assumes you put your Chef cookbooks inside config/cookbooks. If you don't like this, see the Configuration chapter. But here we're going to use that.

I'm also going to assume that you put all Capistano configuration inside config/deploy.rb. When you have a lot of configuration or use the multistage extension, you might want to place it elsewhere.

After configuring Capistrano and writing and downloading Chef recipes, you can hook them up, with a Capistrano hook. Simply provide provide a run list. Let's say you want to run the default recipe of your own cookbook, called main.

# config/deploy.rb

before "deploy:update_code" do
  roundsman.run_list "recipe[main]"
end

I'm hooking it up before the update_code command, and not before deploy so it will also run when running cap deploy:migrations.

Setting up a webserver usually requires that you have the code already there; otherwise restarting nginx or Apache will fail, because it cannot find your application yet. To remedy that you can make another recipe that will configure your webserver and have it run after deploying your new code:

# config/deploy.rb

after "deploy:create_symlink" do
  roundsman.run_list "recipe[main::webserver]"
end

If you want a recipe to only run on a specific role, you can do so like this:

# config/deploy.rb

namespace :install do
  task :postgres, :roles => [:db] do
    roundsman.run_list "recipe[main::postgres]"
  end
end

before "deploy:update_code", "install:postgres"

Configuration

By default, Roundsman will make a lot of Capistrano's configuration available to chef.

So, you might have these settings:

# config/deploy.rb

set :application, "my-awesome-blog"
set :rails_env, "production"
set :deploy_to, "/var/www/#{application}-#{rails_env}"
set :user, "deployer"

Here's how you can use them inside your recipes:

# config/cookbooks/main/recipes/default.rb

directory File.join(node[:deploy_to], "uploads") do
  owner node[:user]
  owner node[:user]
  recursive true
end

Every configuration option from Capistrano is available in Chef. If your using the passenger_apache2 cookbook for example, you can set the attributes like this:

# config/deploy.rb

set :passenger, :version => "3.0.12", :max_pool_size => 4

There are also a set of configuration options for Roundsman itself. They all have sensible defaults, but you can override them if needed. To read all the default configuration:

$ cap roundsman:configuration

You can also perform a lot of tasks by hand if you need to. Here's how to get information:

$ cap --tasks roundsman

To get more information, use the --explain flag and specify a task name, like this:

$ cap --explain roundsman:install_ruby

How does it work?

What Roundsman does is this:

It will determine if you have the right version of Ruby installed. Your machine might already have an older version of Ruby installed, so if it needs to, it will use ruby-build to install the version of Ruby you need for your application.

Then, it will install check the version of chef-solo and install or upgrade as needed.

It will then copy over the cookbooks from your local machine to your deployment machine. This means that you don't need to commit every change while you're still working on it.

It will create your node.json file based upon your Capistrano configuration and run the recipes needed.

This is all done in Capistrano hooks, using Capistrano methods like run, so you can determine when and how your recipes are run.

Tips

Colors

Capistrano and Chef both give a lot of output. Check out capistrano_colors to colorize your output for better readability.

Vagrant

If you want to test out your configuration locally, you should take a look at Vagrant. It makes managing a VirtualBox a breeze. You can even create a stage just for Vagrant with the Capistrano multistage extension.

Contributing

If you want to help out, please! Create an issue or do a pull request and I will take a look at it.

To get this project up and running, make sure you have VirtualBox, because we use vagrant. Then all you need to do is:

bundle install
rake

More Repositories

1

http_accept_language

Ruby on Rails plugin. Fishes out the Accept-Language header into an array.
Ruby
771
star
2

fake_sqs

Provides a fake SQS server that you can run locally to test against
Ruby
292
star
3

elo

The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as chess and Go.
Ruby
158
star
4

metrical

Run MetricFu without making it part of your projects depencies.
Ruby
126
star
5

dotfiles

My bash / zsh / vim / pry settings
Vim Script
88
star
6

i18n_label

Adds translated form labels to Rails 2.2
Ruby
55
star
7

translatable_columns

Provides proxies for localized columns, depending on the locale set by I18n
Ruby
51
star
8

status_cats

Rack middleware replacing status codes with relevant pictures of cats.
Ruby
37
star
9

simple-backend-example

The source code for the article I wrote on Backends in Rails 3.1
Ruby
34
star
10

capistrano_chef_solo

Combining the awesome powers of Capistrano and chef-solo
Ruby
20
star
11

rack-token_auth

Rack middleware for using the Authorization header with token authentication
Ruby
14
star
12

formalize-rails

Use Formalize with the asset pipeline
Ruby
11
star
13

adventures-with-ruby

My own blog
Ruby
11
star
14

not

Syntactic sugar for negating any results: @foo.not.nil?
Ruby
10
star
15

no_value_helper

A simpel helper to display a nice message when there is no value
Ruby
6
star
16

scripted

A framework for organizing scripts
Ruby
6
star
17

spec_coverage

Ruby
6
star
18

basic_named_scopes

Basic named scopes for ActiveRecord makes all find-parameters a named scope
Ruby
5
star
19

model_based_html

Rails plugin for binding html to models
Ruby
4
star
20

root_table

Easy manageable root tables for Rails
Ruby
4
star
21

view

Displaying objects automatically
Ruby
4
star
22

coffee-machine

Some scripts I use for developing with CoffeeScript
Ruby
4
star
23

coffeescript-workshop

Examples and scripts for some workshops
Shell
4
star
24

rspec-smart-formatter

Chooses a formatter for best displaying purpose
Ruby
4
star
25

rule_table

A simple implementation of a rule table with lots of metaprogramming.
Ruby
4
star
26

faker

This fork is deleted soon
Ruby
4
star
27

stots

Ruby
3
star
28

fill

Fill your database, using rake db:seed
Ruby
3
star
29

i18n-airbrake

Ruby
3
star
30

rake_svn

Some handy svn commands for Rails
2
star
31

miniture-ninja

Experiments with WebGL
CoffeeScript
2
star
32

pillory

work in progress
Ruby
2
star
33

validate_database

Rails plugin that validates ActiveRecord according to the database
2
star
34

ubuntu_settings

Personal stuff with configuration, custom scripts and aliases for Ubuntu
Vim Script
2
star
35

capistrano-blaze

Ruby
2
star
36

tally

Simple Slack Bot, using AWS Lambda, SNS, SQS, API Gateway
Ruby
2
star
37

kingsofcode

2
star
38

iain.github.com

Github pages
2
star
39

heliosphere

Sunspot extras
Ruby
2
star
40

wodan

Ruby
1
star
41

opengl

A night of hacking OpenGL in Ruby
Ruby
1
star
42

adventure

Ruby
1
star
43

cramplire

Ruby
1
star
44

test_suite

Ruby
1
star
45

bearded-robot

Ruby
1
star
46

crockford

Crockford's Base32 (not the regular one), it switches out a couple letters to reduce chances of mistyping codes
Ruby
1
star
47

blaze

A tiny Campfire gem
Ruby
1
star
48

object_scoped_i18n

Translate using i18n and scope it according to the object's place in Ruby's hierarchial structure
Ruby
1
star