[HOWTO] Transfer Capistrano 2 to Capistrano 3 Using Ruby on Rails

At First, Why I want to transfer from Capistrano2 to Capistrano3?

  1. Stability
  2. Performance

In Capistrano2,

First, I often stuck at precompile…

and sometimes I get [deploy:update_code] exception while rolling back: Net::SSH::Disconnect, connection closed by remote host”

Third, every deployments take about 10~15 minuates.

So…. that’s why I want to change to capistrano 3.

this post is inspired by https://semaphoreapp.com/blog/2013/11/26/capistrano-3-upgrade-guide.html

But I still have some problems. Here I demo source code from my project and show how I fix these problems.

Just move your old “cap” files to a folder

cd YOUR_PROJECT
mkdir old_cap
mv Capfile old_cap
mv config/deploy.rb old_cap
mv config/deploy/mv old_cap    

1. Gemfile

Original

New

gem “capistrano-rails” = gem ‘capistrano’ + gem ‘capistrano-ext’ + gem ‘capistrano_colors’

2. Capfilee

Original

New

If you want to know what is the deploy flow if you require these files

check this http://capistranorb.com/documentation/getting-started/flow/

3. config/deploy.rb

Original

New

4. config/deploy/staging.rb

Original

New

5. lib/capistrano/tasks/restart.cap

6. lib/capistrano/tasks/sync_to_S3.cap

I use asset_sync to sync assets to S3.

https://github.com/rumblelabs/asset_sync

Notice: within must inside roles or you will get no method problem.

more details https://github.com/capistrano/sshkit

Comments

Google Analytics Alternative