I just ran into the problem of trying to deploy code from an SVN repository to a machine that couldn’t access the repo (corporate firewall in the way). Since manually keeping tabs of which files were changed and pushing by hand sucks, and doing clean builds for minor changes is a time sink, a better way had to be found.

#!/bin/bash

#get latest contents from svn and pull out touched files
svn up | egrep "^A |^U " > updates.txt

#start a manifest of files to push
echo "cd /deploy/path/on/remote/host” > sftp_batch.txt

cat updates.txt | while read line
do
   FILEPATH=${line:5}
   #add command to push the files from your local machine to the remote host
   echo “put $FILEPATH $FILEPATH” >> sftp_batch.txt
done

sftp -b sftp_batch.txt user@remote.host

I have a working folder /work/sitename-dev in which I do all of my development, and a clean check-out of the same repo at /work/sitename-deploy. By tossing the above script into the deploy folder I can work and commit to the repo as often as I like from the dev folder without keeping tabs on my changes.

When it comes time to update the live site, just run the script. This updates the contents of the deploy folder, builds a manifest of touched files and passes that manifest to SFTP as a batchfile for promotion.

Caveats

  • I know this doesn’t address deletions from the SVN repo, but I don’t need that functionality now, so I didn’t write it. You can thought.
  • You need to install your ssh keys for SFTP to work in a scripted manner like this.

If anyone finds this useful, I’d love to know.

  • Digg
  • del.icio.us
  • feedmelinks
  • Reddit
  • NewsVine
  • StumbleUpon
  • Technorati

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*