Skip to content

Instantly share code, notes, and snippets.

@yctay
Last active August 31, 2017 13:43
Show Gist options
  • Save yctay/4433615 to your computer and use it in GitHub Desktop.
Save yctay/4433615 to your computer and use it in GitHub Desktop.
Capistrano recipe for deploying to WebFaction
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :user, "<< YOUR WEBFACTION USERNAME >>"
set :application, "<< YOUR APP NAME >>"
set :repository, "<< YOUR REPOSITORY ADDRESS >>"
set :deploy_to, "/home/<< YOUR WEBFACTION USERNAME >>/webapps/<< YOUR WEBAPP DIRECTORY >>"
set :default_stage, "production"
set :verbose_command_log, true
set :use_sudo, false
set :deploy_via, :checkout
set :branch, "master"
set :default_environment, {
"PATH" => "#{deploy_to}/bin:$PATH",
"GEM_HOME" => "#{deploy_to}/gems",
"RAILS_ENV" => "#{default_stage}"
}
set :scm, :git
set :scm_username, "<< YOUR SCM USERNAME >>"
role :web, "<< YOUR WEB SERVER >>"
role :app, "<< YOUR APP SERVER >>"
role :db, "<< YOUR DB SERVER >>", :primary => true
desc "Restart nginx"
task :restart do
run "#{deploy_to}/bin/restart"
end
desc "Start nginx"
task :start do
run "#{deploy_to}/bin/start"
end
desc "Stop nginx"
task :stop do
run "#{deploy_to}/bin/stop"
end
namespace :deploy do
puts "===================================================\n"
puts " ( ) ( ) )"
puts " ) ( ) ( ( GO GRAB SOME COFFEE"
puts " ( ) ( ) )\n"
puts " <_____________> ___ CAPISTRANO IS ROCKING!"
puts " | |/ _ \\"
puts " | | | |"
puts " | |_| |"
puts " ___| |\\___/"
puts " / \\___________/ \\"
puts " \\_____________________/ \n"
puts "==================================================="
desc "Remake database"
task :remakedb do
run "cd #{deploy_to}/current; bundle exec rake db:migrate RAILS_ENV=#{default_stage}"
run "cd #{deploy_to}/current; bundle exec rake db:seed RAILS_ENV=#{default_stage}"
end
desc "Seed database"
task :seed do
run "cd #{deploy_to}/current; bundle exec rake db:seed RAILS_ENV=#{default_stage}"
end
desc "Migrate database"
task :migrate do
run "cd #{deploy_to}/current; bundle exec rake db:migrate RAILS_ENV=#{default_stage}"
end
desc "Bundle install gems"
task :bundle do
run "cd #{deploy_to}/current; bundle install --deployment"
end
namespace :assets do
desc "Run the precompile task remotely"
task :precompile, :roles => :web, :except => { :no_release => true } do
run "cd #{deploy_to}/current; bundle exec rake assets:precompile RAILS_ENV=#{default_stage}"
end
end
end
after "deploy", "deploy:bundle"
after "deploy", "deploy:assets:precompile"
after "deploy", "deploy:migrate"
after "deploy", "deploy:cleanup"
after "deploy", "restart"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment