Capistrano 3 Upgrade Guide

We recently started receiving support requests about Capistrano 3. Of course to provide quality support you have to know the subject, so I set on a quest to upgrade Semaphore’s deployment script from Capistrano 2 to Capistrano 3. As always it took a bit than expected but in the end new code looks nicer.

I have to say that I did have a flashback from couple of years ago when I was setting up Capistrano for the first time: documentation is missing some things and it’s a bit scattered between the readme, wiki and official homepage. But it’s open source so we are all welcome to contribute improvements.

I will try to make the upgrade easier for you by presenting our old vs new Capistrano configuration step by step.

Imported from Disqus

Philip Hallstrom7 years ago

There is a fork of whenever that supports Capistrano 3. Full disclosure: I wrote it.

https://github.com/phallstr…
https://github.com/phallstr…

https://github.com/javan/wh…

Avatar

Robert Reiz7 years ago

Since I moved to Capistrano 3 the assets:precompile doesn’t get executed. Any idea why it does not precompile the assets?

darkofabijan Mod Robert Reiz7 years ago

Hi Robert,

Do you have following line in your Capfile?

require “capistrano/rails/assets”

Robert Reiz darkofabijan7 years ago

Yes. But that didn’t worked. I exchanged it with “require ‘capistrano/rails’”. And I added explicitly a task “:precompile” to my deploy.rb. Not it works fine. But I still don’t understand why it doesn’t work out of the box.

method Robert Reiz7 years ago

I bet your problem was the same as mine, that I hadn’t added the :web role to the server I was deploying to. See the assets_roles setting on https://github.com/capistra…

Robert Reiz method7 years ago

Yes. That was the problem. But with the current version of capistrano-rails its fixed now.

Avatar

TheHungryCoder method6 years ago

Thanks a lot! I solved my similar problem by adding appropriate assets roles.

Avatar

Sean Horan7 years ago

Capistrano3 doesn’t deploy:restart automatically. You have to add after ‘deploy:publishing’, ‘deploy:restart’, likely within the web role.

Ben Dixon Sean Horan7 years ago

For anyone who’s confused with why this is working for some and not for others it’s because deploy:restart was called automatically in the 3.0 release but removed in 3.1

Avatar

Hung7 years ago

I have Error when run cap deploy:

NameError: undefined local variable or method `production’ for main:Object

classpath:/config/deploy:1:in `(root)’

/srv/webapps/atan_scrum/Capfile:1:in `(root)’

/srv/webapps/atan_scrum/Capfile:6:in `(root)’

/opt/torquebox/current/jruby/bin/cap:23:in `(root)’

(See full trace by running task with --trace)

Please help me.
Thanks so much.

Avatar

Andreas Wenk6 years ago • edited

Thanks for this post. One thing I would like to mention. Afaik, there is no need to run

after :finishing, “deploy:cleanup”

because it is already in the flow when you rund cap [ENV] deploy. See http://capistranorb.com/doc… for further info.

UPDATE: sry - this is only true when using Rails. Please see the link above.

Avatar

Amit Patel5 years ago • edited

Unable to deploy with private github repo. I am getting following error:

DEBUG [ea32bf2c] ERROR: Repository not found.
DEBUG [ea32bf2c] fatal: Could not read from remote repository.

Detailed question is posted http://stackoverflow.com/qu…