Snippet from deploy.rb
task :prod1 do
set :deploy_to, "/home/project/src/prod1"
end
task :prod2 do
set :deploy_to, "/home/project/src/prod2"
end
I have 2 tasks like the above. Now instead of manually running either "cap prod1 deploy" or "cap prod2 deploy", I want to create a task "prod" which sets the required "deploy_to" based on the existence of a file on the server.
something like:
task :prod do
if (A_FILE_IN_SERVER_EXISTS)
set :deploy_to, "/home/project/src/prod2"
else
set :deploy_to, "/home/project/src/prod1"
end
How do I do that?
You can do that like this:
task :set_deploy_to_location do
if capture("[ -f /etc/passwd2 ] && echo '1' || echo '0'").strip == '1'
set :deploy_to, "/home/project/src/prod2"
else
set :deploy_to, "/home/project/src/prod1"
end
logger.info "set deploy_to = #{deploy_to}"
end
This will do what you need. You can hook this method using before and after hooks like this:
before :deploy, :set_deploy_to_location
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