Skip to content

Instantly share code, notes, and snippets.

@dprabu17
Last active August 29, 2015 13:59
Show Gist options
  • Save dprabu17/10956079 to your computer and use it in GitHub Desktop.
Save dprabu17/10956079 to your computer and use it in GitHub Desktop.
Capistrano
#require 'capistrano/ext/multistage'
require "rvm/capistrano"
require "bundler/capistrano"
set :application, "set your application name here"
set :rails_env, 'production'
set :rvm_type, :system
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :copy_exclude, [ '.git' ]
set :repository, "set your repository location here"
set :branch, fetch(:branch, "master")
set :env, fetch(:env, "production")
set :deploy_to, "/home/webapps/www/rails3deployment"
set :backup_to, "/home/webapps/backups"
set :copy_dir, "/home/prabu/tmp"
set :remote_copy_dir, "/tmp"
set :use_sudo, true
role :web, "your web-server here" # Your HTTP server, Apache/etc
role :app, "your app-server here" # This may be the same as your `Web` server
role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
role :db, "your slave db-server here"
set :user, "deployer"
set :scm_passphrase, "p@ssw0rd" # The deploy user's password
set :deploy_via, :remote_cache # you want to use this option, otherwise each deploy will do a full repository clone every time.
default_run_options[:pty] = true #Must be set for the password prompt
set :normalize_asset_timestamps, false #turn off default behavior /public/images
namespace :deploy do
task :start do ; end
task :stop do ; end
desc "Restart the application"
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
#run assets precompile
namespace :assets do
task :precompile, :roles => :web, :except => {:no_release => true} do
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} assets:precompile}
end
end
end
end
desc "Run rake db migrate on server"
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env}"
end
desc "Copy the database.yml file into the latest release"
task :copy_in_database_yml do
run "cp #{shared_path}/config/database.yml #{latest_release}/config/"
end
desc "Create symbolic links for assets "
task :symlink_assets, roles: :web do
run "rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets"
end
after "deploy:restart", "deploy:cleanup"
before "deploy:restart", "copy_in_database_yml"
before "deploy:restart", "deploy:assets:precompile"
before "deploy:restart", "run_migrations"
#http://capitate.rubyforge.org/recipes/deploy.html#deploy:finalize_update
before 'deploy:finalize_update', 'symlink_assets'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment