Is there a way to set a default stage in Capistrano 3?
I\'ve tried putting set :stage, :production
inside deploy.rb but that didn\'t work, it gives the erro
Capistrano v3 is somewhat of a wrapper around Rake, so you need to realize that what's really happening is that a production
task is getting run first, followed by a deploy
task.
If you debug it a little, you'll find that deploy.rb
doesn't get loaded when you don't type in a stage. This is because the stage's task is where deploy.rb
gets loaded: Looking at lib/setup.rb, a task is defined for each stage. When run, the stage's task sets :stage
, loads up the capistrano defaults, and then finally loads your deploy.rb
file.
So, an easy trick would be to tell Capistrano to invoke the stage task every time you run cap
by adding this to the end of your Capfile
(not your deploy.rb
):
Rake::Task[:production].invoke
or, using the invoke
method from Capistrano's DSL:
invoke :production
This may have some unintended consequences if you actually do use multiple stages, but if you only ever use the production
stage, it should work fine.
Another easy solution could be a simple shell alias, such as alias cap='cap production'
, but it might not work great if you have multiple projects with different stage names.