Setting up Capistrano 3 for Rails application

Prerequisites-

  1. An existing Rails application.
  2. Application is uploaded on a SCM preferably Git
  3. Deployment server is SSH enabled. Incase you are trying local deployment on Mac OS X, you can refer here

Now the Capistrano 3 setup –

  1. Install Capistrano and its related sub-modules by adding to Gemfile –
    group :development, :test do
    gem 'capistrano', '~> 3.4.0'
    gem 'capistrano-rails', '~> 1.1.0'
    gem 'capistrano-bundler'
    end
    bundle install
  2. Create requisite directory structure pertaining to Capistrano
    bundle exec cap install
    Screen Shot 2015-06-29 at 10.25.00 AM
  3. Update Capfile to include installed Capistrano helper modules
    # Load DSL and set up stages
    require 'capistrano/setup'
    # Include default deployment tasks
    require ‘capistrano/deploy’
    require ‘capistrano/rails’
    require ‘capistrano/bundler’
  4. Update deploy.rb with general deployment settings. Uncomment and update the configuration as applicable.
  5. Now mention deployment server and SSH connection details, say for local environment, in app > config > deploy > local.rbserver '192.168.1.xx', user: 'username', roles: %w{db web app} , :primary => true
    set :ssh_options, {
    user: 'username', # overrides user setting above
    # keys: %w(/home/user_name/.ssh/id_rsa),
    forward_agent: false,
    # auth_methods: %w(publickey password)
    password: 'Use keys'
    }
  6. Now that the bare-minimum configuration is complete, we can go ahead and test connectivity and structure creation.

    cap staging deploy:check

    Screen Shot 2015-06-29 at 10.33.28 AM

  7. All looks good, now deploy –
    cap staging deploy

References:

Leave a comment