rb-
rb-

Reputation: 2365

Where should I put my deployment tasks when using Capistrano?

I'm using Capistrano to deploy apps that I'm building in Sinatra and Rails. For a while now I've been writing all the stuff I need to get done during the deployment right into config/deploy.rb. It looks like I'm just writing Rake here. I was wondering if I could get some advice on if I'm putting these in the right place or if I could be more "Capistranorish" with my deployments.

Here are a few examples of things I'm doing here. I write pretty much everything that I need my deployments to do here.

# deploy.rb
task :initctl_reload_configuration do
  on roles(:app), in: :sequence do
    execute "sudo initctl reload-configuration"
  end
end

task :rebuild_sitemap_no_ping do
  on roles(:app), in: :sequence do
    execute "cd /srv/app/#{environment}/current && RAILS_ENV=#{environment} bundle exec rake sitemap:refresh:no_ping"
  end
end

task :rebuild_sitemap do
  on roles(:app), in: :sequence do
    execute "cd /srv/app/#{environment}/current && RAILS_ENV=#{environment} bundle exec rake sitemap:refresh"
  end
end

task :restart_services do
  on roles(:app), in: :sequence do
    execute "sudo service tomcat6 restart"
    execute "sudo service sunspot-solr restart"
    execute "sudo service app-#{environment} restart"
    execute "sudo service nginx restart"
  end
end

Upvotes: 1

Views: 190

Answers (1)

user777337
user777337

Reputation:

If that's all you got, it might be just fine leaving it in deploy.rb.

If you really want to move those tasks somewhere, below contents of Capfile (you likely have it in the root of your project) should give you a hint:

# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

So just create a file in lib/capistrano/tasks/ ending with .rake and that should do it!

Upvotes: 3

Related Questions