Skip to content

Instantly share code, notes, and snippets.

@MateuszKubuszok
Created July 26, 2018 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MateuszKubuszok/6e6cb24eb4d81ace2d570f70ab8644b4 to your computer and use it in GitHub Desktop.
Save MateuszKubuszok/6e6cb24eb4d81ace2d570f70ab8644b4 to your computer and use it in GitHub Desktop.
Publishing and testing Jekyll sites
#!/bin/bash --login
ThisDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$ThisDir/.."
if [ ! `command -v jekyll > /dev/null` ]; then
rvm use default ruby
bundle install
fi
JEKYLL_ENV=production bundle exec jekyll build
export AWS_ACCESS_KEY_ID="[access key]"
export AWS_SECRET_ACCESS_KEY="[secret]"
export AWS_DEFAULT_REGION="[S3 region]"
export BUCKET="[S3 bucket]"
export CF_DISTRIBUTION_ID="[CF]"
#!/bin/bash --login
ThisDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$ThisDir/config.sh"
if grep "http://localhost:4000" "$ThisDir/../_site/feed.xml" > /dev/null; then
echo Publish should be run after build.sh not serve.sh
echo -- preventing publishing developer version --
exit 1
fi
pushd $ThisDir/../_site/ > /dev/null
aws s3 sync --delete --size-only --no-progress --sse AES256 ./ s3://$BUCKET/ \
| sed 's/^(dryrun) //' \
| awk '{print "/"$2;}' \
| sed 's/\/.\//\//' \
| sed 's/index.html$//' \
| xargs --no-run-if-empty aws cloudfront create-invalidation --distribution-id $CF_DISTRIBUTION_ID --paths
popd > /dev/null
#!/bin/bash --login
ThisDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$ThisDir/.."
if [ ! `command -v jekyll > /dev/null` ]; then
rvm use default ruby
bundle install
fi
bundle exec jekyll serve --incrementa --draft --verbose
@MateuszKubuszok
Copy link
Author

MateuszKubuszok commented Jul 26, 2018

Requirements

  • AWS CLI installed
  • set up S3 bucket that is statically serving site and CF for that S3 resource on AWS
  • credentials with access to bucket and CF resources (I suggest creating a user just for it)

I set up CF mostly for free SSL certificate, so if you don't need it you might just remove the invalidation from the script.

Installation:

  • Create deployment directory.
  • Create files using gists above and chmod +x them.
  • Set up your credentials in config.sh - do not commit it! Add deployment/config.sh file to .gitignore.
  • Add 'deployment' to exclude in _config.yml.

Usage:

./deployment/serve.sh - test site locally

./deployment/build.sh && ./deployment/publish.sh - build production version and publish it to S3 with invalidations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment