Capistrano Deployment using rsync
Eingetragen von mir selbst. | 4 April, 2007 - 09:01 SoftwareThis was meant to be a comment to to this article here, where comments have unfortunately been closed, but trackbacks are still enabled (it seems). Let's see if it works.
Hi,
I am using your receipe, thanks very much! However, this will not actually only transfer the differences between releases, will it? Since cap creates a new directory for each release you could just as well use scp :(
This is especially bad for me because I have a single huge database fixture (~20MB) and the rest of the application is rather small (<1MB). "cap deploy" takes almost ten minutes just because of this single file.
Any ideas how to do this better? Is there a variable available in cap to refer to the "previous" release? Then you could do something like
cp -a #{previous_path} #{release_path}
rsync -avz --delete -e ssh ./ ........
UPDATE 2007.05.19
I found out how to "do it".
task :update_code, :roles => [:web] do
on_rollback { delete release_path, :recursive => true }
username = user || ENV['USER']
current_task.servers.each do |server|
run "/usr/bin/rsync --exclude=tmp/sessions/** -a \
#{current_release}/ #{release_path}" # cp fails on log/tmp files
puts `rsync -avz -e ssh "./" "#{username}@#{server}:#{release_path}" \
--exclude "tmp" --exclude "log" --exclude "_darcs" --exclude ".svn" --exclude "log"`
end
run <<-CMD
rm -rf #{release_path}/log &&
rm -rf #{release_path}/public/system &&
rm -rf #{release_path}/public/files &&
ln -nfs #{shared_path}/log #{release_path}/log &&
ln -nfs #{shared_path}/files #{release_path}/public/files &&
ln -nfs #{shared_path}/system #{release_path}/public/system &&
mkdir -p #{release_path}/tmp/{cache,pids,sessions,sockets} &&
chmod a+rwt #{release_path}/tmp/{cache,pids,sessions,sockets} &&
cd #{release_path}/config && ln -nfs db-mysql.yml database.yml && cd - &&
perl -pi -e "s/^RAILS_GEM_VERSION = '1.2.1'/RAILS_GEM_VERSION = '1.2.3'/;" \
#{release_path}/config/environment.rb
CMD
end
The last two lines are just to adjust for my different versions and database configuration. But this #{current_release} variable works like a charm. I have to use rsync (can't use cp) because there are unreadable files in the tmp/sessions directory (at least for my "deployment" user) that cp would fail on, and cp can't exclude files.
Works like a charm and only transmits files that actually have changed. Except for a small glitch in the 'symlink' task that once used the wrong path, I haven't found out why that happened yet.
Thanks!
Jens

