Tag Archives: capistrano

Configuration Management

We create Ruby on Rails Web Applications, mainly in several environments, so that is really important not only the automated Deployment for us, but the automated installation (Configuration) also. For Server side, we use dedicated Ubuntu LTS Systems, on the usual providers: AWS, DO, Linode …

We use Capistrano for automated deployments, and we searched years ago for a tool for Configuration Management. We were evaluating all market possibilities: Chef, Puppet, Salt, Ansible …. And finally we decided Chef for a reason: We know ruby so writing recipes in ruby was a big advantage.

But working with Chef Solo we found several limitations:

  • Need to install Chef Agent in node, which makes the process heavy.
  • You need to run all tasks on every setup command, it delays debugging tasks.
  • Debugging errors are a hell, there is not a clear help for errors. Indeed the documentation is sometimes poor.

Probably regarding that situation Ansible server agent-less promise would be the best option. But I found several inconveniences:

  • Language based on YAML, really verbose (try to install a big list of packages)
  • We would lose ruby for writing recipes.
  • Working with environments/roles is not really standardized.

What do we really need?

  • Write recipes (scripts) in Ruby, in our well-known and loved language.
  • Agent-less server side. Solve everything with an ssh connection.
  • Work with variables.
  • Work with environment/roles variables and configurations.
  • Work with templates for configuration files.

Chef, Ansible, Salt … Are really powerful, but:

  • Do we need OS compatibility? No, we use Ubuntu LTS versions.
  • Do we need complicated idioms? No, we have ruby and Shell scripts.
  • Do we need Warehouses or Galaxies of recipes? well … yes, they are useful, but sometimes they are solved with a shell script.

Sometimes, the solution is the easiest way. Shell scripting ? near, but what about ruby, variables or templates …. Capistrano 3:

  • Based on Ruby rake tasks.
  • Only SSH connections, based on SSHkit.
  • Working with roles, environments and variables out of the box.
  • We know the tool because our deployments are based on this.
  • We will integrate the standard recipes into our prun-ops gem.

Yes, we need templates, but we have ERB in Ruby, and googling a while we can find an easy solution for templating.

Today our analysis gives Capistrano 3 as the best way to go, tomorrow … who knows?

How to Get Google to properly Index your Rails website

In order to be properly indexed by Google (and other search engines), we need to fix three basic values in the header: title, description and keywords. So in header layout we should include them as meta tags:

%title= content_for?(:title) ? yield(:title) : "Lebrijo.com - Internet applications Consultancy"
 %meta{content: content_for?(:description) ? yield(:description) : "We build high quality Internet application for our customers", name: "description"}
 %meta{content: content_for?(:keywords) ? yield(:keywords) : "ruby, ruby on rails, consultancy, webapps, developers", name: "keywords"}

Another useful thing is creating a /sitemap.xml file where Engine-bots see your app structure. We can use the sitemap_generator gem, just including it in our Gemfile.

I have created a rake task for auto generating it:

desc "Generates sitemap"
  namespace :sitemap do
  task :generate do
  SitemapGenerator::Sitemap.default_host = 'http://www.lebrijo.com'
  SitemapGenerator::Sitemap.create do
    add '/', changefreq: 'daily', priority: 0.9
    add '/', changefreq: 'daily', host: 'http://blog.lebrijo.com', priority: 0.8
    add '/', changefreq: 'weekly', host: 'http://jenkins.lebrijo.com'
    add '/about', changefreq: 'weekly'
    add '/contact', changefreq: 'weekly'
  end
  SitemapGenerator::Sitemap.ping_search_engines
  end
end

And a Capistrano task, auto-generating sitemap on all deployments:

namespace :sitemap do
  desc "Generate sitemap.xml"
  task :generate do
    on roles(:app) do
      within release_path do
        with rails_env: fetch(:stage) do
          execute :rake, 'sitemap:generate'
        end
      end
    end
  end
after "deploy:published", :generate
end

Finally be careful with your ‘robots.txt’ file configuration, because Google should be allowed to download and crawl your page.

Once everything is done and deployed in your application, just add it to Google WebMaster Tools. Don’t forget to add your sitemap.xml.gz URL.

Here you have a great link enumerating what other things you can do to improve your website SEO features.

Chef basics for Rails Developers

In our new collaboration with Tealeaf Academy friends, we are writing about Chef/Vagrant and how to use them to manage and test your servers configuration.

This is a step-by-step guide (including github projects) to bootstrap and cook a basic Rails server:

  • Step 1. Vagrant: Creating your Development environment (Server Virtualization)
  • Step 2. Knife-solo: Kitchen structure
  • Step 3. Librarian: Managing dependencies
  • Step 4. Creating your own cookbook (rails-stack)
  • Step 5. Cook your Vagrant Box
  • Step 6. Cook a real server
  • Step 7. Deploy with Capistrano
  • Conclusions

Enjoy!!