Skip to content

Instantly share code, notes, and snippets.

@caseyscarborough
Last active February 12, 2019 20:50
Show Gist options
  • Save caseyscarborough/5945304 to your computer and use it in GitHub Desktop.
Save caseyscarborough/5945304 to your computer and use it in GitHub Desktop.
A basic deploy.rb Capistrano script used to deploy Rails applications.
# I am currently using this script with with Capistrano v2.15.5
# for deployment of Rails 3.2.13 and Rails 4.0.0 applications on
# Passenger 4.0.7 with nginx/1.4.1.
require "rvm/capistrano"
set :rvm_ruby_string, 'default'
require "bundler/capistrano"
# Set application and username
set :application, "application-name.com"
set :user, "casey"
set :port, 2200 # Set default SSH port for server if other than 22
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :copy
set :use_sudo, false
# Point to application's git repository location
set :scm, :git
set :repository, "/path/to/repository/.git"
set :branch, "capistrano"
# Server information
role :web, "123.456.7.890"
role :app, "123.456.7.890"
role :db, "123.456.7.890", :primary => true
role :db, "123.456.7.890"
# Passenger
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:precompile_assets"
after "deploy:precompile_assets", "deploy:restart"
namespace :deploy do
# Task to run bundle install after application deployment
task :bundle_gems do
run "cd #{deploy_to}/current && bundle install"
end
# Task to precompile assets after application deployment
task :precompile_assets do
run "cd #{deploy_to}/current && RAILS_ENV=production rake assets:precompile --trace"
end
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment