morning_glory 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ h1. Morning Glory
2
+
3
+ Morning Glory is comprised of a rake task and helper methods that manages the deployment of static assets into an Amazon CloudFront CDN's S3 Bucket, improving the performance of static assets on your Rails web applications.
4
+
5
+ _NOTE: You will require an Amazon Web Services (AWS) account in order to use this gem. Specially: S3 for storing the files you wish to distribute, and CloudFront for CDN distribution of those files._
6
+
7
+ This version of Morning Glory works with Rails 3.x and Ruby 1.9.x
8
+
9
+ h2. What does it do?
10
+
11
+ Morning Glory provides an easy way to deploy Ruby on Rails application assets to the Amazon CloudFront CDN.
12
+
13
+ It solves a number of common issues with S3/CloudFront. For instance, CloudFront won't automatically expire old assets stored on edge nodes when you redeploy new assets (the Cloudfront expiry time is 24 hours minimum).
14
+ To fix this Morning Glory will automatically namespace asset releases for you, then update all references to those renamed assets within your stylesheets ensuring there are no broken asset links.
15
+
16
+ It also provides a helper method to rewrite all standard Rails asset helper generated URLs to your CloudFront CDN distributions, as well as handling switching between HTTP and HTTPS.
17
+
18
+ Morning Glory was also built with SASS (Syntactically Awesome Stylesheets) in mind. If you use Sass for your stylesheets they will automatically be built before deployment to the CDN. See http://sass-lang.com/ for more information on Sass.s
19
+
20
+ h2. What it doesn't do
21
+
22
+ Morning Glory cannot configure your CloudFront distributions for you automatically. You will manually have to login to your AWS Management Console account, "https://console.aws.amazon.com/cloudfront/home":https://console.aws.amazon.com/cloudfront/home, and set up a distribution pointing to an S3 Bucket.
23
+
24
+ h2. Installation
25
+
26
+ <pre>
27
+ gem 'morning_glory'
28
+ </pre>
29
+
30
+ h2. Usage
31
+
32
+ Morning Glory provides it's functionality via rake tasks. You'll need to specify the target rails environment configuration you want to deploy for by using the @RAILS_ENV={env}@ parameter (for example, @RAILS_ENV=production@).
33
+
34
+ <pre>
35
+ rake morning_glory:cloudfront:deploy RAILS_ENV={YOUR_TARGET_ENVIRONMENT}
36
+ </pre>
37
+
38
+ h2. Configuration
39
+
40
+ h3. The Morning Glory configuration file, @config/morning_glory.yml@
41
+
42
+ You can specify a configuration section for every rails environment (production, staging, testing, development). This section can have the following properties defined:
43
+
44
+ <pre>
45
+ ---
46
+ production:
47
+ enabled: true # Is MorningGlory enabled for this environment?
48
+ bucket: cdn.production.foo.com # The bucket to deploy your assets into
49
+ s3_logging_enabled: true # Log the deployment to S3
50
+ revision: "20100317134627" # The revision prefix. This timestamp automatically generateed on deployment
51
+ delete_prev_rev: true # Delete the previous asset release (save on S3 storage space)
52
+ </pre>
53
+
54
+ h3. The Amazon S3 authentication keys configuration file, @config/s3.yml@
55
+
56
+ This file provides the access credentials for your Amazon AWS S3 account.
57
+ You can configure keys for all your environments (production, staging, testing, development).
58
+
59
+ <pre>
60
+ ---
61
+ production:
62
+ access_key_id: YOUR_ACCESS_KEY
63
+ secret_access_key: YOUR_SECRET_ACCESS_KEY
64
+ </pre>
65
+
66
+ Note: If you are deploying your system to Heroku, you can configure your Amazon AWS S3 information with the environment variables S3_KEY and S3_SECRET instead of using a configuration file.
67
+
68
+ h3. Set up an asset_host
69
+
70
+ For each environment that you'd like to utilise the CloudFront CDN for you'll need to define the asset_host within the @config/environments/{ENVIRONMENT}.rb@ configuration file.
71
+
72
+ As of June 2010 AWS supports HTTPS requests on the CloudFront CDN, so you no longer have to worry about switching servers. (Yay!)
73
+
74
+ h4. Example config/environments/production.rb @asset_host@ snippet:
75
+
76
+ Here we're targeting a CNAME domain with HTTP support.
77
+
78
+ <pre>
79
+ ActionController::Base.asset_host = Proc.new { |source, request|
80
+ if request.ssl?
81
+ "#{request.protocol}#{request.host_with_port}"
82
+ else
83
+ "#{request.protocol}assets.example.com"
84
+ end
85
+ }
86
+ </pre>
87
+
88
+
89
+ h3. Why do we have to use a revision-number/namespace/timestamp?
90
+
91
+ Once an asset has been deployed to the Amazon Cloudfront edge servers it cannot be modified - the version exists until it expires (minimum of 24 hours).
92
+
93
+ To get around this we need to prefix the asset path with a revision of some sort - in MorningGlory's case we use a timestamp. That way you can deploy many times during a 24 hour period and always have your latest revision available on your web site.
94
+
95
+ h2. Dependencies
96
+
97
+ h3. AWS S3
98
+
99
+ Required for uploading the assets to the Amazon Web Services S3 buckets.
100
+ See "http://amazon.rubyforge.org/":http://amazon.rubyforge.org/ for more documentation on installation.
101
+
102
+ h2. About the name
103
+
104
+ Perhaps not what you'd expect; a "Morning Glory":http://en.wikipedia.org/wiki/Morning_Glory_cloud is a rare cloud formation observed by glider pilots in Australia (see my side project, "YourFlightLog.com for flight-logging software for paraglider and hang-glider pilots":http://www.yourflightlog.com, from which the Morning Glory plugin was originally extracted).
105
+
106
+ Copyright (c) 2010 "@AdamBurmister":http://twitter.com/adamburmister/, released under the MIT license
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the morning_glory plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the morning_glory plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'Morning Glory'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'morning_glory'
2
+
3
+ # Setup the prefix
4
+ require 'asset_tag_helper' if MORNING_GLORY_CONFIG[Rails.env]['enabled'] == true
@@ -0,0 +1,48 @@
1
+ # Installation instructions
2
+ puts '=' * 80
3
+ puts <<EOF
4
+
5
+ MORNING GLORY CONFIG
6
+
7
+ See the github wiki for more detailed configuration information at:
8
+ http://wiki.github.com/adamburmister/morning_glory/
9
+
10
+ = Morning Glory =
11
+ You will need to manually create & configure your config/morning_glory.yml file.
12
+ Sample config/morning_glory.yml:
13
+
14
+ ---
15
+ production:
16
+ delete_prev_rev: true
17
+ bucket: cdn.production.yoursite.com
18
+ s3_logging_enabled: true
19
+ enabled: true
20
+ asset_directories:
21
+ - images
22
+ - javascripts
23
+ - stylesheets
24
+ revision: "20100316165112"
25
+ staging:
26
+ bucket: cdn.staging.yoursite.com
27
+ enabled: true
28
+ testing:
29
+ enabled: false
30
+ development:
31
+ enabled: false
32
+
33
+
34
+ = Amazon AWS =
35
+ You will need to manually create & configure your config/s3.yml file.
36
+ This file contains your access credentials for accessing the Amazon S3 service.
37
+ Sample config/s3.yml:
38
+
39
+ ---
40
+ production:
41
+ access_key_id: YOUR_ACCESS_KEY
42
+ secret_access_key: YOUR_SECRET_ACCESS_KEY
43
+ staging:
44
+ access_key_id: YOUR_ACCESS_KEY
45
+ secret_access_key: YOUR_SECRET_ACCESS_KEY
46
+
47
+ EOF
48
+ puts '=' * 80
@@ -0,0 +1,27 @@
1
+ require 'action_view/helpers/asset_tag_helper'
2
+
3
+ module ActionView::Helpers::AssetTagHelper
4
+
5
+ def rewrite_asset_path(source, path = nil)
6
+ if path && path.respond_to?(:call)
7
+ return path.call(source)
8
+ elsif path && path.is_a?(String)
9
+ return path % [source]
10
+ end
11
+
12
+ asset_id = rails_asset_id(source)
13
+ if asset_id.blank?
14
+ source
15
+ else
16
+ # AB: As of June AWS Cloudfront supports HTTPS requests. This alternative code path should now be redundant.
17
+ # # If the request isn't SSL, or if the request is SSL and the SSL host is set
18
+ # if !request.ssl? || (request.ssl? && !AssetHostingWithMinimumSsl::asset_ssl_host.empty?)
19
+ # File.join('/', ENV['RAILS_ASSET_ID'], source)
20
+ # else
21
+ # source + "?#{asset_id}"
22
+ # end
23
+ File.join('/', ENV['RAILS_ASSET_ID'], source)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ # Prefix files with a revision to bust the cloudfront non-expiring cache. For instance, /REV_1234/myfile.png
2
+ CLOUDFRONT_REVISION_PREFIX = 'REV_'
3
+
4
+ module MorningGlory
5
+ # Nothing
6
+ end
7
+
8
+ begin
9
+ MORNING_GLORY_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/morning_glory.yml") if !defined? MORNING_GLORY_CONFIG
10
+ rescue
11
+ raise "Error loading MorningGlory configuration files. Please check config/morning_glory.yml is configured correctly."
12
+ end
13
+
14
+ begin
15
+ if (!ENV['S3_KEY'] && !ENV['S3_SECRET'])
16
+ S3_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[Rails.env] if !defined? S3_CONFIG
17
+ end
18
+
19
+ rescue
20
+ raise "Error loading MorningGlory configuration files. Please check config/s3.yml is configured correctly."
21
+ end
22
+
23
+ if defined? MORNING_GLORY_CONFIG
24
+ if MORNING_GLORY_CONFIG[Rails.env]['enabled'] == true
25
+ ENV['RAILS_ASSET_ID'] = CLOUDFRONT_REVISION_PREFIX + MORNING_GLORY_CONFIG[Rails.env]['revision'].to_s
26
+ end
27
+ end
@@ -0,0 +1,188 @@
1
+ require File.dirname(__FILE__) + "/../morning_glory"
2
+
3
+ namespace :morning_glory do
4
+ namespace :cloudfront do
5
+
6
+ @@prev_cdn_revision = nil
7
+ @@scm_commit_required = false
8
+
9
+ begin
10
+ MORNING_GLORY_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/morning_glory.yml") if !defined? MORNING_GLORY_CONFIG
11
+ rescue
12
+ end
13
+
14
+ def check_config
15
+ if !defined? MORNING_GLORY_CONFIG[Rails.env] || MORNING_GLORY_CONFIG[Rails.env]['enabled'] != true
16
+ raise "Deployment appears to be disabled for this environment (#{Rails.env}) within config/morning_glory.yml. Specify an alternative environment with RAILS_ENV={environment name}."
17
+ end
18
+ if (!ENV['S3_KEY'] && !ENV['S3_SECRET'])
19
+ if !defined? S3_CONFIG[Rails.env]
20
+ raise "You seem to be lacking your Amazon S3 configuration file, config/s3.yml"
21
+ end
22
+ end
23
+ end
24
+
25
+ def get_revision
26
+ rev = nil
27
+
28
+ # SVN
29
+ begin
30
+ svn_rev = `svnversion .`.chomp.gsub(':','_')
31
+ puts svn_rev
32
+ if svn_rev != 'exported' && svn_rev != '' && svn_rev != nil
33
+ rev = Digest::MD5.hexdigest( svn_rev ).to_s
34
+ puts '* Using SVN revision'
35
+ end
36
+ rescue
37
+ # Ignore
38
+ end
39
+ # GIT
40
+ begin
41
+ git_rev = `git show --pretty=format:"%H|%ci" --quiet`.split('|')[0]
42
+ if !git_rev.nil?
43
+ rev = git_rev.to_s
44
+ puts '* Using Git revision'
45
+ end
46
+ rescue
47
+ # Ignore
48
+ end
49
+
50
+ if rev.nil?
51
+ rev = Time.new.strftime("%Y%m%d%H%M%S")
52
+ puts '* Using timestamp revision'
53
+ @@scm_commit_required = true
54
+ end
55
+
56
+ return rev
57
+ end
58
+
59
+ def update_revision
60
+ prev = MORNING_GLORY_CONFIG[Rails.env]['revision'].to_s
61
+
62
+ rev = get_revision
63
+
64
+ MORNING_GLORY_CONFIG[Rails.env]['revision'] = rev
65
+ ENV['RAILS_ASSET_ID'] = CLOUDFRONT_REVISION_PREFIX + rev
66
+
67
+ # Store the previous revision so we can delete the bucket from S3 later after deploy
68
+ @@prev_cdn_revision = CLOUDFRONT_REVISION_PREFIX + prev
69
+
70
+ File.open("#{RAILS_ROOT}/config/morning_glory.yml", 'w') { |f| YAML.dump(MORNING_GLORY_CONFIG, f) }
71
+
72
+ puts "* CDN revision updated for '#{Rails.env}' environment to #{ENV['RAILS_ASSET_ID']}"
73
+ end
74
+
75
+ def compile_sass_if_available
76
+ if defined? Sass
77
+ puts "* Compiling Sass stylesheets"
78
+ Sass::Plugin.update_stylesheets
79
+ end
80
+ end
81
+
82
+ desc "Bump the revision, compile any Sass stylesheets, and deploy assets to S3 and Cloudfront"
83
+ task :deploy => [:environment] do |t, args|
84
+ require 'aws/s3'
85
+ require 'fileutils'
86
+
87
+ puts 'MorningGlory: Starting deployment to the Cloudfront CDN...'
88
+
89
+ check_config
90
+
91
+ update_revision
92
+
93
+ compile_sass_if_available
94
+
95
+ # Constants
96
+ SYNC_DIRECTORY = File.join(Rails.root, 'public')
97
+ TEMP_DIRECTORY = File.join(Rails.root, 'tmp', 'morning_glory', 'cloudfront', Rails.env, ENV['RAILS_ASSET_ID']);
98
+ # Configuration constants
99
+ BUCKET = MORNING_GLORY_CONFIG[Rails.env]['bucket'] || Rails.env
100
+ DIRECTORIES = MORNING_GLORY_CONFIG[Rails.env]['asset_directories'] || %w(images javascripts stylesheets)
101
+ CONTENT_TYPES = MORNING_GLORY_CONFIG[Rails.env]['content_types'] || {
102
+ :jpg => 'image/jpeg',
103
+ :png => 'image/png',
104
+ :gif => 'image/gif',
105
+ :css => 'text/css',
106
+ :js => 'text/javascript'
107
+ }
108
+ S3_LOGGING_ENABLED = MORNING_GLORY_CONFIG[Rails.env]['s3_logging_enabled'] || false
109
+ DELETE_PREV_REVISION = MORNING_GLORY_CONFIG[Rails.env]['delete_prev_rev'] || false
110
+ REGEX_ROOT_RELATIVE_CSS_URL = /url\((\'|\")?(\/+.*(#{CONTENT_TYPES.keys.map { |k| '\.' + k.to_s }.join('|')}))\1?\)/
111
+
112
+ # Copy all the assets into the temp directory for processing
113
+ FileUtils.makedirs TEMP_DIRECTORY if !FileTest::directory?(TEMP_DIRECTORY)
114
+ puts "* Copying files to working directory for cache-busting-renaming"
115
+ DIRECTORIES.each do |directory|
116
+ Dir[File.join(SYNC_DIRECTORY, directory, '**', "*.{#{CONTENT_TYPES.keys.join(',')}}")].each do |file|
117
+ file_path = file.gsub(/.*public\//, "")
118
+ temp_file_path = File.join(TEMP_DIRECTORY, file_path)
119
+
120
+ FileUtils.makedirs(File.dirname(temp_file_path)) if !FileTest::directory?(File.dirname(temp_file_path))
121
+
122
+ puts " ** Copied to #{temp_file_path}"
123
+ FileUtils.copy file, temp_file_path
124
+ end
125
+ end
126
+
127
+ puts "* Replacing image references within CSS files"
128
+ DIRECTORIES.each do |directory|
129
+ Dir[File.join(TEMP_DIRECTORY, directory, '**', "*.{css}")].each do |file|
130
+ puts " ** Renaming image references within #{file}"
131
+ buffer = File.new(file,'r').read.gsub(REGEX_ROOT_RELATIVE_CSS_URL) { |m| m.insert m.index('(') + ($1 ? 2 : 1), '/'+ENV['RAILS_ASSET_ID'] }
132
+ File.open(file,'w') {|fw| fw.write(buffer)}
133
+ end
134
+ end
135
+
136
+ # TODO: Update references within JS files
137
+
138
+ AWS::S3::Base.establish_connection!(
139
+ :access_key_id => S3_CONFIG['access_key_id'] || ENV['S3_KEY'],
140
+ :secret_access_key => S3_CONFIG['secret_access_key'] || ENV['S3_SECRET']
141
+ )
142
+
143
+ begin
144
+ puts "* Attempting to create S3 Bucket '#{BUCKET}'"
145
+ AWS::S3::Bucket.create(BUCKET)
146
+
147
+ AWS::S3::Bucket.enable_logging_for(BUCKET) if S3_LOGGING_ENABLED
148
+
149
+ puts "* Uploading files to S3 Bucket '#{BUCKET}'"
150
+ DIRECTORIES.each do |directory|
151
+ Dir[File.join(TEMP_DIRECTORY, directory, '**', "*.{#{CONTENT_TYPES.keys.join(',')}}")].each do |file|
152
+ file_path = file.gsub(/.*#{TEMP_DIRECTORY}\//, "")
153
+ file_path = File.join(ENV['RAILS_ASSET_ID'], file_path)
154
+ file_ext = file.split(/\./)[-1].to_sym
155
+
156
+ puts " ** Uploading #{BUCKET}/#{file_path}"
157
+ AWS::S3::S3Object.store(file_path, open(file), BUCKET,
158
+ :access => :public_read,
159
+ :content_type => CONTENT_TYPES[file_ext])
160
+ end
161
+ end
162
+
163
+ # If the configured to delete the prev revision, and the prev revision value was in the YAML (not the blank concat of CLOUDFRONT_REVISION_PREFIX + revision number)
164
+ if DELETE_PREV_REVISION && @@prev_cdn_revision != CLOUDFRONT_REVISION_PREFIX
165
+ # TODO: Figure out how to delete from the S3 bucket properly
166
+ puts "* Deleting previous CDN revision #{BUCKET}/#{@@prev_cdn_revision}"
167
+ AWS::S3::Bucket.find(BUCKET).objects(:prefix => @@prev_cdn_revision).each do |object|
168
+ puts " ** Deleting #{BUCKET}/#{object.key}"
169
+ object.delete
170
+ end
171
+ end
172
+ rescue
173
+ raise
174
+ ensure
175
+ puts "* Deleting temp cache files in #{TEMP_DIRECTORY}"
176
+ FileUtils.rm_r TEMP_DIRECTORY
177
+ end
178
+
179
+ puts "MorningGlory: DONE! Your assets have been deployed to the Cloudfront CDN."
180
+
181
+ if @@scm_commit_required == true
182
+ puts '='*80
183
+ puts "NB: You will need to commit the /config/morning_glory.yml file and update it on your servers."
184
+ puts '='*80
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'morning_glory'
3
+ s.version = '0.0.1'
4
+ s.date = '2011-07-21'
5
+ s.summary = "Morning Glory is comprised of a rake task and helper methods that manages the deployment of static assets into an Amazon CloudFront CDN’s S3 Bucket, improving the performance of static assets on your Rails web applications."
6
+ s.description = File.read(File.join(File.dirname(__FILE__), 'README.textile'))
7
+ s.platform = Gem::Platform::RUBY
8
+ s.required_ruby_version = '>=1.9'
9
+ s.authors = ["Adam Burmister", "Todd Sedano"]
10
+ s.email = 'professor@gmail.com'
11
+ s.files = Dir['**/**']
12
+ s.homepage = 'https://github.com/professor/morning_glory'
13
+ s.license = 'MIT'
14
+ s.add_development_dependency 'aws-s3'
15
+ s.add_runtime_dependency 'aws-s3'
16
+ # s.has_rdoc = false
17
+ # s.test_files = Dir["test/test*.rb"]
18
+ # s.executables = [ 'anagram' ]
19
+
20
+ end
@@ -0,0 +1,4 @@
1
+ require 'morning_glory'
2
+
3
+ # Setup the prefix
4
+ require 'asset_tag_helper' if MORNING_GLORY_CONFIG[Rails.env]['enabled'] == true
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ RAILS_ASSET_ID = 'REV_TEST'
4
+ CONTENT_TYPES = {
5
+ :jpg => 'image/jpeg',
6
+ :png => 'image/png',
7
+ :gif => 'image/gif',
8
+ :css => 'text/css',
9
+ :js => 'text/javascript'
10
+ }
11
+ REGEX_ROOT_RELATIVE_CSS_URL = /url\((\'|\")?(\/+.*(#{CONTENT_TYPES.keys.map { |k| '\.' + k.to_s }.join('|')}))\1?\).*/
12
+ REPLACEMENT = "url(\1#{RAILS_ASSET_ID}\2\1)"
13
+
14
+ class MorningGloryTest < ActiveSupport::TestCase
15
+
16
+ test "CSS URL replacement" do
17
+ assert_equals "background: url(/images/test.png)".gsub(REGEX_ROOT_RELATIVE_CSS_URL, REPLACEMENT), ""
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: morning_glory
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Adam Burmister
14
+ - Todd Sedano
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-07-21 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: aws-s3
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: aws-s3
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: |-
51
+ h1. Morning Glory
52
+
53
+ Morning Glory is comprised of a rake task and helper methods that manages the deployment of static assets into an Amazon CloudFront CDN's S3 Bucket, improving the performance of static assets on your Rails web applications.
54
+
55
+ _NOTE: You will require an Amazon Web Services (AWS) account in order to use this gem. Specially: S3 for storing the files you wish to distribute, and CloudFront for CDN distribution of those files._
56
+
57
+ This version of Morning Glory works with Rails 3.x and Ruby 1.9.x
58
+
59
+ h2. What does it do?
60
+
61
+ Morning Glory provides an easy way to deploy Ruby on Rails application assets to the Amazon CloudFront CDN.
62
+
63
+ It solves a number of common issues with S3/CloudFront. For instance, CloudFront won't automatically expire old assets stored on edge nodes when you redeploy new assets (the Cloudfront expiry time is 24 hours minimum).
64
+ To fix this Morning Glory will automatically namespace asset releases for you, then update all references to those renamed assets within your stylesheets ensuring there are no broken asset links.
65
+
66
+ It also provides a helper method to rewrite all standard Rails asset helper generated URLs to your CloudFront CDN distributions, as well as handling switching between HTTP and HTTPS.
67
+
68
+ Morning Glory was also built with SASS (Syntactically Awesome Stylesheets) in mind. If you use Sass for your stylesheets they will automatically be built before deployment to the CDN. See http://sass-lang.com/ for more information on Sass.s
69
+
70
+ h2. What it doesn't do
71
+
72
+ Morning Glory cannot configure your CloudFront distributions for you automatically. You will manually have to login to your AWS Management Console account, "https://console.aws.amazon.com/cloudfront/home":https://console.aws.amazon.com/cloudfront/home, and set up a distribution pointing to an S3 Bucket.
73
+
74
+ h2. Installation
75
+
76
+ <pre>
77
+ gem 'morning_glory'
78
+ </pre>
79
+
80
+ h2. Usage
81
+
82
+ Morning Glory provides it's functionality via rake tasks. You'll need to specify the target rails environment configuration you want to deploy for by using the @RAILS_ENV={env}@ parameter (for example, @RAILS_ENV=production@).
83
+
84
+ <pre>
85
+ rake morning_glory:cloudfront:deploy RAILS_ENV={YOUR_TARGET_ENVIRONMENT}
86
+ </pre>
87
+
88
+ h2. Configuration
89
+
90
+ h3. The Morning Glory configuration file, @config/morning_glory.yml@
91
+
92
+ You can specify a configuration section for every rails environment (production, staging, testing, development). This section can have the following properties defined:
93
+
94
+ <pre>
95
+ ---
96
+ production:
97
+ enabled: true # Is MorningGlory enabled for this environment?
98
+ bucket: cdn.production.foo.com # The bucket to deploy your assets into
99
+ s3_logging_enabled: true # Log the deployment to S3
100
+ revision: "20100317134627" # The revision prefix. This timestamp automatically generateed on deployment
101
+ delete_prev_rev: true # Delete the previous asset release (save on S3 storage space)
102
+ </pre>
103
+
104
+ h3. The Amazon S3 authentication keys configuration file, @config/s3.yml@
105
+
106
+ This file provides the access credentials for your Amazon AWS S3 account.
107
+ You can configure keys for all your environments (production, staging, testing, development).
108
+
109
+ <pre>
110
+ ---
111
+ production:
112
+ access_key_id: YOUR_ACCESS_KEY
113
+ secret_access_key: YOUR_SECRET_ACCESS_KEY
114
+ </pre>
115
+
116
+ Note: If you are deploying your system to Heroku, you can configure your Amazon AWS S3 information with the environment variables S3_KEY and S3_SECRET instead of using a configuration file.
117
+
118
+ h3. Set up an asset_host
119
+
120
+ For each environment that you'd like to utilise the CloudFront CDN for you'll need to define the asset_host within the @config/environments/{ENVIRONMENT}.rb@ configuration file.
121
+
122
+ As of June 2010 AWS supports HTTPS requests on the CloudFront CDN, so you no longer have to worry about switching servers. (Yay!)
123
+
124
+ h4. Example config/environments/production.rb @asset_host@ snippet:
125
+
126
+ Here we're targeting a CNAME domain with HTTP support.
127
+
128
+ <pre>
129
+ ActionController::Base.asset_host = Proc.new { |source, request|
130
+ if request.ssl?
131
+ "#{request.protocol}#{request.host_with_port}"
132
+ else
133
+ "#{request.protocol}assets.example.com"
134
+ end
135
+ }
136
+ </pre>
137
+
138
+
139
+ h3. Why do we have to use a revision-number/namespace/timestamp?
140
+
141
+ Once an asset has been deployed to the Amazon Cloudfront edge servers it cannot be modified - the version exists until it expires (minimum of 24 hours).
142
+
143
+ To get around this we need to prefix the asset path with a revision of some sort - in MorningGlory's case we use a timestamp. That way you can deploy many times during a 24 hour period and always have your latest revision available on your web site.
144
+
145
+ h2. Dependencies
146
+
147
+ h3. AWS S3
148
+
149
+ Required for uploading the assets to the Amazon Web Services S3 buckets.
150
+ See "http://amazon.rubyforge.org/":http://amazon.rubyforge.org/ for more documentation on installation.
151
+
152
+ h2. About the name
153
+
154
+ Perhaps not what you'd expect; a "Morning Glory":http://en.wikipedia.org/wiki/Morning_Glory_cloud is a rare cloud formation observed by glider pilots in Australia (see my side project, "YourFlightLog.com for flight-logging software for paraglider and hang-glider pilots":http://www.yourflightlog.com, from which the Morning Glory plugin was originally extracted).
155
+
156
+ Copyright (c) 2010 "@AdamBurmister":http://twitter.com/adamburmister/, released under the MIT license
157
+ email: professor@gmail.com
158
+ executables: []
159
+
160
+ extensions: []
161
+
162
+ extra_rdoc_files: []
163
+
164
+ files:
165
+ - init.rb
166
+ - install.rb
167
+ - lib/asset_tag_helper.rb
168
+ - lib/morning_glory.rb
169
+ - lib/tasks/morning_glory.rake
170
+ - MIT-LICENSE
171
+ - morning_glory.gemspec
172
+ - rails/init.rb
173
+ - Rakefile
174
+ - README.textile
175
+ - test/morning_glory_test.rb
176
+ - test/test_helper.rb
177
+ - uninstall.rb
178
+ has_rdoc: true
179
+ homepage: https://github.com/professor/morning_glory
180
+ licenses:
181
+ - MIT
182
+ post_install_message:
183
+ rdoc_options: []
184
+
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ hash: 29
193
+ segments:
194
+ - 1
195
+ - 9
196
+ version: "1.9"
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ none: false
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ hash: 3
203
+ segments:
204
+ - 0
205
+ version: "0"
206
+ requirements: []
207
+
208
+ rubyforge_project:
209
+ rubygems_version: 1.3.7
210
+ signing_key:
211
+ specification_version: 3
212
+ summary: "Morning Glory is comprised of a rake task and helper methods that manages the deployment of static assets into an Amazon CloudFront CDN\xE2\x80\x99s S3 Bucket, improving the performance of static assets on your Rails web applications."
213
+ test_files: []
214
+