|
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, "[email protected]: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 |
Various steps above in ansible could be done in a preceding play and set using "local_action" versus remote ops. Thus the two steps you have above are not quite equivalent.
Also make sure you are using Control Persist and pipelining mode for maximum performance benefits, (see ansible.cfg for pipelining, off by default).
Ultimately though the amount of time you have posted above makes it sound like there's really a DNS issue going on here.
If you are in fact using -c ssh on a system that isn't new enough to support ControlPersist, you're better off with ansible using paramiko, which is what fabric uses. Depends on what OS you are running but Ansible will choose a default smartly.
I'm also a bit confused by the git checkout and then doing the rsync, where as I believe Fabric is just doing a symlink. Still, rsync should be fast locally, I'm not quite following the need for that step if everything is in git and ansible is also creating the symlink.
I'd probably also check to see if you are benchmarking repeated runs and such, but I'm unable to read the Fabric enough to understand what it's doing.