Deploy with rsync and purge the CDN with curl

16.02.2015 by Stefan Wintermeyer

If you work with rsync to deploy static content to your webserver and what to purge those files from your Fastly CDN here is the script.

What the script does:

# Create a tempfile
#
tempfoo=`basename $0`
TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1
# Deploy
#
rsync -rlpcgoDvz --log-file=$TMPFILE --delete _site/* deployer@webserver-farm.example.com:/var/www/www.example.com/
# Purge the CDN
#
cat $TMPFILE | grep "\] <fc...... " | cut -d \  -f 5 | while read -r filename; do
echo "Purge http://www.example.com/$filename"; curl -X PURGE http://www.example.com/$filename; done
echo
# Remove the tempfile
#
rm -f $TMPFILE
CDN