On this blog post I walk you through how to lightweight you web Heroku instance by moving all your assets (CSS, Javascipt and images) to a CDN (Content Delivery Network). We will be using Amazon S3 web services for the storage and Amazon CLoudFront for the CDN.
Octopress
{% comment %}
What is Octopress
{% endcomment %}
Octopress is a framework designed by [Brandon Mathis] for Jekyll, the blog aware static site generator powering Github Pages. To start blogging with Jekyll, you have to write your own HTML templates, CSS, Javascripts and set up your configuration. But with Octopress All of that is already taken care of. Simply clone or fork Octopress, install dependencies and the theme, and you’re set.
Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through a converter (like Markdown) and our Liquid renderer, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server. Jekyll also happens to be the engine behind GitHub Pages, which means you can use Jekyll to host your project’s page, blog, or website from GitHub’s servers for free.
Why use Octopress ?
Octopress make your blogging experience easier (with some limit), Octopress provide all the organization layer like themes, layouts, generators and plugins and taking advantage of what Jekyll provide. But Octopress/Jekyll is not for everyone unless your are the kind of person that like to get your hand dirty.
Octopress: a blogging framework for hackers
– By Octopress
If you don’t like command line amd coding stuff: «go your way» otherwise keep reading.
Heroku
{% comment %}
What is Heroku
{% endcomment %}
Heroku is a PaaS (Platform as a Service) provider, It let you focus on your app and take care of the deployment and configuration stuff for you. There are a lot to talk about Heroku and I don’t like reinvent the wheel, so go ahead to their site for more information
{% comment %}
Why use Heroku?
Well, good question, its a personal choice I am Developer/IT guy and I love control. Heroku provide me all the tools I need to do that. {% endcomment %}
Amazon AWS
{% comment %}
What is Amazon AWS?
{% endcomment %}
Amozon is an IaaS (Infrastructure as a Service) provider, Amazon provide much more than Heroku, as Heroku is mostly an application oriented platform, Amazon is a broad and deep core infrastructure services (Compute, Storage & Content Delivery, Database, Network…).
{% comment %}
Why use Amazon AWS?
Well its the first that come to my mind and the free plan offer more than you need for a blog. {% endcomment %}
Step 1: Amazon AWS
Follow this guide. The documentation is pretty well done, you will go through it wihout any problem and if you are stuck at some place feel free to contact via the comment section.
Step 2: Get API keys
Login to your Amazon AWS account and go to thw shell Management:
{% link_img center /images/aws-image-01.png %}
Go to Identity & Access Management shell:
{% link_img center /images/aws-image-02.png %}
This screen show up
{% link_img center /images/aws-image-03.png %}
- On the left side bar select Users
- Click Create New Users
{% link_img center /images/aws-image-04.png %}
- Enter a new username in the field whatever you what (until it make sense)
- Click Create
Then on the next page
{% link_img center /images/aws-image-05.png %}
- Click Show user security credentials and copy them in a secure place
- Click Download credentials (Save it in a secure place)
Click on the user that you just created to edit it
{% link_img center /images/aws-image-06.png %}
scroll to the bottom of the page until the Permissions section
{% link_img center /images/aws-image-07.png %}
Click Attach Policy
{% link_img center /images/aws-image-08.png %}
- Search for s3
- Click the checkbox next to AmazonS3FullAccess
- Click Attach Policy
Step 3: Add some gem dependencies
|
|
then run:
|
|
Step 4: Set up the SDK
Create a credentials config file:
- ~/.aws/credentials (Linux/Mac)
- %USERPROFILE%.aws\credentials (Windows)
|
|
Step 5: Create some Rake tasks
Add these line after the existing require statement in your RakeFile
|
|
Declare this global variable after server_port
in your Rakefile
|
|
Add these task at the end of your RakeFile
|
|
Step 6: Use your CDN
Now your are all setup you need to modify some layout file:
- source/_includes/head.html
- source/_includes/scripts.html
replace
|
|
by
|
|
If you use the img
liquid tag plugin to reference images in your post, instead of modify each post you can modify the plugin to auto detect the url to use.
|
|
then add this to your _config.yml
|
|
YOUR_CDN_URL:
- Can be the Amazon S3 url: http://
bucket
.s3.amazonaws.com or http://bucket
.s3-aws-region
.amazonaws.com - Can be the Amazon CloudFront url: http://
generated_domain_name
.cloudfront.net - Can be a custom domain name url: http://cdn.yourblogdomain.tld (need some DNS and CloudFront settings)
Step 7: Test the new URL
Open your browser and the dev tools, hit your blog and you should see this for example for the screen.css
{% link_img center /images/aws-image-09.png %}
That’s it ! Now you have a supercharge blog and a lightweight Heroku web instance.