asset_sync 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6da0a6735b574c2e13ef9bb97f00b35f6b28555e81a43aeaa2a4d74ca86cac44
4
- data.tar.gz: 11eafe2e4c2297e47a64736d4d6834140271d26c557dcddf2244eabd356cc2b3
3
+ metadata.gz: 0ca689aa3521a19cb98a52f5c4319cc1e69ef0091b5ba8a2076745ec536f4cc9
4
+ data.tar.gz: 2fb823e7bd97003a447521bc1640dd1a0ee934e4692bfc6c0c4f8d8aa46545e2
5
5
  SHA512:
6
- metadata.gz: 3fb08a40bb3769b7a966483b28c9c7b5b050ff6f2457f066f4c66bd3646f6da11fc99981b62924a884effa8b0662e314f1725b0e92fdfc6166536a42634f42ce
7
- data.tar.gz: 6743f47d2400bce60b26291c21743f0a99427ddb108b9d5f5492913d595f5b71dd2824bf48e51e1117a6e6be641afb3dce85e2265f9dd8cf537be30f75f2df5d
6
+ metadata.gz: a15f3c71c845ae310f8ea1ed20a38dcd652832d7952ace0db544c6269810701bb0217242696018a7eb0c5a4dd839e5cb018714c2a623106cd3662a1e4b95e02f
7
+ data.tar.gz: 7b9b929264f61d277248956a29132c969f1c8402bc4f0e606f3e273a7a6b835ea166b45b8f75c9264fce1f224dcd7e8ab7ae99a6f3396be56c7444fd7e266bef
data/CHANGELOG.md CHANGED
@@ -18,6 +18,25 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [2.4.0] - 2017-12-20
22
+
23
+ ### Added
24
+
25
+ - Add support for Azure Blob storage
26
+ (https://github.com/AssetSync/asset_sync/pull/363)
27
+ - Add option: `include_manifest`
28
+ (https://github.com/AssetSync/asset_sync/pull/365)
29
+
30
+ ### Changed
31
+
32
+ - Add public API method `get_asset_files_from_manifest` split from `get_local_files` for another gem
33
+ (https://github.com/AssetSync/asset_sync/pull/366)
34
+
35
+ ### Fixed
36
+
37
+ - Nothing
38
+
39
+
21
40
  ## [2.3.0] - 2017-12-05
22
41
 
23
42
  ### Added
@@ -842,7 +861,8 @@ Changes:
842
861
  * Merge branch 'sinatra'
843
862
 
844
863
 
845
- [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.3.0...HEAD
864
+ [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.4.0...HEAD
865
+ [2.4.0]: https://github.com/AssetSync/asset_sync/compare/v2.3.0...v2.4.0
846
866
  [2.3.0]: https://github.com/AssetSync/asset_sync/compare/v2.2.0...v2.3.0
847
867
  [2.2.0]: https://github.com/AssetSync/asset_sync/compare/v2.1.0...v2.2.0
848
868
  [2.1.0]: https://github.com/AssetSync/asset_sync/compare/v2.0.0...v2.1.0
data/README.md CHANGED
@@ -33,6 +33,14 @@ gem "asset_sync"
33
33
  gem "fog-aws"
34
34
  ```
35
35
 
36
+ Or, to use Azure Blob storage, configure as this.
37
+
38
+ ``` ruby
39
+ gem "asset_sync"
40
+ gem "fog-azure-rm"
41
+ ```
42
+
43
+
36
44
  ### Extended Installation (Faster sync with turbosprockets)
37
45
 
38
46
  It's possible to improve **asset:precompile** time if you are using Rails 3.2.x
@@ -64,6 +72,12 @@ Or, to use Google Storage Cloud, configure as this.
64
72
  config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.storage.googleapis.com"
65
73
  ```
66
74
 
75
+ Or, to use Azure Blob storage, configure as this.
76
+
77
+ ``` ruby
78
+ #config/environments/production.rb
79
+ config.action_controller.asset_host = "//#{ENV['AZURE_STORAGE_ACCOUNT_NAME']}.blob.core.windows.net/#{ENV['FOG_DIRECTORY']}"
80
+ ```
67
81
 
68
82
 
69
83
  On **HTTPS**: the exclusion of any protocol in the asset host declaration above will allow browsers to choose the transport mechanism on the fly. So if your application is available under both HTTP and HTTPS the assets will be served to match.
@@ -73,11 +87,20 @@ On **HTTPS**: the exclusion of any protocol in the asset host declaration above
73
87
  ``` ruby
74
88
  config.action_controller.asset_host = "//s3.amazonaws.com/#{ENV['FOG_DIRECTORY']}"
75
89
  ```
76
- Or
90
+
91
+ Or, to use Google Storage Cloud, configure as this.
77
92
 
78
93
  ``` ruby
79
94
  config.action_controller.asset_host = "//storage.googleapis.com/#{ENV['FOG_DIRECTORY']}"
80
95
  ```
96
+
97
+ Or, to use Azure Blob storage, configure as this.
98
+
99
+ ``` ruby
100
+ #config/environments/production.rb
101
+ config.action_controller.asset_host = "//#{ENV['AZURE_STORAGE_ACCOUNT_NAME']}.blob.core.windows.net/#{ENV['FOG_DIRECTORY']}"
102
+ ```
103
+
81
104
  On **non default S3 bucket region**: If your bucket is set to a region that is not the default US Standard (us-east-1) you must use the first style of url ``//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com`` or amazon will return a 301 permanently moved when assets are requested. Note the caveat above about bucket names and periods.
82
105
 
83
106
  If you wish to have your assets sync to a sub-folder of your bucket instead of into the root add the following to your ``production.rb`` file
@@ -167,6 +190,7 @@ Run the included Rake task to generate a starting point.
167
190
 
168
191
  rails g asset_sync:install --provider=Rackspace
169
192
  rails g asset_sync:install --provider=AWS
193
+ rails g asset_sync:install --provider=AzureRM
170
194
 
171
195
  The generator will create a Rails initializer at `config/initializers/asset_sync.rb`.
172
196
 
@@ -199,6 +223,9 @@ AssetSync.configure do |config|
199
223
  # upload instead of searching the assets directory.
200
224
  # config.manifest = true
201
225
  #
226
+ # Upload the manifest file also.
227
+ # config.include_manifest = false
228
+ #
202
229
  # Fail silently. Useful for environments such as Heroku
203
230
  # config.fail_silently = true
204
231
  #
@@ -220,6 +247,7 @@ Run the included Rake task to generate a starting point.
220
247
 
221
248
  rails g asset_sync:install --use-yml --provider=Rackspace
222
249
  rails g asset_sync:install --use-yml --provider=AWS
250
+ rails g asset_sync:install --use-yml --provider=AzureRM
223
251
 
224
252
  The generator will create a YAML file at `config/asset_sync.yml`.
225
253
 
@@ -293,6 +321,7 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
293
321
  * **existing_remote_files**: (`'keep', 'delete', 'ignore'`) what to do with previously precompiled files. **default:** `'keep'`
294
322
  * **gzip\_compression**: (`true, false`) when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. **default:** `'false'`
295
323
  * **manifest**: (`true, false`) when enabled, will use the `manifest.yml` generated by Rails to get the list of local files to upload. **experimental**. **default:** `'false'`
324
+ * **include_manifest**: (`true, false`) when enabled, will upload the `manifest.yml` generated by Rails. **default:** `'false'`
296
325
  * **enabled**: (`true, false`) when false, will disable asset sync. **default:** `'true'` (enabled)
297
326
  * **ignored\_files**: an array of files to ignore e.g. `['ignore_me.js', %r(ignore_some/\d{32}\.css)]` Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy **default**: `[]`
298
327
  * **cache\_asset\_regexps**: an array of files to add cache headers e.g. `['cache_me.js', %r(cache_some\.\d{8}\.css)]` Useful if there are some files that are added to sprockets assets list and need to be set as 'Cacheable' on uploaded server. Only rails compiled regexp is matched internally **default**: `[]`
@@ -316,12 +345,12 @@ end
316
345
  The blocks are run when local files are being scanned and uploaded
317
346
 
318
347
  #### Fog (Required)
319
- * **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage)
348
+ * **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage) or *AzureRM* (Azure Blob)
320
349
  * **fog\_directory**: your bucket name
321
350
 
322
351
  #### Fog (Optional)
323
352
 
324
- * **fog\_region**: the region your storage bucket is in e.g. *eu-west-1* (AWS), *ord* (Rackspace)
353
+ * **fog\_region**: the region your storage bucket is in e.g. *eu-west-1* (AWS), *ord* (Rackspace), *japanwest* (Azure Blob)
325
354
  * **fog\_path\_style**: To use buckets with dot in names, check https://github.com/fog/fog/issues/2381#issuecomment-28088524
326
355
 
327
356
  #### AWS
@@ -338,6 +367,10 @@ The blocks are run when local files are being scanned and uploaded
338
367
  * **google\_storage\_access\_key\_id**: your Google Storage access key
339
368
  * **google\_storage\_secret\_access\_key**: your Google Storage access secret
340
369
 
370
+ #### Azure Blob
371
+ * **azure\_storage\_account\_name**: your Azure Blob access key
372
+ * **azure\_storage\_access\_key**: your Azure Blob access secret
373
+
341
374
  #### Rackspace (Optional)
342
375
 
343
376
  * **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: `https://lon.identity.api.rackspacecloud.com/v2.0`
@@ -494,9 +527,17 @@ end
494
527
 
495
528
  Make sure you have a .env file with these details:-
496
529
 
530
+ # for AWS provider
497
531
  AWS_ACCESS_KEY_ID=<yourkeyid>
498
532
  AWS_SECRET_ACCESS_KEY=<yoursecretkey>
499
533
  FOG_DIRECTORY=<yourbucket>
534
+ FOG_REGION=<youbucketregion>
535
+
536
+ # for AzureRM provider
537
+ AZURE_STORAGE_ACCOUNT_NAME=<youraccountname>
538
+ AZURE_STORAGE_ACCESS_KEY=<youraccesskey>
539
+ FOG_DIRECTORY=<yourcontainer>
540
+ FOG_REGION=<yourcontainerregion>
500
541
 
501
542
  Make sure the bucket has read/write permissions. Then to run the tests:-
502
543
 
data/asset_sync.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency "jeweler"
28
28
 
29
29
  s.add_development_dependency "fog-aws"
30
+ s.add_development_dependency "fog-azure-rm"
30
31
 
31
32
  s.add_development_dependency "uglifier"
32
33
  s.add_development_dependency "appraisal"
@@ -24,6 +24,7 @@ module AssetSync
24
24
  attr_accessor :invalidate
25
25
  attr_accessor :cdn_distribution_id
26
26
  attr_accessor :cache_asset_regexps
27
+ attr_accessor :include_manifest
27
28
 
28
29
  # FOG configuration
29
30
  attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
@@ -42,6 +43,10 @@ module AssetSync
42
43
  # Google Storage
43
44
  attr_accessor :google_storage_secret_access_key, :google_storage_access_key_id
44
45
 
46
+ # Azure Blob with Fog::AzureRM
47
+ attr_accessor :azure_storage_account_name
48
+ attr_accessor :azure_storage_access_key
49
+
45
50
  validates :existing_remote_files, :inclusion => { :in => %w(keep delete ignore) }
46
51
 
47
52
  validates :fog_provider, :presence => true
@@ -69,6 +74,7 @@ module AssetSync
69
74
  self.cdn_distribution_id = nil
70
75
  self.invalidate = []
71
76
  self.cache_asset_regexps = []
77
+ self.include_manifest = false
72
78
  @additional_local_file_paths_procs = []
73
79
 
74
80
  load_yml! if defined?(::Rails) && yml_exists?
@@ -120,6 +126,10 @@ module AssetSync
120
126
  fog_provider =~ /google/i
121
127
  end
122
128
 
129
+ def azure_rm?
130
+ fog_provider =~ /azurerm/i
131
+ end
132
+
123
133
  def cache_asset_regexp=(cache_asset_regexp)
124
134
  self.cache_asset_regexps = [cache_asset_regexp]
125
135
  end
@@ -174,6 +184,10 @@ module AssetSync
174
184
  self.invalidate = yml["invalidate"] if yml.has_key?("invalidate")
175
185
  self.cdn_distribution_id = yml['cdn_distribution_id'] if yml.has_key?("cdn_distribution_id")
176
186
  self.cache_asset_regexps = yml['cache_asset_regexps'] if yml.has_key?("cache_asset_regexps")
187
+ self.include_manifest = yml['include_manifest'] if yml.has_key?("include_manifest")
188
+
189
+ self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
190
+ self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")
177
191
 
178
192
  # TODO deprecate the other old style config settings. FML.
179
193
  self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
@@ -208,25 +222,31 @@ module AssetSync
208
222
  options.merge!({:scheme => fog_scheme}) if fog_scheme
209
223
  options.merge!({:aws_signature_version => aws_signature_version}) if aws_signature_version
210
224
  options.merge!({:path_style => fog_path_style}) if fog_path_style
225
+ options.merge!({:region => fog_region}) if fog_region
211
226
  elsif rackspace?
212
227
  options.merge!({
213
228
  :rackspace_username => rackspace_username,
214
229
  :rackspace_api_key => rackspace_api_key
215
230
  })
216
- options.merge!({
217
- :rackspace_region => fog_region
218
- }) if fog_region
231
+ options.merge!({ :rackspace_region => fog_region }) if fog_region
219
232
  options.merge!({ :rackspace_auth_url => rackspace_auth_url }) if rackspace_auth_url
220
233
  elsif google?
221
234
  options.merge!({
222
235
  :google_storage_secret_access_key => google_storage_secret_access_key,
223
236
  :google_storage_access_key_id => google_storage_access_key_id
224
237
  })
238
+ options.merge!({:region => fog_region}) if fog_region
239
+ elsif azure_rm?
240
+ require 'fog/azurerm'
241
+ options.merge!({
242
+ :azure_storage_account_name => azure_storage_account_name,
243
+ :azure_storage_access_key => azure_storage_access_key,
244
+ })
245
+ options.merge!({:environment => fog_region}) if fog_region
225
246
  else
226
247
  raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
227
248
  end
228
249
 
229
- options.merge!({:region => fog_region}) if fog_region && !rackspace?
230
250
  return options
231
251
  end
232
252
 
@@ -31,12 +31,16 @@ module AssetSync
31
31
  config.google_storage_access_key_id = ENV['GOOGLE_STORAGE_ACCESS_KEY_ID'] if ENV.has_key?('GOOGLE_STORAGE_ACCESS_KEY_ID')
32
32
  config.google_storage_secret_access_key = ENV['GOOGLE_STORAGE_SECRET_ACCESS_KEY'] if ENV.has_key?('GOOGLE_STORAGE_SECRET_ACCESS_KEY')
33
33
 
34
+ config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME'] if ENV.has_key?('AZURE_STORAGE_ACCOUNT_NAME')
35
+ config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY'] if ENV.has_key?('AZURE_STORAGE_ACCESS_KEY')
36
+
34
37
  config.enabled = (ENV['ASSET_SYNC_ENABLED'] == 'true') if ENV.has_key?('ASSET_SYNC_ENABLED')
35
38
 
36
39
  config.existing_remote_files = ENV['ASSET_SYNC_EXISTING_REMOTE_FILES'] || "keep"
37
40
 
38
41
  config.gzip_compression = (ENV['ASSET_SYNC_GZIP_COMPRESSION'] == 'true') if ENV.has_key?('ASSET_SYNC_GZIP_COMPRESSION')
39
42
  config.manifest = (ENV['ASSET_SYNC_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_MANIFEST')
43
+ config.include_manifest = (ENV['ASSET_SYNC_INCLUDE_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_INCLUDE_MANIFEST')
40
44
  end
41
45
 
42
46
  config.prefix = ENV['ASSET_SYNC_PREFIX'] if ENV.has_key?('ASSET_SYNC_PREFIX')
@@ -41,13 +41,25 @@ module AssetSync
41
41
  expand_file_names(self.config.ignored_files)
42
42
  end
43
43
 
44
+ def get_manifest_path
45
+ return [] unless self.config.include_manifest
46
+
47
+ if ActionView::Base.respond_to?(:assets_manifest)
48
+ manifest = Sprockets::Manifest.new(ActionView::Base.assets_manifest.environment, ActionView::Base.assets_manifest.dir)
49
+ manifest_path = manifest.filename
50
+ else
51
+ manifest_path = self.config.manifest_path
52
+ end
53
+ [manifest_path.sub(/^#{path}\//, "")] # full path to relative path
54
+ end
55
+
44
56
  def local_files
45
57
  @local_files ||=
46
58
  (get_local_files + config.additional_local_file_paths).uniq
47
59
  end
48
60
 
49
61
  def always_upload_files
50
- expand_file_names(self.config.always_upload)
62
+ expand_file_names(self.config.always_upload) + get_manifest_path
51
63
  end
52
64
 
53
65
  def files_with_custom_headers
@@ -58,7 +70,10 @@ module AssetSync
58
70
  self.config.invalidate.map { |filename| File.join("/", self.config.assets_prefix, filename) }
59
71
  end
60
72
 
61
- def get_local_files
73
+ # @api
74
+ # To get a list of asset files indicated in a manifest file.
75
+ # It makes sense if a user sets `config.manifest` is true.
76
+ def get_asset_files_from_manifest
62
77
  if self.config.manifest
63
78
  if ActionView::Base.respond_to?(:assets_manifest)
64
79
  log "Using: Rails 4.0 manifest access"
@@ -80,6 +95,13 @@ module AssetSync
80
95
  log "Warning: Manifest could not be found"
81
96
  end
82
97
  end
98
+ end
99
+
100
+ def get_local_files
101
+ if from_manifest = get_asset_files_from_manifest
102
+ return from_manifest
103
+ end
104
+
83
105
  log "Using: Directory Search of #{path}/#{self.config.assets_prefix}"
84
106
  Dir.chdir(path) do
85
107
  to_load = self.config.assets_prefix.present? ? "#{self.config.assets_prefix}/**/**" : '**/**'
@@ -202,6 +224,12 @@ module AssetSync
202
224
  })
203
225
  end
204
226
 
227
+ if config.azure_rm?
228
+ # converts content_type from MIME::Type to String.
229
+ # because Azure::Storage (called from Fog::AzureRM) expects content_type as a String like "application/json; charset=utf-8"
230
+ file[:content_type] = file[:content_type].content_type if file[:content_type].is_a?(::MIME::Type)
231
+ end
232
+
205
233
  bucket.files.create( file ) unless ignore
206
234
  file_handle.close
207
235
  gzip_file_handle.close if gzip_file_handle
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AssetSync
2
- VERSION = "2.3.0".freeze
4
+ VERSION = "2.4.0".freeze
3
5
  end
@@ -5,7 +5,7 @@ module AssetSync
5
5
 
6
6
  # Commandline options can be defined here using Thor-like options:
7
7
  class_option :use_yml, :type => :boolean, :default => false, :desc => "Use YML file instead of Rails Initializer"
8
- class_option :provider, :type => :string, :default => "AWS", :desc => "Generate with support for 'AWS', 'Rackspace', or 'Google'"
8
+ class_option :provider, :type => :string, :default => "AWS", :desc => "Generate with support for 'AWS', 'Rackspace', 'Google', or 'AzureRM"
9
9
 
10
10
  def self.source_root
11
11
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
@@ -23,6 +23,10 @@ module AssetSync
23
23
  options[:provider] == 'Rackspace'
24
24
  end
25
25
 
26
+ def azure_rm?
27
+ options[:provider] == 'AzureRM'
28
+ end
29
+
26
30
  def aws_access_key_id
27
31
  "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
28
32
  end
@@ -47,6 +51,14 @@ module AssetSync
47
51
  "<%= ENV['RACKSPACE_API_KEY'] %>"
48
52
  end
49
53
 
54
+ def azure_storage_account_name
55
+ "<%= ENV['AZURE_STORAGE_ACCOUNT_NAME'] %>"
56
+ end
57
+
58
+ def azure_storage_access_key
59
+ "<%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>"
60
+ end
61
+
50
62
  def app_name
51
63
  @app_name ||= Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "").downcase
52
64
  end
@@ -26,6 +26,12 @@ if defined?(AssetSync)
26
26
 
27
27
  # if you need to change rackspace_auth_url (e.g. if you need to use Rackspace London)
28
28
  # config.rackspace_auth_url = "lon.auth.api.rackspacecloud.com"
29
+ <%- elsif azure_rm? -%>
30
+ config.fog_provider = 'AzureRM'
31
+ config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME']
32
+ config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY']
33
+
34
+ # config.fog_directory specifies container name of Azure Blob storage
29
35
  <%- end -%>
30
36
  config.fog_directory = ENV['FOG_DIRECTORY']
31
37
 
@@ -46,6 +52,9 @@ if defined?(AssetSync)
46
52
  # upload instead of searching the assets directory.
47
53
  # config.manifest = true
48
54
  #
55
+ # Upload the manifest file also.
56
+ # config.include_manifest = false
57
+ #
49
58
  # Fail silently. Useful for environments such as Heroku
50
59
  # config.fail_silently = true
51
60
  #
@@ -24,6 +24,12 @@ defaults: &defaults
24
24
  rackspace_api_key: "<%= rackspace_api_key %>"
25
25
  # if you need to change rackspace_auth_url (e.g. if you need to use Rackspace London)
26
26
  # rackspace_auth_url: "https://lon.identity.api.rackspacecloud.com/v2.0"
27
+ <%- elsif azure_rm? -%>
28
+ fog_provider: 'AzureRM'
29
+ azure_storage_account_name: "<%= azure_storage_account_name %>"
30
+ azure_storage_access_key: "<%= azure_storage_access_key %>"
31
+
32
+ # fog_directory specifies container name of Azure Blob storage
27
33
  <%- end -%>
28
34
  fog_directory: "<%= app_name %>-assets"
29
35
  # You may need to specify what region your storage bucket is in
@@ -0,0 +1,19 @@
1
+ defaults: &defaults
2
+ fog_provider: "AzureRM"
3
+ azure_storage_account_name: 'xxxx'
4
+ azure_storage_access_key: 'zzzz'
5
+
6
+ development:
7
+ <<: *defaults
8
+ fog_directory: "rails_app_development"
9
+ existing_remote_files: keep
10
+
11
+ test:
12
+ <<: *defaults
13
+ fog_directory: "rails_app_test"
14
+ existing_remote_files: keep
15
+
16
+ production:
17
+ <<: *defaults
18
+ fog_directory: "rails_app_production"
19
+ existing_remote_files: delete
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "fog/azurerm"
3
+
4
+ def bucket(name)
5
+ options = {
6
+ :provider => 'AzureRM',
7
+ :azure_storage_account_name => ENV['AZURE_STORAGE_ACCOUNT_NAME'],
8
+ :azure_storage_access_key => ENV['AZURE_STORAGE_ACCESS_KEY']
9
+ }
10
+ options.merge!({ :environment => ENV['FOG_REGION'] }) if ENV.has_key?('FOG_REGION')
11
+
12
+ connection = Fog::Storage.new(options)
13
+ connection.directories.get(ENV['FOG_DIRECTORY'], :prefix => name)
14
+ end
15
+
16
+ def execute(command)
17
+ app_path = File.expand_path("../../dummy_app", __FILE__)
18
+ Dir.chdir app_path
19
+ `#{command}`
20
+ end
21
+
22
+ describe "AssetSync" do
23
+
24
+ before(:each) do
25
+ @prefix = SecureRandom.hex(6)
26
+ end
27
+
28
+ let(:app_js_regex){
29
+ /#{@prefix}\/application-[a-zA-Z0-9]*.js$/
30
+ }
31
+
32
+ let(:app_js_gz_regex){
33
+ /#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
34
+ }
35
+
36
+ let(:files){ bucket(@prefix).files }
37
+
38
+
39
+ after(:each) do
40
+ @directory = bucket(@prefix)
41
+ @directory.files.each do |f|
42
+ f.destroy
43
+ end
44
+ end
45
+
46
+ it "sync" do
47
+ execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile"
48
+
49
+ files = bucket(@prefix).files
50
+
51
+ app_js = files.select{ |f| f.key =~ app_js_regex }.first
52
+ expect(app_js.content_type).to eq("application/javascript")
53
+
54
+ app_js_gz = files.select{ |f| f.key =~ app_js_gz_regex }.first
55
+ expect(app_js_gz.content_type).to eq("application/javascript")
56
+ expect(app_js_gz.content_encoding).to eq("gzip")
57
+ end
58
+
59
+ it "sync with enabled=false" do
60
+ execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile"
61
+ expect(bucket(@prefix).files.size).to eq(0)
62
+ end
63
+
64
+ it "sync with gzip_compression=true" do
65
+ execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile"
66
+ # bucket(@prefix).files.size.should == 3
67
+
68
+ app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
69
+ app_js = files.get( app_js_path.key )
70
+ expect(app_js.content_type).to eq("application/javascript")
71
+ end
72
+
73
+ end
74
+
@@ -0,0 +1,142 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe AssetSync do
4
+ include_context "mock Rails without_yml"
5
+
6
+ describe 'with initializer' do
7
+ before(:each) do
8
+ AssetSync.config = AssetSync::Config.new
9
+ AssetSync.configure do |config|
10
+ config.fog_provider = 'AzureRM'
11
+ config.azure_storage_account_name = 'aaaa'
12
+ config.azure_storage_access_key = 'bbbb'
13
+ config.fog_directory = 'mybucket'
14
+ config.existing_remote_files = "keep"
15
+ end
16
+ end
17
+
18
+ it "should configure provider as AzureRM" do
19
+ expect(AssetSync.config.fog_provider).to eq('AzureRM')
20
+ expect(AssetSync.config).to be_azure_rm
21
+ end
22
+
23
+ it "should should keep existing remote files" do
24
+ expect(AssetSync.config.existing_remote_files?).to eq(true)
25
+ end
26
+
27
+ it "should configure azure_storage_account_name" do
28
+ expect(AssetSync.config.azure_storage_account_name).to eq("aaaa")
29
+ end
30
+
31
+ it "should configure azure_storage_access_key" do
32
+ expect(AssetSync.config.azure_storage_access_key).to eq("bbbb")
33
+ end
34
+
35
+ it "should configure fog_directory" do
36
+ expect(AssetSync.config.fog_directory).to eq("mybucket")
37
+ end
38
+
39
+ it "should configure existing_remote_files" do
40
+ expect(AssetSync.config.existing_remote_files).to eq("keep")
41
+ end
42
+
43
+ it "should default gzip_compression to false" do
44
+ expect(AssetSync.config.gzip_compression).to be_falsey
45
+ end
46
+
47
+ it "should default manifest to false" do
48
+ expect(AssetSync.config.manifest).to be_falsey
49
+ end
50
+ end
51
+
52
+ describe 'from yml' do
53
+ before(:each) do
54
+ set_rails_root('azure_rm_with_yml')
55
+ AssetSync.config = AssetSync::Config.new
56
+ end
57
+
58
+ it "should configure azure_storage_account_name" do
59
+ expect(AssetSync.config.azure_storage_account_name).to eq("xxxx")
60
+ end
61
+
62
+ it "should configure azure_storage_access_key" do
63
+ expect(AssetSync.config.azure_storage_access_key).to eq("zzzz")
64
+ end
65
+
66
+ it "should configure fog_directory" do
67
+ expect(AssetSync.config.fog_directory).to eq("rails_app_test")
68
+ end
69
+
70
+ it "should configure existing_remote_files" do
71
+ expect(AssetSync.config.existing_remote_files).to eq("keep")
72
+ end
73
+
74
+ it "should default gzip_compression to false" do
75
+ expect(AssetSync.config.gzip_compression).to be_falsey
76
+ end
77
+
78
+ it "should default manifest to false" do
79
+ expect(AssetSync.config.manifest).to be_falsey
80
+ end
81
+ end
82
+
83
+ describe 'with no configuration' do
84
+ before(:each) do
85
+ AssetSync.config = AssetSync::Config.new
86
+ end
87
+
88
+ it "should be invalid" do
89
+ expect{ AssetSync.sync }.to raise_error(::AssetSync::Config::Invalid)
90
+ end
91
+ end
92
+
93
+ describe 'with fail_silent configuration' do
94
+ before(:each) do
95
+ allow(AssetSync).to receive(:stderr).and_return(StringIO.new)
96
+ AssetSync.config = AssetSync::Config.new
97
+ AssetSync.configure do |config|
98
+ config.fail_silently = true
99
+ end
100
+ end
101
+
102
+ it "should not raise an invalid exception" do
103
+ expect{ AssetSync.sync }.not_to raise_error
104
+ end
105
+ end
106
+
107
+ describe 'with gzip_compression enabled' do
108
+ before(:each) do
109
+ AssetSync.config = AssetSync::Config.new
110
+ AssetSync.config.gzip_compression = true
111
+ end
112
+
113
+ it "config.gzip? should be true" do
114
+ expect(AssetSync.config.gzip?).to be_truthy
115
+ end
116
+ end
117
+
118
+ describe 'with manifest enabled' do
119
+ before(:each) do
120
+ AssetSync.config = AssetSync::Config.new
121
+ AssetSync.config.manifest = true
122
+ end
123
+
124
+ it "config.manifest should be true" do
125
+ expect(AssetSync.config.manifest).to be_truthy
126
+ end
127
+
128
+ it "config.manifest_path should default to public/assets.." do
129
+ expect(AssetSync.config.manifest_path).to match(/public\/assets\/manifest.yml/)
130
+ end
131
+
132
+ it "config.manifest_path should default to public/assets.." do
133
+ Rails.application.config.assets.manifest = "/var/assets"
134
+ expect(AssetSync.config.manifest_path).to eq("/var/assets/manifest.yml")
135
+ end
136
+
137
+ it "config.manifest_path should default to public/custom_assets.." do
138
+ Rails.application.config.assets.prefix = 'custom_assets'
139
+ expect(AssetSync.config.manifest_path).to match(/public\/custom_assets\/manifest.yml/)
140
+ end
141
+ end
142
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hamilton
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-12-05 00:00:00.000000000 Z
14
+ date: 2017-12-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-core
@@ -125,6 +125,20 @@ dependencies:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
+ - !ruby/object:Gem::Dependency
129
+ name: fog-azure-rm
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
128
142
  - !ruby/object:Gem::Dependency
129
143
  name: uglifier
130
144
  requirement: !ruby/object:Gem::Requirement
@@ -194,12 +208,15 @@ files:
194
208
  - spec/dummy_app/Rakefile
195
209
  - spec/dummy_app/app/assets/javascripts/application.js
196
210
  - spec/fixtures/aws_with_yml/config/asset_sync.yml
211
+ - spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
197
212
  - spec/fixtures/google_with_yml/config/asset_sync.yml
198
213
  - spec/fixtures/rackspace_with_yml/config/asset_sync.yml
199
214
  - spec/fixtures/with_invalid_yml/config/asset_sync.yml
200
215
  - spec/integration/aws_integration_spec.rb
216
+ - spec/integration/azure_rm_integration_spec.rb
201
217
  - spec/spec_helper.rb
202
218
  - spec/unit/asset_sync_spec.rb
219
+ - spec/unit/azure_rm_spec.rb
203
220
  - spec/unit/google_spec.rb
204
221
  - spec/unit/multi_mime_spec.rb
205
222
  - spec/unit/rackspace_spec.rb
@@ -234,12 +251,15 @@ test_files:
234
251
  - spec/dummy_app/Rakefile
235
252
  - spec/dummy_app/app/assets/javascripts/application.js
236
253
  - spec/fixtures/aws_with_yml/config/asset_sync.yml
254
+ - spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
237
255
  - spec/fixtures/google_with_yml/config/asset_sync.yml
238
256
  - spec/fixtures/rackspace_with_yml/config/asset_sync.yml
239
257
  - spec/fixtures/with_invalid_yml/config/asset_sync.yml
240
258
  - spec/integration/aws_integration_spec.rb
259
+ - spec/integration/azure_rm_integration_spec.rb
241
260
  - spec/spec_helper.rb
242
261
  - spec/unit/asset_sync_spec.rb
262
+ - spec/unit/azure_rm_spec.rb
243
263
  - spec/unit/google_spec.rb
244
264
  - spec/unit/multi_mime_spec.rb
245
265
  - spec/unit/rackspace_spec.rb