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/*
# Purge the CDN
cat $TMPFILE | grep "\] <fc...... " | cut -d \  -f 5 | while read -r filename; do
echo "Purge$filename"; curl -X PURGE$filename; done
# Remove the tempfile
rm -f $TMPFILE