Managing code releases

Recently I decided to streamline my code release process. I use subversion for my source control which means I push code live by running svn up on each of our production servers. I’m lazy, so I wanted an easier way to do this all at once. The end result is a simple shell script that lets me run svn update commands on multiple servers at once. It shows me the status of svn on each server and gives me chance to confirm that everything is okay before going ahead with the launch.

This example assumes you have two servers (app1 and app2) that are using public key authentication. Obviously, you’ll need to modify this script to work in your own environment. Make sure you replace “/var/www/” with your own document root and change appX.yourdomain.com to the IP address of each production server.

#!/bin/sh

# connect to each server and echo their current status
echo "Connecting to app1...\n"
ssh app1.yourdomain.com 'cd /var/www/; svn status --show-updates; exit'
echo "\nConnecting to app2...\n"
ssh app2.yourdomain.com 'cd /var/www/; svn status --show-updates; exit'
# add additional servers here as needed
tput smso
# confirm the release before publishing
echo "\nDo you want to publish these changes to production? (y/n)\n"
tput rmso
read answer
if [ $answer == "y" ]; then
    # if "y", proceed with the release
    echo "\nPublishing to production..."
    echo "\nPublishing to app1..."
    ssh app1.yourdomain.com 'cd /var/www/; svn up; exit'
    echo "\nPublishing to app2..."
    ssh app2.yourdomain.com 'cd /var/www/; svn up; exit'
    # add additional servers here as needed
    echo "\nDone"
else
    # if "n", cancel the release.
    echo "\nCanceled"
    exit;
fi