Skip to content

Instantly share code, notes, and snippets.

@davethegr8
Forked from bettin/deploy.sh
Last active August 29, 2015 14:16
Show Gist options
  • Save davethegr8/c0e421317da9916811ca to your computer and use it in GitHub Desktop.
Save davethegr8/c0e421317da9916811ca to your computer and use it in GitHub Desktop.
#!/bin/bash
# Requires s3cmd
# https://github.com/s3tools/s3cmd
# Variables
LIVE_BUCKET="s3://$1"
SITE_DIR='_site/' # run this script from your Jekyll root folder.
##
# Usage:
# ./deploy.sh S3_Bucket_Name
# ./deploy.sh www.yourjekyllsite.com
# Check for argument
if (( $# != 1 ))
then
echo "Whoops, you forgot to include the S3 Bucket."
echo "Usage: deploy.sh S3_Bucket_Name "
exit 1
fi
echo '===================================='
echo 'Build and deploy for site:'
echo $1
echo '===================================='
echo -e '\nBuilding Jekyll site.'
jekyll build
echo -e '> Done.\n'
echo 'Compress .html, .css and .js files.'
find $SITE_DIR \( -iname '*.html' -o -iname '*.css' -o -iname '*.js' \) -exec gzip -9 -n {} \; -exec mv {}.gz {} \;
echo -e "> Done.\n"
echo "Sync to Amazon S3 Bucket: $LIVE_BUCKET"
# sync gzipped html/css/js files
s3cmd sync --progress -M --acl-public --delete-removed --add-header 'Cache-Control: max-age=600' --add-header 'Content-Encoding:gzip' _site/ $LIVE_BUCKET --exclude '*.*' --include '*.html' --include '*.js' --include '*.css'
# sync other files (not html/js/css)
s3cmd sync --progress -M --acl-public --delete-removed --add-header 'Cache-Control: max-age=600' --exclude '*.html' --exclude '*.js' --exclude '*.css' --exclude '*.sh' --exclude '.DS_Store' --exclude 'README.md' _site/ $LIVE_BUCKET
echo '> Done.'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment