Created
November 8, 2016 14:01
-
-
Save kenbarbour/eeb15c0aabf03da77d4a0492e30cf674 to your computer and use it in GitHub Desktop.
A simple deploy script to pull from git before rsyncing to servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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