Agile Development Workflow Part 2 - Love the sync
Continuation of Agile Development Workflow Part 1 - Setup (I’d start there).
My lively-hood depends on the sync. It’s really what pulls all my projects together and unifies my workflow. It allows me to develop in numerous web technologies like Ruby On Rails, PHP, Django, Catalyst with relative ease, all at once. The Sync process is based on customized rsync commands. Assuming that you set up ssh properly (see Part 1), all we have to do now is create our shell script that does the heavy lifting for us. Essentially we’re pushing all of our changes up to the server as we see fit. Rsync can be customized to upload only the files that change with relative ease.
The first thing we’ll want to do is create the sync file which will be responsible for handling the rsync process. In the command line do:
macAttack: kb$ sudo touch /usr/bin/sync
macAttack: kb$ sudo chmod +x /usr/bin/sync
macAttack: kb$ mate /usr/bin/sync
You should be staring at an empty file. What we want to do is replicate the process you would usually do to push the site up live, or upload it to your development server via ftp.
It’s important that you have a consistent directory structure for your websites to get all of these “rules” setup (assuming that you’ll be working with multiple sites) properly. It will allow us to setup new rules with minimal effort.
I use Subversion (svn) for all of my projects and because of this I have a common directory structure for most of my web apps. It looks like this:
macAttack: kb$ /Development/Project/trunk/
For branches the directory structure looks like this:
macAttack: kb$ /Development/Project/branches/name
The beauty of syncing is all changes get moved over, overwriting the previous files so you rarely run into any sync errors and if you do it’s usually user error.
Here are the contents of my sync script (simplified)
#!/bin/bash
REPO=”"
SRC=”"
BRANCH=”"
DEV=”Development”
HOME=”/Users/kb”
case $1 in
s)
rsync –exclude-from=$HOME/.rsync-exclude -e “ssh” -ruv $HOME/$DEV/somedirection/trunk/blog/ serveradmin@mediatemple.com:~/domains/somedirection.com/html/
exit
;;
*) echo “Unrecognized”
;;
esac
Let’s break it down.
- –exclude-from=$HOME is setup to be the same path that relates to ~/. In my user home dir ~/ there’s a file named .rsync-exclude, this file is a line-break separated list of filenames we want to exclude in our sync. Check out my exclude list » rsync exclude. The exclude list prevents .svn (subversion dir’s) from being pushed to the remote server, so you can work on a checked out copy of your web project, but the server only gets what it needs without any unnecessary files.
- -e “ssh” tells rsync to go over ssh to sync the files, since we already set up ssh to enable auto-login to the remote server we won’t be prompted to provide a password on every sync (and you will sync alot).
- finally we pass the parameters -ruv -r, –recursive recurse into directories #this way you only have to pass a top level path -u, –update update only (don’t overwrite newer files) #it’s important that your computers internal clock matches the remote servers -v, –verbose increase verbosity
- The Local Path: $HOME/$DEV/somedirection/trunk/blog/
- The Remote Path: serveradmin@mediatemple.com:~/domains/somedirection.com/html/ => username@remotehost:remotepath
If the following command is run from from Terminal:
macAttack: kb$/usr/bin/sync s
Rsync is a powerful tool, can work wonders with backups as well.
Let me know if you found this article helpful and give feedback. Stay tuned for Sync integration with TextMate that will really put your whole dev process in overdrive!
Popularity: 22% [?]
