• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 14 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extensions so you can use jammit with s3/cloudfront for your Rails app

Jammit S3

Introduction

Jammit S3 is a jammit wrapper that provides appropriate hooks so you can easily deploy your assets to s3/cloudfront

It's especially great for Heroku user who use generated assets such as coffee-script and sass. jammit-s3 includes a script you can use as a hook to recompile and upload all your assets.

Installation

To install jammit-s3, just use:

gem install jammit-s3

If you are using Rails3, add it to your project's Gemfile:

gem 'jammit-s3'

Jammit S3 already has a gem dependency for jammit, so I'd recommend removing any existing gem 'jammit' references from your Gemfile.

Configuration

Within your config/assets.yml, just add a toplevel key called s3_bucket that contains the bucketname you want to use. If jammit-s3 doesn't find the bucket, it will try to create it. Bucketnames need to be globally unique. Learn more about bucketnames here

s3_bucket: my-awesome-jammit-bucket

Deployment

To deploy your files to s3, just the jammit-s3 command at your project's root.

jammit-s3

If using it in the context of your Rails3 app, I'd recommend using bundle exec

bundle exec jammit-s3

Saving Authentication Info

Set your authenticaton information within config/assets.yml

s3_access_key_id: 03HDMNF59CWZ2J24T702
s3_secret_access_key: 1TzRlDmuH8DoOlJ2tlwW8qx+i+Pfe0jzIouWI2BL

Replace these with your own access keys, found here.

As you probably don't want to check this data into source control, I'd recommend you just set it to an environment variable on your local box, and use ERB

s3_access_key_id: <%= ENV['ACCESS_KEY_ID'] %>
s3_secret_access_key: <%= ENV['SECRET_ACCESS_KEY'] %>

You can then set these env variables in your .bash_profile

Folders to upload

By default, jammit-s3 will upload your configured asset directly, along with public/images. However you can customize this using the s3_upload_files setting, which should be a list of file globs.

# adds image uploads
s3_upload_files:
  - public/css/images/**

Setting permissions on uploaded s3 objects

By default, jammit-s3 uses the permission setting found on the s3 bucket. However, you can override this with the config:

s3_permission: public_read

Valid permission options are:

private: Owner gets FULL_CONTROL. No one else has any access rights. This is the default.

public_read: Owner gets FULL_CONTROL and the anonymous principal is granted READ access. If this policy is used on an object, it can be read from a browser with no authentication.

public_read_write: Owner gets FULL_CONTROL, the anonymous principal is granted READ and WRITE access. This is a useful policy to apply to a bucket, if you intend for any anonymous user to PUT objects into the bucket.

authenticated_read: - Owner gets FULL_CONTROL, and any principal authenticated as a registered Amazon S3 user is granted READ access.

Using CloudFront

For this to work you need to make sure you have the CloudFront enabled via you Amazon acccount page. Go here: http://aws.amazon.com/cloudfront/ and click "Sign Up"

To use CloudFront, simply add the following settings to config/assets.yml:

use_cloudfront: on
cloudfront_dist_id: XXXXXXXXXXXXXX
cloudfront_domain: xyzxyxyz.cloudfront.net

Please note that cloudfront_dist_id is not the same as the CloudFront domain name. Inside CloudFront management console select the distribution, and you will see Distribution ID and Domain Name values.

This will use the CloudFront domain name for your assets instead of serving them from the (slow) S3 bucket.

Known issues with CloudFront invalidation

  1. It may reportedly take up to 15 minutes to invalidate all the CloudFront caches around the globe (and Amazon charges for more than a certain number of invalidations per month).

  2. It's non-atomic from the perspective of the end-user: They may get an older version of the site with a newer version of the JavaScript and CSS, or vice versa.

  3. It doesn't play nicely with aggressive HTTP caching. For example, once I serve a script or a stylesheet, I would like it to be cached indefinitely with no more round trips to see whether it is valid.

Given these constraints, there's still an important need for some kind of content-based hashing. Done right, this assures that all files can be cached indefinitely, and the user will always get matched HTML/JS/CSS files. (This currently is in the works).

Bugs / Feature Requests

To suggest a feature or report a bug: http://github.com/railsjedi/jammit-s3/issues/

Jammit Home Page

Jammit S3 is a simple wrapper around Jammit. To view the original Jammit docs, use http://documentcloud.github.com/jammit/

More Repositories

1

heroku-rails

easy configuration / multi-environment setup with heroku with deployment hooks *NOTE* I no longer use Heroku. If anyone would like to take over this gem, just github msg me. Thanks!
Ruby
111
star
2

aarrr

this gem is no longer in active development. please msg me if you'd like to take it over
Ruby
61
star
3

guard-resque

guard plugin for auto restarting resque processes in dev mode when your code changes
Ruby
33
star
4

jammit-sinatra

Jammit Rack middleware for use with Sinatra/Padrino
Ruby
23
star
5

railsgen

super cool rails3 application generator
Ruby
23
star
6

vimconfig

my macvim configuration for the textmate convert
Vim Script
20
star
7

middleman-bourbon

easily integrates bourbon within middleman static site projects
Ruby
15
star
8

heroscale

gem that allows easy querying of your heroku app's queue depth
14
star
9

rails3-aloha-sample

sample app showing aloha editor integration with rails3 and mongoid
Ruby
12
star
10

know1thing

if i would have known just one thing....
Ruby
9
star
11

middleman-shower

middleman template for shower
JavaScript
8
star
12

seattlejs-coffeescript

CoffeeScript Presentation for SeattleJS (nov 11th, 2010)
Ruby
5
star
13

omniauth-appdotnet

App.net login strategy for OmniAuth. Built for Lizi.ai
Ruby
5
star
14

pitchr

track which pitches work for whom. sample app for my mongoseattle 2011 talk
JavaScript
5
star
15

bootstrap-rails

preferred rails template, with mongoid, stylus, guard, twitter bootstrap, and more....
Ruby
4
star
16

config

easy to use configuration gem that uses YML sources
Ruby
4
star
17

senchrino

a padrino app for sencha touch development with coffeescript/guard/compass
JavaScript
3
star
18

open-in-terminal-tmbundle

Textmate bundle to easily pop open terminal windows. CMD+SHIFT+O to open the current editing file in terminal. CMD+CTRL+O to open the current project in terminal
3
star
19

deployer

Deployer is gem that enhances Capistrano to simplify the deployment of Ruby on Rails applications.
Ruby
3
star
20

stopusinglinkedin

CSS
2
star
21

viewfu

handle view helpers for Rails3
Ruby
2
star
22

rails3-generators

haml and factory_girl generators
Ruby
2
star
23

openid_mongodb_store

MongoDB store for OpenID associations
Ruby
2
star
24

better_partials

a better way to call partials in rails3
Ruby
2
star
25

compass-rails31

adding back removed rails 3.1 branch of compass (my code needz it!)
Ruby
2
star
26

seconds-deck

seconds slideshow
JavaScript
1
star
27

portfolio

my portfolio site (webby powered)
JavaScript
1
star
28

cucumber_playground

messing around with cucumber
Ruby
1
star
29

thinkvitamin

working through code examples on thinkvitamin
1
star
30

remarkable-mongoid-tmbundle

Remarkable TextMate Bundle
1
star
31

ruby-stylus-nib

JavaScript
1
star
32

rspec2_playground

examples and exploration from "the rspec book"
Ruby
1
star
33

dm-active_model

Development has moved to http://github.com/datamapper/dm-active_model
Ruby
1
star
34

juiced

an idea...
1
star
35

mongoseattle2011

slides for mongoseattle talk
JavaScript
1
star
36

google-api-ruby-client

forked copy of https://code.google.com/p/google-api-ruby-client/ hacked to fit our needs, i don't recommend using this fork
Ruby
1
star