Automate Everything

January 30, 2016

It’s pretty easy to host a static site on Amazon, all you have to do is copy files to an S3 bucket, update a couple of properties on the bucket, and voila! You can upload files via the GUI, but it’s relatively time consuming and definitely repetitive. Naturally there is an easier way.

I wrote the following script to deploy my site in one step. It manages the environments, jekyll build, and copying of files in one step. It even removes the extensions from my blog posts so that I have cleaner URL paths.



rm -rf _site/
JEKYLL_ENV="production" jekyll build

# deploy main site
s3cmd put -r --exclude='blog.html' --exclude='posts/*' _site/ s3://

# deploy blog
s3cmd put _site/blog.html s3://
s3cmd put _site/error.html s3://

# strip extension so we can serve clean urls
for POST in $(ls -1 _site/posts/); do
    mv "_site/posts/$POST" "_site/posts/$STRIPPED"
s3cmd put -r -m text/html _site/posts/ s3://

export JEKYLL_ENV="development"

All you have to do is chmod +x and then you can deploy your site with ./

I have a love/hate relationship with bash, but in this case it was the right tool for the job - grouping a bunch of CLI operations into a single command.