Skip to content

Instantly share code, notes, and snippets.

@kenbarbour
Created November 8, 2016 14:01
Show Gist options
  • Save kenbarbour/eeb15c0aabf03da77d4a0492e30cf674 to your computer and use it in GitHub Desktop.
Save kenbarbour/eeb15c0aabf03da77d4a0492e30cf674 to your computer and use it in GitHub Desktop.
A simple deploy script to pull from git before rsyncing to servers
#!/bin/bash
set -e # Stop on any error
# Path on this machine to source code (omit trailing slash)
SOURCEPATH=~/deploy/myproject
# Path on remote server to place source code (omit trailing slash)
DESTPATH=/var/www/myproject
# Space separated list of hosts
SERVERS="[email protected] [email protected]"
# Perform a git pull before deploying
( cd $SOURCEPATH ; git pull )
for SERVER in $SERVERS
do
IFS=':'
read HOST PORT <<< "$SERVER"
if [ -z "$PORT" ]
then
PORT=22
fi
rsync -rz -e "ssh -p $PORT" --delete $SOURCEPATH/ $HOST:$DESTPATH/
done
echo "Deployment successful."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment