Remote Deployment with Ant and Rsync

Remote Deployment with Ant and Rsync - this tutorial will teach us how to deploy projects on a remote server. This is very suitable especially for those who implements Continuous Integration where you will deploy projects upon every successful build or after passing all through unit tests, code analysis, and load testing.

Ant sample buildfile

Add this to your Ant's buidlfile (e.g. build.xml)

<target name="deploy">
<exec dir="." executable="rsync" failonerror="true">
<arg line="-aog -e ssh " /var/www/html/sites/ ${remote.user}@${remote.address}:/var/www/html/sites/ />

SSH Public Key

- This will prevent Ant from sending out an error message because your password couldn' be sent.

Check Your SSH Public Key

Check the public key on your computer by running this command.

$ ls -al ~/.ssh/

Create Your SSH Public Key

Run this command if you still don't have a public key.

$ ssh-keygen -t rsa

Copy SSH Public Key

Let's build the connection between your local and remote server by copying the public key from your local server to remoteserver and saving it in the authorized_keys file.

$ scp ~/.ssh/

remoteserver$ cat ~/ >> ~/.ssh/authorized_keys

Next time that you login by SSH from your computer to the server, it will stop asking for a password and the Ant task will stop complaining.

For added security, when you create your key, use a passphrase.

Don't forget to put the passphrase into the sshexec task.

Don't use the passphrase if you put the build.xml file in CVS or SVN, because your co-workers will see your passphrase and also they won't be able to use the sshexec task unless they use the same passphrase as you.