I'm using capistrano 2 to deploy my application. According to the documentation, the deploy:cold
task will call deploy:update
followed by deploy:migrate
and finally call deploy:start
.
In my application I don't have a migration step, and when I run cap deploy:cold
, it does the update but then shows this:
* 2014-04-09 14:57:45 executing `deploy:migrate'
`deploy:migrate' is only run for servers matching {:roles=>:db, :only=>{:primary=>true}}, but no servers matched
and deploy:start
is not being called. If I call it manually, it works fine - but never through deploy:cold
. What am I missing?
The problem is that Capistrano 2 defines a default task called deploy:migrate
that is specified to run only for the role :db
. If you don't have that role in your application (which most do not), then when deploy:migrate
runs it will error out on the missing role, and that kind of error normally terminates the deployment scenario.
This can happen for other tasks, if you have a complex setup where some tasks are only run for specific servers. This behavior is not documented at all at Capistrano's site, which is a shame.
Starting with Capistrano 2.7 there is a way to circumvent the "is only run for servers matching role" error, by specifying a task property that tells Capistrano to skip tasks if no servers matches any of its specified roles:
For example:
namespace :deploy do
task :stuff, :roles => :somerole, :on_no_matching_servers => :continue do
# stuff
end
end
Now this works well for custom tasks, but how to set this for the default task migrate
? you have to override the task with your own setting and add the :on_no_matching_servers
option. I've added this to the global.rb
file:
namespace :deploy do
task :migrate, :on_no_matching_servers => :continue do end
end