rsync is an open source utility that provides fast incremental file transfer.
You can use rsync with Rake to quickly deploy changes to your application on your remote host. For this you have to define a new Rake task in your Rakefile in the application directory:
<pre>
desc “Deploy basic application directories”
task :deploy => :environment do
dirs = %w{ app lib test public config}
onserver = “login@remotehost:/home/rails-app-directory/”
dirs.each do | dir|
`rsync -avz -e ssh “#{RAILS_ROOT}/#{dir}” “#{onserver}” —exclude “.svn”`
end
end
Change login to your login at your remote host and /home/rails-app-directory to the directory where your Rails app resides on the server. After that rolling out changes to your code on server is as simple as
<pre>
$cd /Sites/rails-site3
$rake deploy
This is a great tip as rsync is super fast and can work both ways. But rsync is too good just to be a nix only utility. There is also a Windows version available from ITeF!x that installs cygwin, ssh and all the other goodies to get you going on the Windows side.
Follow the installation instructions and you shouldn’t have any problems.
To make life easy I added the default install directory (C:\Program Files\cwRsync\bin) to my path. I also added a couple of system variables for cygwin: CYGWIN = nontsec and HOME = c:\path\to\home\directory.
Once you have rsync downloaded an installed you can alter the code above slightly to work on a Windows system.
<pre>
desc “Deploy basic application directories”
task :deploy => :environment do
dirs = %w{ app lib test public/images public/stylesheets public/javascripts db}
dirs.each do | dir|
onserver = “”mailto:username@yourdomain.com">username@yourdomain.com:/home/username/web/"
local = “/cygdrive/c/rails_app/” + dir
cmd = “rsync -arvz -e ssh #{local} #{onserver} —exclude \”.svn\" —exclude \“*~\” "
puts cmd
rsync = IO.popen(cmd, "r")
while line = rsync.gets
end
rsync.close
end
end
Notice that in the local assignment I’m not using “#{RAILS_ROOT}/”. This is because of the way cygwin has to access the NT (or FAT I suppose) file system. “/cygdrive/c/rails_app/” evaluates to “c:\rails_app”. Notice also that I added another exclude for files ending with ~. This is because I use VIM and it leaves these files all over and I haven’t gotten around to another solution but this should serve as an example of how to exclude other file types.
Once last piece of goodness. If you’re using Textdrive (and why wouldn’t you?) then you can set up certificates to authenticate with rsync instead of a password.
Here’s how it works. Open a command prompt. If you’ve added C:\Program Files\cwRsync\bin to the path then the ssh command should be available from the command line.
Type this:
<pre>
ssh-keygen -d
You will be prompted to save the key to a file. Choose a location otherwise it will default to the value in your $HOME + \id_dsa. When prompted for a passphrase you can leave it blank.
Now upload the file you just created (id_dsa.pub) to Textdrive into your /home/username/.ssh directory and rename it to authorized_keys if this file doesn’t exist otherwise copy the contents of your file into the end of the authorized_keys file. Note that you must upload the “id_dsa.pub” file, not the “id_dsa” file. One is your public key and the other is your private key.
Once this is done you know have a way to authenticate yourself via certificate from your machine to the Textdrive server. This means that when you run the “rake deploy” command you won’t be prompted for a password each time because you are authenticating via public/private keys.
This last part was derived from an KB article on Textdrive.
rsync is an open source utility that provides fast incremental file transfer.
You can use rsync with Rake to quickly deploy changes to your application on your remote host. For this you have to define a new Rake task in your Rakefile in the application directory:
<pre>
desc “Deploy basic application directories”
task :deploy => :environment do
dirs = %w{ app lib test public config}
onserver = “login@remotehost:/home/rails-app-directory/”
dirs.each do | dir|
`rsync -avz -e ssh “#{RAILS_ROOT}/#{dir}” “#{onserver}” —exclude “.svn”`
end
end
Change login to your login at your remote host and /home/rails-app-directory to the directory where your Rails app resides on the server. After that rolling out changes to your code on server is as simple as
<pre>
$cd /Sites/rails-site3
$rake deploy
This is a great tip as rsync is super fast and can work both ways. But rsync is too good just to be a nix only utility. There is also a Windows version available from ITeF!x that installs cygwin, ssh and all the other goodies to get you going on the Windows side.
Follow the installation instructions and you shouldn’t have any problems.
To make life easy I added the default install directory (C:\Program Files\cwRsync\bin) to my path. I also added a couple of system variables for cygwin: CYGWIN = nontsec and HOME = c:\path\to\home\directory.
Once you have rsync downloaded an installed you can alter the code above slightly to work on a Windows system.
<pre>
desc “Deploy basic application directories”
task :deploy => :environment do
dirs = %w{ app lib test public/images public/stylesheets public/javascripts db}
dirs.each do | dir|
onserver = “”mailto:username@yourdomain.com">username@yourdomain.com:/home/username/web/"
local = “/cygdrive/c/rails_app/” + dir
cmd = “rsync -arvz -e ssh #{local} #{onserver} —exclude \”.svn\" —exclude \“*~\” "
puts cmd
rsync = IO.popen(cmd, "r")
while line = rsync.gets
end
rsync.close
end
end
Notice that in the local assignment I’m not using “#{RAILS_ROOT}/”. This is because of the way cygwin has to access the NT (or FAT I suppose) file system. “/cygdrive/c/rails_app/” evaluates to “c:\rails_app”. Notice also that I added another exclude for files ending with ~. This is because I use VIM and it leaves these files all over and I haven’t gotten around to another solution but this should serve as an example of how to exclude other file types.
Once last piece of goodness. If you’re using Textdrive (and why wouldn’t you?) then you can set up certificates to authenticate with rsync instead of a password.
Here’s how it works. Open a command prompt. If you’ve added C:\Program Files\cwRsync\bin to the path then the ssh command should be available from the command line.
Type this:
<pre>
ssh-keygen -d
You will be prompted to save the key to a file. Choose a location otherwise it will default to the value in your $HOME + \id_dsa. When prompted for a passphrase you can leave it blank.
Now upload the file you just created (id_dsa.pub) to Textdrive into your /home/username/.ssh directory and rename it to authorized_keys if this file doesn’t exist otherwise copy the contents of your file into the end of the authorized_keys file. Note that you must upload the “id_dsa.pub” file, not the “id_dsa” file. One is your public key and the other is your private key.
Once this is done you know have a way to authenticate yourself via certificate from your machine to the Textdrive server. This means that when you run the “rake deploy” command you won’t be prompted for a password each time because you are authenticating via public/private keys.
This last part was derived from an KB article on Textdrive.