Created
January 9, 2011 13:52
-
-
Save denmarkin/771701 to your computer and use it in GitHub Desktop.
Example capistrano receipe with bells and whistles. See for details/supported features: http://denmarkin.tumblr.com/post/2667677553/capistrano-receipe-with-bells-and-wistles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :application, "myapp" | |
# github stuff | |
set :repository, "[email protected]:exampleAcc/myapp.git" | |
set :scm, :git | |
set :scm_username, "github_id" | |
set :scm_passphrase, "github_password" | |
set :branch, "dev" | |
set :git_enable_submodules, 1 | |
set :use_sudo, false | |
set :deploy_to, "/home/user/rails_apps/#{application}" | |
#server login | |
set :user, "ssh_login" | |
set :password, "ssh_password" | |
set :mysql_user, "mysql_login" | |
set :mysql_password, "mysql_password" | |
ssh_options[:forward_agent] = true | |
default_run_options[:pty] = true # see http://www.mail-archive.com/[email protected]/msg07323.html for details | |
server "xx.xx.xx.xx", :app, :web, :db, :primary => true | |
# gem dependencies | |
# you should specify versions for each gem, because it expects 2 args | |
# see http://mislav.uniqpath.com/rails/specify-your-dependencies-with-capistrano/ | |
depend :remote, :gem, "ruby-debug", ">=0.10.4" | |
depend :remote, :gem, "mysql", ">=2.8.1" | |
depend :remote, :gem, "acts_as_state_machine", ">=2.2.0" | |
depend :remote, :gem, "echoe", ">=4.3.1" | |
depend :remote, :gem, "RedCloth", ">=4.2.3" | |
# web-server (specific for passenger) | |
namespace :deploy do | |
task :start do ; end | |
task :stop do ; end | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" | |
end | |
end | |
# gems installation | |
# see http://henrik.nyh.se/2008/10/cap-gems-install-and-a-gem-dependency-gotcha | |
namespace :gems do | |
desc "Install gems" | |
task :install, :roles => :app do | |
run "cd #{current_release} && #{sudo} rake RAILS_ENV=production gems:install" | |
end | |
end | |
# database.yml generation | |
# see http://shanesbrain.net/2007/5/30/managing-database-yml-with-capistrano-2-0 | |
require 'erb' | |
before "deploy:setup", :db | |
after "deploy:update_code", "db:symlink" | |
namespace :db do | |
desc "Create database yaml in shared path" | |
task :default do | |
db_config = ERB.new <<-EOF | |
base: &base | |
adapter: mysql | |
socket: /var/run/mysqld/mysqld.sock | |
username: #{mysql_user} | |
password: #{mysql_password} | |
development: | |
database: #{application}_dev | |
<<: *base | |
test: | |
database: #{application}_test | |
<<: *base | |
production: | |
database: #{application}_prod | |
<<: *base | |
EOF | |
run "mkdir -p #{shared_path}/config" | |
put db_config.result, "#{shared_path}/config/database.yml" | |
end | |
desc "Make symlink for database yaml" | |
task :symlink do | |
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment