Stupid question but we've got a broken Capistrano recipe and I want to verify that we're not using after
& before
incorrectly?
Do these before & after tasks belong w/in the :deploy
namespace block or outside of it? I see examples of both here.
This is an excerpt from the problematic deploy.rb:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
# copy database.yml into project
task :copy_database_config do
production_db_config = "/Library/RoRconfig/#{application}.yml"
run "cp #{production_db_config} #{current_release}/config/database.yml"
`puts "replaced database.yml with live copy"`
end
task :pipeline_precompile do
run "cd #{release_path}; RAILS_ENV=production rake assets:precompile"
end
after "deploy:update_code", "deploy:pipeline_precompile" ### <---
before "deploy:finalize_update", "deploy:copy_database_config" ### <---
end
If you are not developing a gem, but simply using Capistrano to deploy an application: Your deployment will be unique to your particular project, based on a combination of various Capistrano gems, configuration, server environment, etc. The only real way to test your deployment is by using a staging environment.
I use a setup similar to:
after :deploy, "deploy:update_code", "deploy:pipeline_precompile"
before :deploy, "deploy:finalize_update", "deploy:copy_database_config"
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
# copy database.yml into project
task :copy_database_config do
production_db_config = "/Library/RoRconfig/#{application}.yml"
run "cp #{production_db_config} #{current_release}/config/database.yml"
`puts "replaced database.yml with live copy"`
end
task :pipeline_precompile do
run "cd #{release_path}; RAILS_ENV=production rake assets:precompile"
end
end
According to capistrano's doc at https://capistranorb.com/documentation/getting-started/before-after/, here's how they suggest for inside and outside of :deploy namespace:
# call an existing task
before :starting, :ensure_user
after :finishing, :notify
# or define in block
namespace :deploy do
before :starting, :ensure_user do
#
end
after :finishing, :notify do
#
end
end
However, be careful not to put these hooks inside your custom capistrano rake file that you import as the load order may make it not exist.
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