Skip to content

Instantly share code, notes, and snippets.

@sundevilyang
Created October 26, 2012 01:45
Show Gist options
  • Save sundevilyang/3956495 to your computer and use it in GitHub Desktop.
Save sundevilyang/3956495 to your computer and use it in GitHub Desktop.
Deploying Rails 3 Apps with Git, Capistrano and Passenger
# app/config/
load 'deploy/assets'
set :rake, "bundle exec rake"
set :application, "Beijing Rubyist"
set :repository, "https://github.com/beijing-rubyist/bjrubyist.git"
set :scm, :git
role :web, "bjrubyist.org" # Your HTTP server, Apache/etc
role :app, "bjrubyist.org" # This may be the same as your `Web` server
role :db, "bjrubyist.org", :primary => true # This is where Rails migrations will run
role :db, "bjrubyist.org"
set :deploy_to, "/sg552/apps/bjrubyist/"
default_run_options[:pty] = true
# change to your username
set :user, "wenyang"
namespace :deploy do
task :start do
"sudo nginx"
end
task :stop do
"sudo nginx -s stop"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
namespace :assets do
task :precompile do
run "cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile "
end
end
desc "Copy database.yml to release_path"
task :cp_database_yml do
puts "=== executing my customized command: "
#puts "cp -r #{shared_path}/config/* #{release_path}/config/"
run "cp -r #{shared_path}/config/* #{release_path}/config/"
run "ln -s #{shared_path}/db/production.sqlite3 #{release_path}/db/production.sqlite3"
end
before "deploy:assets:precompile", :cp_database_yml

1. Set Up Git Repository

[localuser ~]$ cd projectdir  
[localuser projectdir]$ ssh [remoteuser@]host  
[remoteuser ~]$ mkdir projectdir.git  
[remoteuser ~]$ cd projectdir.git  
[remoteuser projectdir.git]$ git init --bare  
[remoteuser projectdir]$ exit  

#2. Set Up Capistrano

[localuser projectdir]$ gem install capistrano  
gem 'capistrano' #add to gem file  
[localuser projectdir]$ capify .  
[localuser projectdir]$ cap deploy  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment