From 6cb0ac94609a11d047f8959511eaa311a9d602f7 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Fri, 18 Jan 2013 15:59:18 -0800 Subject: [PATCH 01/14] added rackspace support for CORS --- lib/asset_sync/config.rb | 7 ++++++- lib/asset_sync/storage.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 9258ffc2..54899ac4 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -15,6 +15,7 @@ class Invalid < StandardError; end attr_accessor :public_path attr_accessor :enabled + # FOG configuration attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace'] attr_accessor :fog_directory # e.g. 'the-bucket-name' @@ -24,7 +25,7 @@ class Invalid < StandardError; end attr_accessor :aws_access_key_id, :aws_secret_access_key # Rackspace - attr_accessor :rackspace_username, :rackspace_api_key, :rackspace_auth_url + attr_accessor :rackspace_username, :rackspace_api_key, :rackspace_auth_url, :rackspace_origin, :rackspace_allow_origin # Google Storage attr_accessor :google_storage_secret_access_key, :google_storage_access_key_id @@ -50,6 +51,8 @@ def initialize self.always_upload = [] self.ignored_files = [] self.enabled = true + self.allow_origin = "" + self.origin = "" load_yml! if defined?(Rails) && yml_exists? end @@ -122,6 +125,8 @@ def load_yml! self.rackspace_username = yml["rackspace_username"] self.rackspace_auth_url = yml["rackspace_auth_url"] if yml.has_key?("rackspace_auth_url") self.rackspace_api_key = yml["rackspace_api_key"] + self.rackspace_allow_origin = yml["allow_origin"] if yml.has_key?("allow_origin") + self.rackspace_origin = yml["origin"] if yml.has_key?("origin") self.google_storage_secret_access_key = yml["google_storage_secret_access_key"] self.google_storage_access_key_id = yml["google_storage_access_key_id"] self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files") diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index f9479e12..9b90d4ed 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -119,6 +119,18 @@ def upload_file(f) gzipped = "#{path}/#{f}.gz" ignore = false + if config.rackspace_allow_origin.present? + file.merge!({ + :access_control_allow_origin => config.rackspace_allow_origin + }) + end + + if config.rackspace_origin.present? + file.merge!({ + :origin => config.rackspace_origin + }) + end + if config.gzip? && File.extname(f) == ".gz" # Don't bother uploading gzipped assets if we are in gzip_compression mode # as we will overwrite file.css with file.css.gz if it exists. From 81b5a0a2815b159c2f43aaed5a57b5d4a8386ed2 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Fri, 18 Jan 2013 17:15:40 -0800 Subject: [PATCH 02/14] added CORS headers for rackspace --- lib/asset_sync/config.rb | 8 +-- .../rackspace_with_yml/config/asset_sync.yml | 2 + spec/integration/aws_integration_spec.rb | 6 +- .../integration/rackspace_integration_spec.rb | 63 +++++++++++++++++++ spec/unit/rackspace_spec.rb | 19 ++++++ 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 spec/integration/rackspace_integration_spec.rb diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 54899ac4..09cc10f2 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -51,8 +51,8 @@ def initialize self.always_upload = [] self.ignored_files = [] self.enabled = true - self.allow_origin = "" - self.origin = "" + self.rackspace_allow_origin = "" + self.rackspace_origin = "" load_yml! if defined?(Rails) && yml_exists? end @@ -125,8 +125,8 @@ def load_yml! self.rackspace_username = yml["rackspace_username"] self.rackspace_auth_url = yml["rackspace_auth_url"] if yml.has_key?("rackspace_auth_url") self.rackspace_api_key = yml["rackspace_api_key"] - self.rackspace_allow_origin = yml["allow_origin"] if yml.has_key?("allow_origin") - self.rackspace_origin = yml["origin"] if yml.has_key?("origin") + self.rackspace_allow_origin = yml["rackspace_allow_origin"] if yml.has_key?("rackspace_allow_origin") + self.rackspace_origin = yml["rackspace_origin"] if yml.has_key?("rackspace_origin") self.google_storage_secret_access_key = yml["google_storage_secret_access_key"] self.google_storage_access_key_id = yml["google_storage_access_key_id"] self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files") diff --git a/spec/fixtures/rackspace_with_yml/config/asset_sync.yml b/spec/fixtures/rackspace_with_yml/config/asset_sync.yml index d693fdf5..604b8260 100644 --- a/spec/fixtures/rackspace_with_yml/config/asset_sync.yml +++ b/spec/fixtures/rackspace_with_yml/config/asset_sync.yml @@ -2,6 +2,8 @@ defaults: &defaults fog_provider: "Rackspace" rackspace_username: "xxxx" rackspace_api_key: "zzzz" + rackspace_origin: "mysite.com" + rackspace_allow_origin: "*" region: "eu-west-1" development: diff --git a/spec/integration/aws_integration_spec.rb b/spec/integration/aws_integration_spec.rb index 2e48208b..a6c71870 100644 --- a/spec/integration/aws_integration_spec.rb +++ b/spec/integration/aws_integration_spec.rb @@ -31,7 +31,7 @@ def execute(command) end it "sync" do - execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile" + execute "rake FOG_PROVIDER=AWS ASSET_SYNC_PREFIX=#{@prefix} assets:precompile" bucket(@prefix).files.size.should == 5 app_js = bucket(@prefix).files.get("#{@prefix}/application.js") @@ -43,12 +43,12 @@ def execute(command) end it "sync with enabled=false" do - execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile" + execute "rake FOG_PROVIDER=AWS ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile" bucket(@prefix).files.size.should == 0 end it "sync with gzip_compression=true" do - execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile" + execute "rake FOG_PROVIDER=AWS ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile" bucket(@prefix).files.size.should == 3 app_js = bucket(@prefix).files.get("#{@prefix}/application.js") diff --git a/spec/integration/rackspace_integration_spec.rb b/spec/integration/rackspace_integration_spec.rb new file mode 100644 index 00000000..331bf53b --- /dev/null +++ b/spec/integration/rackspace_integration_spec.rb @@ -0,0 +1,63 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +def bucket(name) + options = { + :provider => 'rackspace', + :rackspace_username => ENV['RACKSPACE_USERNAME'], + :rackspace_api_key => ENV['RACKSPACE_API_KEY'] + } + + connection = Fog::Storage.new(options) + connection.directories.get(ENV['FOG_DIRECTORY'], :prefix => name) +end + +def execute(command) + app_path = File.expand_path("../../dummy_app", __FILE__) + Dir.chdir app_path + `#{command}` +end + +describe "AssetSync" do + + before(:each) do + @prefix = SecureRandom.hex(6) + end + + after(:each) do + @directory = bucket(@prefix) + @directory.files.each do |f| + f.destroy + end + end + + it "sync" do + execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile" + bucket(@prefix).files.size.should == 5 + + app_js = bucket(@prefix).files.get("#{@prefix}/application.js") + app_js.content_type.should == "text/javascript" + app_js.origin.should == 'mysite.com' + app_js.access_control_allow_origin.should == '' + + app_js_gz = bucket(@prefix).files.get("#{@prefix}/application.js.gz") + app_js_gz.content_type.should == "text/javascript" + app_js_gz.content_encoding.should == "gzip" + + app_js_gz.content_encoding.should == "gzip" + end + + it "sync with enabled=false" do + execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile" + bucket(@prefix).files.size.should == 0 + end + + it "sync with gzip_compression=true" do + execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile" + bucket(@prefix).files.size.should == 3 + + app_js = bucket(@prefix).files.get("#{@prefix}/application.js") + app_js.content_type.should == "text/javascript" + end + +end + diff --git a/spec/unit/rackspace_spec.rb b/spec/unit/rackspace_spec.rb index 3f7a6c60..489d423c 100644 --- a/spec/unit/rackspace_spec.rb +++ b/spec/unit/rackspace_spec.rb @@ -14,6 +14,8 @@ config.rackspace_username = 'aaaa' config.rackspace_api_key = 'bbbb' config.existing_remote_files = 'keep' + config.rackspace_origin = 'mysite.com' + config.rackspace_allow_origin = '*' end end @@ -54,6 +56,14 @@ AssetSync.config.rackspace_auth_url.should be_false end + it "should set origin rackspace_origin" do + AssetSync.config.rackspace_origin.should == "mysite.com" + end + + it "should set allow origin rackspace_allow_origin" do + AssetSync.config.rackspace_allow_origin.should == "*" + end + end describe 'using Rackspace from yml' do @@ -86,5 +96,14 @@ it "should configure existing_remote_files" do AssetSync.config.existing_remote_files.should == "keep" end + + it "should set origin rackspace_origin" do + AssetSync.config.rackspace_origin.should == "mysite.com" + end + + it "should set allow origin rackspace_allow_origin" do + AssetSync.config.rackspace_allow_origin.should == "*" + end + end end From 5d0df140ce06549b2abeb0cd6851127455dc3860 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Sat, 19 Jan 2013 17:43:35 -0800 Subject: [PATCH 03/14] fixed mime type definition --- lib/asset_sync/multi_mime.rb | 4 +--- lib/asset_sync/version.rb | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index d1d3cf09..5e1faab3 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -3,9 +3,7 @@ class MultiMime def self.lookup(ext) - if defined?(Mime::Type) - Mime::Type.lookup_by_extension(ext) - elsif defined?(Rack::Mime) + if defined?(Rack::Mime) ext_with_dot = ".#{ext}" Rack::Mime.mime_type(ext_with_dot) else diff --git a/lib/asset_sync/version.rb b/lib/asset_sync/version.rb index 4edeef8a..e8e63523 100644 --- a/lib/asset_sync/version.rb +++ b/lib/asset_sync/version.rb @@ -1,3 +1,3 @@ module AssetSync - VERSION = "0.5.4" + VERSION = "0.5.5" end From 62400e847a7b7c8cc9b51e70aa16a0204d1b9c68 Mon Sep 17 00:00:00 2001 From: fountainheadpro Date: Thu, 24 Jan 2013 14:08:14 -0800 Subject: [PATCH 04/14] Update README.md added rackspace CORS headers info. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ab87a69e..94c463bc 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,9 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION'] #### Rackspace (Optional) * **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: lon.auth.api.rackspacecloud.com +* **rackspace_allow_origin: "*" optional - enables rackspace CORS requests to your assets by setting Allow-Access-Control-Origin - to the value provided. +* **rackspace_origin: "mysite.com" optional - for sets the origin header for assets. + ## Amazon S3 Multiple Region Support From 4cd314a56931d2b207031f7e70935b60e49a01bd Mon Sep 17 00:00:00 2001 From: fountainheadpro Date: Thu, 24 Jan 2013 14:10:12 -0800 Subject: [PATCH 05/14] Update README.md markup fix. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 94c463bc..939b99b2 100644 --- a/README.md +++ b/README.md @@ -294,8 +294,8 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION'] #### Rackspace (Optional) * **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: lon.auth.api.rackspacecloud.com -* **rackspace_allow_origin: "*" optional - enables rackspace CORS requests to your assets by setting Allow-Access-Control-Origin - to the value provided. -* **rackspace_origin: "mysite.com" optional - for sets the origin header for assets. +* **rackspace_allow_origin**: "*" optional - enables rackspace CORS requests to your assets by setting Allow-Access-Control-Origin - to the value provided. +* **rackspace_origin**: "mysite.com" optional - for sets the origin header for assets. ## Amazon S3 Multiple Region Support From ca7562fcc5d29f860eea6ea1329f12cafffc6b27 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 19 Feb 2013 12:33:12 -0800 Subject: [PATCH 06/14] it will upload all the files. --- lib/asset_sync/storage.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 9b90d4ed..e747cb7d 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -172,9 +172,9 @@ def upload_file(f) def upload_files # get a fresh list of remote files - remote_files = ignore_existing_remote_files? ? [] : get_remote_files + #remote_files = ignore_existing_remote_files? ? [] : get_remote_files # fixes: https://github.com/rumblelabs/asset_sync/issues/19 - local_files_to_upload = local_files - ignored_files - remote_files + always_upload_files + local_files_to_upload = local_files - ignored_files # Upload new files local_files_to_upload.each do |f| From 357b56fc4f12b453e20eb060964af4364dc8997b Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 19 Feb 2013 14:06:26 -0800 Subject: [PATCH 07/14] multimime fix --- lib/asset_sync/multi_mime.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index 5e1faab3..0e001b1f 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -3,12 +3,12 @@ class MultiMime def self.lookup(ext) - if defined?(Rack::Mime) - ext_with_dot = ".#{ext}" - Rack::Mime.mime_type(ext_with_dot) - else - MIME::Types.type_for(ext).first - end + #if defined?(Rack::Mime) + # ext_with_dot = ".#{ext}" + # Rack::Mime.mime_type(ext_with_dot) + #else + MIME::Types.type_for(ext).first + #end end From 8ef9537334d84cde63976cc7c9339bc1a68c7d7d Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 19 Feb 2013 14:24:15 -0800 Subject: [PATCH 08/14] multimime fix --- lib/asset_sync/storage.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index e747cb7d..1315a5b8 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -167,7 +167,8 @@ def upload_file(f) log "Uploading: #{f}" end - file = bucket.files.create( file ) unless ignore + bucket.files.create( file ) unless ignore + file end def upload_files From bab67c07d04fdf7f6904a755ce3378040fee1c03 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 19 Feb 2013 15:27:13 -0800 Subject: [PATCH 09/14] multimime fix --- lib/asset_sync/multi_mime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index 0e001b1f..8567a2e2 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -7,7 +7,7 @@ def self.lookup(ext) # ext_with_dot = ".#{ext}" # Rack::Mime.mime_type(ext_with_dot) #else - MIME::Types.type_for(ext).first + "#{MIME::Types.type_for(ext).first}" #end end From cc0e0ae3b6cf69209468cabd47b3861cb4d30b83 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 19 Feb 2013 17:14:51 -0800 Subject: [PATCH 10/14] multimime fix --- lib/asset_sync/multi_mime.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index 8567a2e2..0d2f5e64 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -1,13 +1,17 @@ module AssetSync class MultiMime + types={ + "ttf"=> "font/truetype" + } + def self.lookup(ext) #if defined?(Rack::Mime) # ext_with_dot = ".#{ext}" # Rack::Mime.mime_type(ext_with_dot) #else - "#{MIME::Types.type_for(ext).first}" + types[ext] || "#{MIME::Types.type_for(ext).first}" #end end From 4831ec199ae3208656563ab59f2ea2439aa8d9cf Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 19 Feb 2013 17:54:20 -0800 Subject: [PATCH 11/14] multimime fix --- lib/asset_sync/multi_mime.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index 0d2f5e64..f08af1a1 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -2,7 +2,7 @@ module AssetSync class MultiMime types={ - "ttf"=> "font/truetype" + "ttf"=> "application/x-font-woff" } def self.lookup(ext) @@ -11,7 +11,7 @@ def self.lookup(ext) # ext_with_dot = ".#{ext}" # Rack::Mime.mime_type(ext_with_dot) #else - types[ext] || "#{MIME::Types.type_for(ext).first}" + "#{MIME::Types.type_for(ext).first}" #end end From c635bea8dfaefd8997cd28e3348c1882aa6d9efb Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Thu, 21 Feb 2013 17:21:13 -0800 Subject: [PATCH 12/14] error handling --- lib/asset_sync/storage.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 1315a5b8..376e848d 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -180,7 +180,11 @@ def upload_files # Upload new files local_files_to_upload.each do |f| next unless File.file? "#{path}/#{f}" # Only files. - upload_file f + begin + upload_file f + rescue + log "error - #{$!} - file: #{f}" + end end end From d441b19c29d34a4ae70c839c656727debc1d9848 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Tue, 30 Apr 2013 14:40:25 -0700 Subject: [PATCH 13/14] changed mime resolution to always use mime-types --- lib/asset_sync/multi_mime.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/asset_sync/multi_mime.rb b/lib/asset_sync/multi_mime.rb index f08af1a1..880f735b 100644 --- a/lib/asset_sync/multi_mime.rb +++ b/lib/asset_sync/multi_mime.rb @@ -1,19 +1,16 @@ +require 'mime/types' + module AssetSync class MultiMime - types={ - "ttf"=> "application/x-font-woff" - } - def self.lookup(ext) - + "#{MIME::Types.type_for(ext).first}" #if defined?(Rack::Mime) # ext_with_dot = ".#{ext}" # Rack::Mime.mime_type(ext_with_dot) #else - "#{MIME::Types.type_for(ext).first}" + # #end - end end From 4f994cf0d0e4944ffe747c3bb47fe558d0e9e705 Mon Sep 17 00:00:00 2001 From: Sergey Zelvenskiy Date: Mon, 20 May 2013 15:51:40 -0700 Subject: [PATCH 14/14] fix for warn_on_failure condition --- lib/asset_sync/storage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index ec081174..a8f95756 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -206,7 +206,7 @@ def upload_files upload_file f rescue Exception => ex log "error - #{$!} - file: #{f}" - railse ex unless config.warn_on_failure + raise ex unless config.warn_on_failure end end end