I have a namespace and a couple tasks in the namespace that run after deploy:updated. Here is an example:
namespace :myservice do
task :start do
on roles(:app) do
sudo :start, "my/application"
end
end
end
I'd love for one of these tasks to only run on a certain environment or host property. How can I accomplish this?
I'd love to be able to filter on environment such as:
namespace :myservice do
task :start do
on roles(:app), env(:vagrant) do
sudo :start, "my/application"
end
end
end
What is the best way to accomplish this?
It seems like capistrano multi-stage would help you. https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension
Essentially, you would have a stage called vagrant
where you might define configuration variables, which would then be referenced by your main deploy.rb
script(s) and acted on.
Here is a conceptual example,
# config/deploy/production.rb
set :should_start_my_application, false
# config/deploy/vagrant.rb
set :should_start_my_application, true
# config/deploy.rb
namespace :myservice do
task :start do
on roles(:app) do
if should_start_application then
sudo :start, "my/application"
end
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With