Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jianyuan/248987 to your computer and use it in GitHub Desktop.
Save jianyuan/248987 to your computer and use it in GitHub Desktop.
# This requires the capistrano-ext and railsless-deploy gems
#
# Github are disabling their gems service after 1 year starting from 2009, refer to
# http://github.com/leehambley/railsless-deploy for any updates concerning this.
#
# gem sources -a http://gems.github.com/
# sudo gem install capistrano-ext
# gem install leehambley-railsless-deploy
# ----------------------------------------------------------------------------
# Capistrano settings
# ----------------------------------------------------------------------------
set :shared_children, %w(config upload logs)
# ----------------------------------------------------------------------------
# Application settings
# ----------------------------------------------------------------------------
set :application, "website.com"
set :deploy_to, "/var/www/website.com/#{stage}"
set :runner, "website"
set :user, "website"
set :use_sudo, false
# ----------------------------------------------------------------------------
# Repository settings
# ----------------------------------------------------------------------------
set :scm, :bzr
set :deploy_via, :export
set :repository, "/var/www/repositories/website.com/" # This can be a github repository, etc ... mine is local.
# ----------------------------------------------------------------------------
# Role settings
# ----------------------------------------------------------------------------
role :web, "#{application}"
# ----------------------------------------------------------------------------
# SSH settings
# ----------------------------------------------------------------------------
ssh_options[:keys] = %w(/home/mathew/.ssh/private_key)
ssh_options[:port] = 22
namespace :deploy do
desc <<-DESC
[internal] Touches up the released code. This is called by update_code
after the basic deploy finishes. It assumes a Rails project was deployed,
so if you are deploying something else, you may want to override this
task with your own environment's requirements
DESC
task :finalize_update, :except => { :no_release => true } do
# link log and upload directories
run "rmdir #{latest_release}/application/logs"
run "rmdir #{latest_release}/upload"
run "ln -s #{shared_path}/logs #{latest_release}/application/logs"
run "ln -s #{shared_path}/upload #{latest_release}/upload"
# copy configuration files
run "cp -rf #{shared_path}/config/ #{latest_release}/application/"
# copy index.php
run "cp -f #{shared_path}/index.php #{latest_release}/index.php"
# chmod directories and files
run "find #{shared_path} -type d -exec chmod 0755 {} \\;"
run "find #{latest_release} -type d -exec chmod 0755 {} \\;"
run "find #{latest_release} -type f -exec chmod 644 {} \\;"
end
namespace :web do
task :disable do
run "cp #{shared_path}/maintenance.html #{latest_release}"
run "echo #{stage}"
end
task :enable do
run "rm -f #{latest_release}/maintenance.html"
end
end
end
after "deploy:update_code", "deploy:web:disable"
after "deploy:symlink", "deploy:web:enable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment