Skip to content

Instantly share code, notes, and snippets.

@randika
Created March 14, 2012 15:50
Show Gist options
  • Save randika/2037413 to your computer and use it in GitHub Desktop.
Save randika/2037413 to your computer and use it in GitHub Desktop.
Capistrano receip
set :application, "myapp-name"
set :repository, "."
set :deploy_via, :copy
set :scm, :git
set :branch, "master"
set :user, "ubuntu"
set :use_sudo, false
set :deploy_to, "/home/ubuntu/webapps/myapp-name"
set :server, :passenger
set :location, "ec2-184-73-xx-xxx.compute-1.amazonaws.com"
server "ec2-184-73-xx-xxx.compute-1.amazonaws.com", :app, :web, :db, :primary => true
ssh_options[:keys] = ["#{ENV['HOME']}/workspace/env/keys/ec2dev.pem"] # make sure you also have the public key
# ==============================
# Bundler
# ==============================
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
bundler.create_symlink
run "cd #{release_path} && bundle install --without test"
end
end
# ==============================
# Uploads
# ==============================
namespace :uploads do
desc <<-EOD
Creates the upload folders unless they exist
and sets the proper upload permissions.
EOD
task :setup, :except => { :no_release => true } do
dirs = uploads_dirs.map { |d| File.join(shared_path, d) }
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
end
desc <<-EOD
[internal] Creates the symlink to uploads shared folder
for the most recently deployed version.
EOD
task :symlink, :except => { :no_release => true } do
run "rm -rf #{release_path}/public/uploads"
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
desc <<-EOD
[internal] Computes uploads directory paths
and registers them in Capistrano environment.
EOD
task :register_dirs do
set :uploads_dirs, %w(uploads)
set :shared_children, fetch(:shared_children) + fetch(:uploads_dirs)
end
end
# ==============================
# Passenger
# ==============================
namespace :passenger do
desc "Restarting Application............"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
# =====================================
# have Capistrano automatically trust project rvmrc files
# =====================================
namespace :rvm do
task :trust_rvmrc do
run "rvm rvmrc trust #{release_path}"
end
end
# ======================================
# Set the default env in case it's not loading automatically
# ======================================
set :default_environment, {
'PATH' => "/home/ubuntu/.rvm/gems/ruby-1.9.2-p290/bin:/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/ubuntu/.rvm/rubies/ruby-1.9.2-p290/bin:/home/ubuntu/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$PATH",
'RUBY_VERSION' => 'ruby 1.9.2p290',
'GEM_HOME' => '/home/ubuntu/.rvm/gems/ruby-1.9.2-p290',
'GEM_PATH' => '/home/ubuntu/.rvm/gems/ruby-1.9.2-p290:/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@global'
}
after 'deploy:update_code', 'bundler:bundle_new_release'
after "deploy:migrations", "deploy:cleanup"
after "deploy:finalize_update", "uploads:symlink"
after "deploy", "rvm:trust_rvmrc"
on :start, "uploads:register_dirs"
after :deploy, "passenger:restart"
require "bundler/capistrano"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment