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.
set :shared_children, %w(config logs) # Shared directories, these directories contain generated content which should not be wiped out during deployments.
set :application, "domain.com" # Application name
set :deploy_to, "/var/www/#{application}/#{stage}" # Path where files are deployed to ...
# Commands on the server are run as the following user :
set :runner, "website"
set :user, "website"
set :use_sudo, false # sudo isn't required for my deployment.
set :scm, :bzr # I am using bazaar, so I specify it here
set :deploy_via, :export # This will use bzr export as the method of obtaining the code from the repository.
set :repository, "/home/user/repositories/domain.com" # This is the path to the code repository on the server, remember when you pushed the code up to the server?
role :web, "#{application}"
ssh_options[:keys] = %w(/home/user/.ssh/private_key) # SSH 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