Skip to content

Instantly share code, notes, and snippets.

@e1senh0rn
Forked from antonversal/deploy.rb
Created December 14, 2010 11:51
Show Gist options
  • Save e1senh0rn/740315 to your computer and use it in GitHub Desktop.
Save e1senh0rn/740315 to your computer and use it in GitHub Desktop.
set :stages, %w(staging production beta)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
# Ok, capistrano_recipes totally breaks not only multistage...
# require 'capistrano_recipes'
require 'capistrano_colors'
require 'bundler/capistrano'
require 'thinking_sphinx/deploy/capistrano'
require 'config/boot'
require 'hoptoad_notifier/capistrano'
set :shared_children, %w( config bundle tmp log system sphinx )
set :scm, :git
set :git_enable_submodules, true
set :deploy_via, :remote_cache
set :scm_verbose, true
set :repository, "[email protected]:l8/zn_new.git"
set :branch, "master"
set :run_options, { :pty => true }
set :ssh_options, { :forward_agent => true }
set :use_sudo, false
set :bundle_flags, "--deployment"
set :bundle_without, [:development, :test, :cucumber, :autotest]
on :start do
`ssh-add`
end
set :normal_symlinks, %w(
config/newrelic.yml
config/database.yml
config/unicorn.conf.rb
)
normal_symlinks << "config/newrelic.yml" unless fetch(:skip_newrelic, true)
set :weird_symlinks, {
'bundle' => 'vendor/bundle',
'tmp' => 'tmp',
'sphinx' => 'db/sphinx'
}
after "deploy:setup", "deploy:config_setup"
after "deploy:finalize_update", "deploy:app_symlinks"
before 'deploy:symlink', 'assets:package'
namespace :deploy do
task :default do
thinking_sphinx.stop
update
migrate
restart
thinking_sphinx.configure
thinking_sphinx.start
cleanup
end
desc "Start unicorn"
task :start, :roles => :app do
run "cd #{current_path} && rake app:unicorn:start" if fetch(:web_server, nil) == :unicorn
end
desc "Stop unicorn"
task :stop, :roles => :app do
run "cd #{current_path} && rake app:unicorn:stop" if fetch(:web_server, nil) == :unicorn
end
desc "Restart unicorn"
task :restart, :roles => :app do
# run "cd #{current_path} && rake app:unicorn:restart"
case fetch(:web_server, nil)
when :unicorn
stop
start
when :passenger
run "touch #{release_path}/tmp/restart.txt"
end
end
task :app_symlinks do
normal_symlinks.map do |path|
run "rm -rf #{release_path}/#{path} && ln -nfs #{shared_path}/#{path} #{release_path}/#{path}"
end
weird_symlinks.map do |from, to|
run "rm -rf #{release_path}/#{to} && ln -s #{shared_path}/#{from} #{release_path}/#{to}"
end
end
desc "Copy *.example.yml to *.yml"
task :config_setup do
normal_symlinks.map do |path|
top.upload path, "#{shared_path}/#{path}"
end
end
task :seed do
run "cd #{current_path}; rake RAILS_ENV=#{variables[:rails_env]} db:seed"
end
end
namespace :assets do
desc 'Update package javascripts & stylesheets'
task :package, :roles => :app do
run "cd #{release_path} && RAILS_ENV=#{rails_env} rake assets:package_stylesheets"
end
end
@darkside
Copy link

capistrano_recipes breaks if you're using bundler, gotta call bundle exec or bin/cap for it to work ;)

@e1senh0rn
Copy link
Author

Thanx for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment