Skip to content

Setting Up Capistrano

Joe Cridge edited this page Apr 25, 2016 · 1 revision
  1. Add Capistrano to your Gemfile:

    gem 'capistrano', '~> 3.4.0'
  2. Install it…
    In the root directory of your app (on the development machine):

    $ bundle install && cap install
    
  3. Fill out config/deploy.rb:

    lock '3.4.0'
    
    set :application, 'my_app'
    set :repo_url, '[email protected]:username/repo_name.git'
    
    set :deploy_to, '/apps/my_app' # /apps must be owned by the user in config/deploy/production.rb
    
    namespace :deploy do
    
      desc "Load secrets into the environment"
      task :load_secrets do
        # Export application secrets as environment variables in a file on the server
        run "source ~/.rails/secrets"
      end
    
      after :restart, :clear_cache do
        on roles(:web), in: :groups, limit: 3, wait: 10 do
          # Here we can do anything such as:
          # within release_path do
          #   execute :rake, 'cache:clear'
          # end
        end
      end
    
    end
  4. Fill out config/deploy/production.rb:

    server '123.456.7.8:22', user: 'webdev', roles: %w{app db web}, primary: true
    
    set :ssh_options, {
       forward_agent: true,
       paranoid: true,
       keys: %w{~/.ssh/id_rsa}
    }