-
-
Save davethegr8/c0e421317da9916811ca to your computer and use it in GitHub Desktop.
This file contains 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 | |
# 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