Skip to content

Instantly share code, notes, and snippets.

@jakcharlton
Created January 20, 2013 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakcharlton/4577995 to your computer and use it in GitHub Desktop.
Save jakcharlton/4577995 to your computer and use it in GitHub Desktop.
Basic cap script
require 'net/https'
require 'json'
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
default_run_options[:pty] = true
set :application, 'porpoise'
set :repository, "git@bitbucket.org:fairfax/china-#{application}.git"
set :scm, :git
set :scm_verbose, true
set :deploy_via, :remote_cache # A checked-out copy of the repo that is then updated and copied as necessary.
set :bundle_cmd, "/var/lib/gems/1.9.1/bin/bundle"
# Use the local user's keys for convenience. (May not be applicable here.)
set :ssh_options, { forward_agent: false }
set :runner, "updatebot"
set :user, "updatebot"
set :use_sudo, false
ssh_options[:keys] = %w(~/.ssh/updatebot_ssh)
ssh_options[:user] = "updatebot"
ssh_options[:port] = 22
ssh_options[:forward_agent] = false
namespace :deploy do
task :full do
update_code
assets
check_env
uploads_symlink
symlink
setup_db
restart
end
task :assets do
run "cd #{release_path} && RAILS_ENV=#{rails_env} /var/lib/gems/1.9.1/bin/bundle exec rake assets:precompile"
end
task :check_env do
# Will it float?
run "if [ ! -d #{shared_path}/pids ]; then mkdir -p #{shared_path}/pids; fi"
end
task :uploads_symlink do
run "if [ ! -L #{release_path}/public/images ]; then rm -rf #{release_path}/public/images; fi"
run "if [ ! -e #{release_path}/public/images ]; then ln -sv #{shared_path}/images #{release_path}/public/images; fi"
end
task :restart, except: { no_release: true } do
run "touch #{release_path}/tmp/restart.txt"
end
task :setup_db do
run "cd #{current_path} && RAILS_ENV=#{rails_env} /var/lib/gems/1.9.1/bin/bundle exec rake db:setup"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment