|
load 'deploy' if respond_to?(:namespace) # cap2 differentiator |
|
|
|
# general config |
|
set :application, "myapp" |
|
set :valid_environments, ["staging","production"] |
|
set :user, "deployer" |
|
|
|
# git config |
|
set :scm, :git |
|
set :repository, "git@github.com:my/repo.git" |
|
set :branch, "master" |
|
set :deploy_via, :remote_cache |
|
|
|
|
|
default_run_options[:pty] = true |
|
# set :use_sudo, true |
|
# ssh_options[:forward_agent] = true |
|
set :current_dir, "myapp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace :deploy do |
|
|
|
desc "Sets up basic directory structure on target server" |
|
task :setup, :except => { :no_release => true } do |
|
dirs = [deploy_to, releases_path, shared_path] |
|
dirs += shared_children.map { |d| File.join(shared_path, d) } |
|
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}" |
|
end |
|
|
|
|
|
desc <<-DESC |
|
Updates the symlink to the most recently deployed version. Capistrano works \ |
|
by putting each new release of your application in its own directory. When \ |
|
you deploy a new version, this task's job is to update the `current' symlink \ |
|
to point at the new version. You will rarely need to call this task \ |
|
directly; instead, use the `deploy' task (which performs a complete \ |
|
deploy, including `restart') or the 'update' task (which does everything \ |
|
except `restart'). |
|
DESC |
|
task :create_symlink, :except => { :no_release => true } do |
|
on_rollback do |
|
if previous_release |
|
run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" |
|
else |
|
logger.important "no previous release to rollback to, rollback of symlink skipped" |
|
end |
|
end |
|
|
|
# delete the old and create a new symlink to the latest release |
|
run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}" |
|
|
|
# delete the uploads directory out of the new codebase if it exists. then symlink the uploads directory to there. |
|
# run "rm -rf #{latest_release}/app/assets/uploads && ln -s #{deploy_to}/shared/uploads #{latest_release}/app/assets/uploads" |
|
run "ln -s #{deploy_to}/shared/uploads #{latest_release}/app/assets/uploads" |
|
end |
|
|
|
|
|
|
|
desc <<-DESC |
|
Restarts your application. |
|
|
|
By default, this will be invoked via sudo as the 'app' user. If |
|
you are in an environment where you can't use sudo, set |
|
the :use_sudo variable to false: |
|
|
|
set :use_sudo, false |
|
DESC |
|
task :restart, :roles => :app, :except => { :no_release => true } do |
|
run "#{sudo} chown -R www-data:www-data /var/apps/myapp/shared/uploads/" |
|
run "#{sudo} /etc/init.d/apache2 reload" |
|
end |
|
|
|
|
|
|
|
desc <<-DESC |
|
[internal] Touches up the released code. This is called by update_code \ |
|
after the basic deploy finishes. |
|
|
|
This task will make the release group-writable (if the :group_writable \ |
|
variable is set to true, which is the default). It will then change \ |
|
ownership of the release and the symlink that was created if the owners \ |
|
variable exists. |
|
DESC |
|
task :finalize_update, :except => { :no_release => true } do |
|
# run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) |
|
run "#{sudo} chown -R #{owners} #{current_path}" if exists?("owners") |
|
run "#{sudo} chown -R #{owners} #{latest_release}" if exists?("owners") |
|
end |
|
|
|
end |
I would be to know whether capistrano is checking out the whole history or just the head revision?
There's a bit too much automagic here to see where it's checking out the repo and doing the git commands.
SSH overhead between tasks, even untuned and using the wrong connection plugins, should be around .5 seconds or less, and you have a small number of tasks here -- so something is definitely up and/or very different.