Skip to content

yong/publish2cloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

==What it is for==
You have a running rails application, but some of the content do not change often (company frontpage, marketing materials etc). And you are thinking about taking advantage of Amazon's cloudfront service for better speed and reliability.

Publish2Cloud is a ruby gem that help you to move the content to the cloud (Amazon's cloudfront cdn service). It does NOT encourge/force you to write static html like the old days, you will keep your database driven rails site running. But if the rendered content does not change often, this gem can pull the content from your site and push them to cloudfront, along with some DNS help, those content will be served faster and more reliably.

==What it does==
Assuming your site is running at 'www.company.com', and you enabled cloudfront on bucket 'company-cdn' and assigned a CNAME 'cdn.company.com'. And on 'www.company.com', there are some contents that rarely changes, for example:
http://www.company.com/contract

You can use publish2Cloud's rake task to fecth 'http://www.company.com/contract', and upload it to 'company-cdn' (invalidate the original one from the cloud if already exists), so that you can have the content at:
http://cdn.company.com/contract

==Install==
gem install publish2cloud

With Rails 3, add this line into Gemfile
group :development do
  gem 'publish2cloud'
end

==Usage==
You need a amazon aws account, and enable s3 and cloudfront service.

Create config/publish2cloud.rb in your rails projects, and make it look like this:
P2C_S3_ACCESS_KEY_ID=''
P2C_S3_SECRET_ACCESS_KEY=''
P2C_S3_BUCKET=''
#Optional
#P2C_MAX_AGE=86400
#This is not one in .cloudfront.net url
P2C_CF_DISTRIBUTION_ID=''
#This file a just a ruby program, feel free modify P2C_URLS with code
P2C_URLS=['', '']

Run it:
rake p2c:push

In the future, you will need to run 'rake p2c:push' each time when the cached content changes (new deployment, data being updated in database etc).

==Thanks and Credits==
I used some code of jmlacroix, and his original post is at:
http://jmlacroix.com/archives/cloudfront-hosting.html
http://jmlacroix.com/archives/cloudfront-publishing.html

I also used heroku_san's code as a reference to add rake task into a gem:
https://github.com/fastestforward/heroku_san

==License==
Copyright 2011 Intridea Inc ( http://intridea.com ), released under the MIT license.

About

publish content to amazon cloudfront

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages