asset_sync 2.9.1 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +47 -1
- data/README.md +35 -5
- data/asset_sync.gemspec +1 -0
- data/lib/asset_sync/config.rb +29 -1
- data/lib/asset_sync/engine.rb +6 -0
- data/lib/asset_sync/storage.rb +53 -9
- data/lib/asset_sync/version.rb +1 -1
- data/lib/generators/asset_sync/install_generator.rb +21 -1
- data/lib/generators/asset_sync/templates/asset_sync.rb +10 -0
- data/lib/generators/asset_sync/templates/asset_sync.yml +6 -1
- data/spec/fixtures/backblaze_with_yml/config/asset_sync.yml +20 -0
- data/spec/integration/backblaze_intergration_spec.rb +74 -0
- data/spec/unit/backblaze_spec.rb +150 -0
- data/spec/unit/storage_spec.rb +66 -0
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9d768c5e2075b08498c16af32ad4fb3f1006d4c68bd88846a60c843309a8ef3
|
4
|
+
data.tar.gz: 87a0b335fd8fc8903f30ce171d78d7beff4a87cb7fe0962bdf0c68dcf537c277
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24dba26c0c958ce65353daccf498fba8b5689a778d9e091325eeb323677f8057ade739e37c60a7c1e8d66d3bae36d87601da6d2bd569bf06559df89cdfca24f9
|
7
|
+
data.tar.gz: eca6579e50a37d8ce887cb5a44c068db42a387d04b58badb9b371d77944fd7f1a95c57132a0af4863f63efe62a7403f68b74d512145da78ca4aeee060344e17c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,46 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
18
18
|
- Nothing
|
19
19
|
|
20
20
|
|
21
|
+
## [2.13.0] - 2020-12-14
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Add Backblaze B2 Cloud Storage support
|
26
|
+
(https://github.com/AssetSync/asset_sync/pull/410)
|
27
|
+
|
28
|
+
|
29
|
+
## [2.12.1] - 2020-06-17
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
|
33
|
+
- Fix initializer template in generator
|
34
|
+
(https://github.com/AssetSync/asset_sync/pull/404)
|
35
|
+
|
36
|
+
|
37
|
+
## [2.12.0] - 2020-06-11
|
38
|
+
|
39
|
+
### Added
|
40
|
+
|
41
|
+
- Add option `aws_session_token` to support AWS Temporary Security Credentials
|
42
|
+
(https://github.com/AssetSync/asset_sync/pull/403)
|
43
|
+
|
44
|
+
|
45
|
+
## [2.11.0] - 2020-03-13
|
46
|
+
|
47
|
+
### Added
|
48
|
+
|
49
|
+
- Add option `remote_file_list_cache_file_path` to skip scanning remote
|
50
|
+
(https://github.com/AssetSync/asset_sync/pull/400)
|
51
|
+
|
52
|
+
|
53
|
+
## [2.10.0] - 2020-02-26
|
54
|
+
|
55
|
+
### Added
|
56
|
+
|
57
|
+
- Add option `concurrent_uploads_max_threads` to limit number of threads for uploading files
|
58
|
+
(https://github.com/AssetSync/asset_sync/pull/398)
|
59
|
+
|
60
|
+
|
21
61
|
## [2.9.1] - 2020-02-20
|
22
62
|
|
23
63
|
### Fixed
|
@@ -946,7 +986,13 @@ Changes:
|
|
946
986
|
* Merge branch 'sinatra'
|
947
987
|
|
948
988
|
|
949
|
-
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.
|
989
|
+
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.13.0...HEAD
|
990
|
+
[2.13.0]: https://github.com/AssetSync/asset_sync/compare/v2.12.1...v2.13.0
|
991
|
+
[2.12.1]: https://github.com/AssetSync/asset_sync/compare/v2.12.0...v2.12.1
|
992
|
+
[2.12.0]: https://github.com/AssetSync/asset_sync/compare/v2.11.0...v2.12.0
|
993
|
+
[2.11.0]: https://github.com/AssetSync/asset_sync/compare/v2.10.0...v2.11.0
|
994
|
+
[2.10.0]: https://github.com/AssetSync/asset_sync/compare/v2.9.1...v2.10.0
|
995
|
+
[2.9.1]: https://github.com/AssetSync/asset_sync/compare/v2.9.0...v2.9.1
|
950
996
|
[2.9.0]: https://github.com/AssetSync/asset_sync/compare/v2.8.2...v2.9.0
|
951
997
|
[2.8.2]: https://github.com/AssetSync/asset_sync/compare/v2.8.1...v2.8.2
|
952
998
|
[2.8.1]: https://github.com/AssetSync/asset_sync/compare/v2.8.0...v2.8.1
|
data/README.md
CHANGED
@@ -38,6 +38,13 @@ gem "asset_sync"
|
|
38
38
|
gem "fog-azure-rm"
|
39
39
|
```
|
40
40
|
|
41
|
+
To use Backblaze B2, insert these.
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
gem "asset_sync"
|
45
|
+
gem "fog-backblaze"
|
46
|
+
```
|
47
|
+
|
41
48
|
|
42
49
|
### Extended Installation (Faster sync with turbosprockets)
|
43
50
|
|
@@ -77,6 +84,13 @@ Or, to use Azure Blob storage, configure as this.
|
|
77
84
|
config.action_controller.asset_host = "//#{ENV['AZURE_STORAGE_ACCOUNT_NAME']}.blob.core.windows.net/#{ENV['FOG_DIRECTORY']}"
|
78
85
|
```
|
79
86
|
|
87
|
+
Or, to use Backblaze B2, configure as this.
|
88
|
+
|
89
|
+
``` ruby
|
90
|
+
#config/environments/production.rb
|
91
|
+
config.action_controller.asset_host = "//f000.backblazeb2.com/file/#{ENV['FOG_DIRECTORY']}"
|
92
|
+
```
|
93
|
+
|
80
94
|
|
81
95
|
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.
|
82
96
|
|
@@ -170,7 +184,7 @@ heroku config:add FOG_DIRECTORY=xxxx
|
|
170
184
|
heroku config:add FOG_PROVIDER=Rackspace
|
171
185
|
```
|
172
186
|
|
173
|
-
Google Storage Cloud configuration is supported as well. The preferred option is using the [GCS JSON API](https://github.com/fog/fog-google#storage) which requires that you create an appropriate service account, generate the signatures and make them accessible to asset sync at the prescribed location
|
187
|
+
Google Storage Cloud configuration is supported as well. The preferred option is using the [GCS JSON API](https://github.com/fog/fog-google#storage) which requires that you create an appropriate service account, generate the signatures and make them accessible to asset sync at the prescribed location
|
174
188
|
|
175
189
|
```bash
|
176
190
|
heroku config:add FOG_PROVIDER=Google
|
@@ -199,6 +213,7 @@ Run the included Rake task to generate a starting point.
|
|
199
213
|
rails g asset_sync:install --provider=Rackspace
|
200
214
|
rails g asset_sync:install --provider=AWS
|
201
215
|
rails g asset_sync:install --provider=AzureRM
|
216
|
+
rails g asset_sync:install --provider=Backblaze
|
202
217
|
|
203
218
|
The generator will create a Rails initializer at `config/initializers/asset_sync.rb`.
|
204
219
|
|
@@ -208,6 +223,7 @@ AssetSync.configure do |config|
|
|
208
223
|
config.fog_directory = ENV['FOG_DIRECTORY']
|
209
224
|
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
210
225
|
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
226
|
+
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.key?('AWS_SESSION_TOKEN')
|
211
227
|
|
212
228
|
# Don't delete files from the store
|
213
229
|
# config.existing_remote_files = 'keep'
|
@@ -245,6 +261,12 @@ AssetSync.configure do |config|
|
|
245
261
|
# Upload files concurrently
|
246
262
|
# config.concurrent_uploads = false
|
247
263
|
#
|
264
|
+
# Number of threads when concurrent_uploads is enabled
|
265
|
+
# config.concurrent_uploads_max_threads = 10
|
266
|
+
#
|
267
|
+
# Path to cache file to skip scanning remote
|
268
|
+
# config.remote_file_list_cache_file_path = './.asset_sync_remote_file_list_cache.json'
|
269
|
+
#
|
248
270
|
# Fail silently. Useful for environments such as Heroku
|
249
271
|
# config.fail_silently = true
|
250
272
|
#
|
@@ -267,6 +289,7 @@ Run the included Rake task to generate a starting point.
|
|
267
289
|
rails g asset_sync:install --use-yml --provider=Rackspace
|
268
290
|
rails g asset_sync:install --use-yml --provider=AWS
|
269
291
|
rails g asset_sync:install --use-yml --provider=AzureRM
|
292
|
+
rails g asset_sync:install --use-yml --provider=Backblaze
|
270
293
|
|
271
294
|
The generator will create a YAML file at `config/asset_sync.yml`.
|
272
295
|
|
@@ -342,6 +365,8 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
|
|
342
365
|
* **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'`
|
343
366
|
* **include_manifest**: (`true, false`) when enabled, will upload the `manifest.yml` generated by Rails. **default:** `'false'`
|
344
367
|
* **concurrent_uploads**: (`true, false`) when enabled, will upload the files in different Threads, this greatly improves the upload speed. **default:** `'false'`
|
368
|
+
* **concurrent_uploads_max_threads**: when concurrent_uploads is enabled, this determines the number of threads that will be created. **default:** `10`
|
369
|
+
* **remote_file_list_cache_file_path**: if present, use this path to cache remote file list to skip scanning remote **default:** `nil`
|
345
370
|
* **enabled**: (`true, false`) when false, will disable asset sync. **default:** `'true'` (enabled)
|
346
371
|
* **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**: `[]`
|
347
372
|
* **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**: `[]`
|
@@ -374,7 +399,7 @@ To customize the overrides:
|
|
374
399
|
AssetSync.configure do |config|
|
375
400
|
# Clear the default overrides
|
376
401
|
config.file_ext_to_mime_type_overrides.clear
|
377
|
-
|
402
|
+
|
378
403
|
# Add/Edit overrides
|
379
404
|
# Will call `#to_s` for inputs
|
380
405
|
config.file_ext_to_mime_type_overrides.add(:js, :"application/x-javascript")
|
@@ -383,7 +408,7 @@ end
|
|
383
408
|
The blocks are run when local files are being scanned and uploaded
|
384
409
|
|
385
410
|
#### Fog (Required)
|
386
|
-
* **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage) or *AzureRM* (Azure Blob)
|
411
|
+
* **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage) or *AzureRM* (Azure Blob) or *Backblaze* (Backblaze B2)
|
387
412
|
* **fog\_directory**: your bucket name
|
388
413
|
|
389
414
|
#### Fog (Optional)
|
@@ -417,6 +442,11 @@ When using the S3 API
|
|
417
442
|
* **azure\_storage\_account\_name**: your Azure Blob access key
|
418
443
|
* **azure\_storage\_access\_key**: your Azure Blob access secret
|
419
444
|
|
445
|
+
#### Backblaze B2
|
446
|
+
* **b2\_key\_id**: Your Backblaze B2 key ID
|
447
|
+
* **b2\_key\_token**: Your Backblaze B2 key token
|
448
|
+
* **b2\_bucket\_id**: Your Backblaze B2 bucket ID
|
449
|
+
|
420
450
|
#### Rackspace (Optional)
|
421
451
|
|
422
452
|
* **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: `https://lon.identity.api.rackspacecloud.com/v2.0`
|
@@ -542,7 +572,7 @@ AssetSync.configure do |config|
|
|
542
572
|
config.prefix = 'assets'
|
543
573
|
# Can be a `Pathname` or `String`
|
544
574
|
# Will be converted into an `Pathname`
|
545
|
-
# If relative, will be converted into an absolute path
|
575
|
+
# If relative, will be converted into an absolute path
|
546
576
|
# via `::Rails.root` or `::Dir.pwd`
|
547
577
|
config.public_path = Pathname('./public')
|
548
578
|
end
|
@@ -613,7 +643,7 @@ Make sure you have a .env file with these details:-
|
|
613
643
|
AWS_SECRET_ACCESS_KEY=<yoursecretkey>
|
614
644
|
FOG_DIRECTORY=<yourbucket>
|
615
645
|
FOG_REGION=<youbucketregion>
|
616
|
-
|
646
|
+
|
617
647
|
# for AzureRM provider
|
618
648
|
AZURE_STORAGE_ACCOUNT_NAME=<youraccountname>
|
619
649
|
AZURE_STORAGE_ACCESS_KEY=<youraccesskey>
|
data/asset_sync.gemspec
CHANGED
data/lib/asset_sync/config.rb
CHANGED
@@ -27,6 +27,8 @@ module AssetSync
|
|
27
27
|
attr_accessor :cache_asset_regexps
|
28
28
|
attr_accessor :include_manifest
|
29
29
|
attr_accessor :concurrent_uploads
|
30
|
+
attr_accessor :concurrent_uploads_max_threads
|
31
|
+
attr_accessor :remote_file_list_cache_file_path
|
30
32
|
|
31
33
|
# FOG configuration
|
32
34
|
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
|
@@ -35,7 +37,7 @@ module AssetSync
|
|
35
37
|
attr_reader :fog_public # e.g. true, false, "default"
|
36
38
|
|
37
39
|
# Amazon AWS
|
38
|
-
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_reduced_redundancy, :aws_iam_roles, :aws_signature_version
|
40
|
+
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_session_token, :aws_reduced_redundancy, :aws_iam_roles, :aws_signature_version
|
39
41
|
attr_accessor :fog_host # e.g. 's3.amazonaws.com'
|
40
42
|
attr_accessor :fog_port # e.g. '9000'
|
41
43
|
attr_accessor :fog_path_style # e.g. true
|
@@ -53,6 +55,11 @@ module AssetSync
|
|
53
55
|
attr_accessor :azure_storage_account_name
|
54
56
|
attr_accessor :azure_storage_access_key
|
55
57
|
|
58
|
+
# Backblaze B2 with Fog::Backblaze
|
59
|
+
attr_accessor :b2_key_id
|
60
|
+
attr_accessor :b2_key_token
|
61
|
+
attr_accessor :b2_bucket_id
|
62
|
+
|
56
63
|
validates :existing_remote_files, :inclusion => { :in => %w(keep delete ignore) }
|
57
64
|
|
58
65
|
validates :fog_provider, :presence => true
|
@@ -86,6 +93,8 @@ module AssetSync
|
|
86
93
|
self.cache_asset_regexps = []
|
87
94
|
self.include_manifest = false
|
88
95
|
self.concurrent_uploads = false
|
96
|
+
self.concurrent_uploads_max_threads = 10
|
97
|
+
self.remote_file_list_cache_file_path = nil
|
89
98
|
@additional_local_file_paths_procs = []
|
90
99
|
|
91
100
|
load_yml! if defined?(::Rails) && yml_exists?
|
@@ -149,6 +158,10 @@ module AssetSync
|
|
149
158
|
fog_provider =~ /azurerm/i
|
150
159
|
end
|
151
160
|
|
161
|
+
def backblaze?
|
162
|
+
fog_provider =~ /backblaze/i
|
163
|
+
end
|
164
|
+
|
152
165
|
def cache_asset_regexp=(cache_asset_regexp)
|
153
166
|
self.cache_asset_regexps = [cache_asset_regexp]
|
154
167
|
end
|
@@ -199,6 +212,7 @@ module AssetSync
|
|
199
212
|
self.fog_scheme = yml["fog_scheme"]
|
200
213
|
self.aws_access_key_id = yml["aws_access_key_id"]
|
201
214
|
self.aws_secret_access_key = yml["aws_secret_access_key"]
|
215
|
+
self.aws_session_token = yml["aws_session_token"] if yml.has_key?("aws_session_token")
|
202
216
|
self.aws_reduced_redundancy = yml["aws_reduced_redundancy"]
|
203
217
|
self.aws_iam_roles = yml["aws_iam_roles"]
|
204
218
|
self.aws_signature_version = yml["aws_signature_version"]
|
@@ -222,10 +236,16 @@ module AssetSync
|
|
222
236
|
self.cache_asset_regexps = yml['cache_asset_regexps'] if yml.has_key?("cache_asset_regexps")
|
223
237
|
self.include_manifest = yml['include_manifest'] if yml.has_key?("include_manifest")
|
224
238
|
self.concurrent_uploads = yml['concurrent_uploads'] if yml.has_key?('concurrent_uploads')
|
239
|
+
self.concurrent_uploads_max_threads = yml['concurrent_uploads_max_threads'] if yml.has_key?('concurrent_uploads_max_threads')
|
240
|
+
self.remote_file_list_cache_file_path = yml['remote_file_list_cache_file_path'] if yml.has_key?('remote_file_list_cache_file_path')
|
225
241
|
|
226
242
|
self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
|
227
243
|
self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")
|
228
244
|
|
245
|
+
self.b2_key_id = yml['b2_key_id'] if yml.has_key?("b2_key_id")
|
246
|
+
self.b2_key_token = yml['b2_key_token'] if yml.has_key?("b2_key_token")
|
247
|
+
self.b2_bucket_id = yml['b2_bucket_id'] if yml.has_key?("b2_bucket_id")
|
248
|
+
|
229
249
|
# TODO deprecate the other old style config settings. FML.
|
230
250
|
self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
|
231
251
|
self.aws_secret_access_key = yml["aws_access_secret"] if yml.has_key?("aws_access_secret")
|
@@ -254,6 +274,7 @@ module AssetSync
|
|
254
274
|
:aws_access_key_id => aws_access_key_id,
|
255
275
|
:aws_secret_access_key => aws_secret_access_key
|
256
276
|
})
|
277
|
+
options.merge!({:aws_session_token => aws_session_token}) if aws_session_token
|
257
278
|
end
|
258
279
|
options.merge!({:host => fog_host}) if fog_host
|
259
280
|
options.merge!({:port => fog_port}) if fog_port
|
@@ -285,6 +306,13 @@ module AssetSync
|
|
285
306
|
:azure_storage_access_key => azure_storage_access_key,
|
286
307
|
})
|
287
308
|
options.merge!({:environment => fog_region}) if fog_region
|
309
|
+
elsif backblaze?
|
310
|
+
require 'fog/backblaze'
|
311
|
+
options.merge!({
|
312
|
+
:b2_key_id => b2_key_id,
|
313
|
+
:b2_key_token => b2_key_token,
|
314
|
+
:b2_bucket_id => b2_bucket_id,
|
315
|
+
})
|
288
316
|
else
|
289
317
|
raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
|
290
318
|
end
|
data/lib/asset_sync/engine.rb
CHANGED
@@ -23,6 +23,7 @@ module AssetSync
|
|
23
23
|
|
24
24
|
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID'] if ENV.has_key?('AWS_ACCESS_KEY_ID')
|
25
25
|
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] if ENV.has_key?('AWS_SECRET_ACCESS_KEY')
|
26
|
+
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.has_key?('AWS_SESSION_TOKEN')
|
26
27
|
config.aws_signature_version = ENV['AWS_SIGNATURE_VERSION'] if ENV.has_key?('AWS_SIGNATURE_VERSION')
|
27
28
|
config.aws_reduced_redundancy = ENV['AWS_REDUCED_REDUNDANCY'] == true if ENV.has_key?('AWS_REDUCED_REDUNDANCY')
|
28
29
|
|
@@ -35,6 +36,10 @@ module AssetSync
|
|
35
36
|
config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME'] if ENV.has_key?('AZURE_STORAGE_ACCOUNT_NAME')
|
36
37
|
config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY'] if ENV.has_key?('AZURE_STORAGE_ACCESS_KEY')
|
37
38
|
|
39
|
+
config.b2_key_id = ENV['B2_KEY_ID'] if ENV.has_key?('B2_KEY_ID')
|
40
|
+
config.b2_key_token = ENV['B2_KEY_TOKEN'] if ENV.has_key?('B2_KEY_TOKEN')
|
41
|
+
config.b2_bucket_id = ENV['B2_BUCKET_ID'] if ENV.has_key?('B2_BUCKET_ID')
|
42
|
+
|
38
43
|
config.enabled = (ENV['ASSET_SYNC_ENABLED'] == 'true') if ENV.has_key?('ASSET_SYNC_ENABLED')
|
39
44
|
|
40
45
|
config.existing_remote_files = ENV['ASSET_SYNC_EXISTING_REMOTE_FILES'] || "keep"
|
@@ -43,6 +48,7 @@ module AssetSync
|
|
43
48
|
config.manifest = (ENV['ASSET_SYNC_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_MANIFEST')
|
44
49
|
config.include_manifest = (ENV['ASSET_SYNC_INCLUDE_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_INCLUDE_MANIFEST')
|
45
50
|
config.concurrent_uploads = (ENV['ASSET_SYNC_CONCURRENT_UPLOADS'] == 'true') if ENV.has_key?('ASSET_SYNC_CONCURRENT_UPLOADS')
|
51
|
+
config.remote_file_list_cache_file_path = ENV['ASSET_SYNC_REMOTE_FILE_LIST_CACHE_FILE_PATH'] if ENV.has_key?('ASSET_SYNC_REMOTE_FILE_LIST_CACHE_FILE_PATH')
|
46
52
|
end
|
47
53
|
|
48
54
|
config.prefix = ENV['ASSET_SYNC_PREFIX'] if ENV.has_key?('ASSET_SYNC_PREFIX')
|
data/lib/asset_sync/storage.rb
CHANGED
@@ -22,7 +22,13 @@ module AssetSync
|
|
22
22
|
|
23
23
|
def bucket
|
24
24
|
# fixes: https://github.com/rumblelabs/asset_sync/issues/18
|
25
|
-
|
25
|
+
|
26
|
+
@bucket ||= if self.config.backblaze?
|
27
|
+
connection.directories.get(self.config.fog_directory)
|
28
|
+
else
|
29
|
+
connection.directories.get(self.config.fog_directory, :prefix => self.config.assets_prefix)
|
30
|
+
end
|
31
|
+
|
26
32
|
end
|
27
33
|
|
28
34
|
def log(msg)
|
@@ -37,6 +43,10 @@ module AssetSync
|
|
37
43
|
self.config.public_path
|
38
44
|
end
|
39
45
|
|
46
|
+
def remote_file_list_cache_file_path
|
47
|
+
self.config.remote_file_list_cache_file_path
|
48
|
+
end
|
49
|
+
|
40
50
|
def ignored_files
|
41
51
|
expand_file_names(self.config.ignored_files)
|
42
52
|
end
|
@@ -58,6 +68,32 @@ module AssetSync
|
|
58
68
|
(get_local_files + config.additional_local_file_paths).uniq
|
59
69
|
end
|
60
70
|
|
71
|
+
def remote_files
|
72
|
+
return [] if ignore_existing_remote_files?
|
73
|
+
return @remote_files if @remote_files
|
74
|
+
|
75
|
+
if remote_file_list_cache_file_path && File.file?(remote_file_list_cache_file_path)
|
76
|
+
begin
|
77
|
+
content = File.read(remote_file_list_cache_file_path)
|
78
|
+
return @remote_files = JSON.parse(content)
|
79
|
+
rescue JSON::ParserError
|
80
|
+
warn "Failed to parse #{remote_file_list_cache_file_path} as json"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
@remote_files = get_remote_files
|
85
|
+
end
|
86
|
+
|
87
|
+
def update_remote_file_list_cache(local_files_to_upload)
|
88
|
+
return unless remote_file_list_cache_file_path
|
89
|
+
return if ignore_existing_remote_files?
|
90
|
+
|
91
|
+
File.open(self.remote_file_list_cache_file_path, 'w') do |file|
|
92
|
+
uploaded = local_files_to_upload + remote_files
|
93
|
+
file.write(uploaded.to_json)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
61
97
|
def always_upload_files
|
62
98
|
expand_file_names(self.config.always_upload) + get_manifest_path
|
63
99
|
end
|
@@ -243,24 +279,30 @@ module AssetSync
|
|
243
279
|
end
|
244
280
|
|
245
281
|
def upload_files
|
246
|
-
# get a fresh list of remote files
|
247
|
-
remote_files = ignore_existing_remote_files? ? [] : get_remote_files
|
248
282
|
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
|
249
283
|
local_files_to_upload = local_files - ignored_files - remote_files + always_upload_files
|
250
284
|
local_files_to_upload = (local_files_to_upload + get_non_fingerprinted(local_files_to_upload)).uniq
|
285
|
+
# Only files.
|
286
|
+
local_files_to_upload = local_files_to_upload.select { |f| File.file? "#{path}/#{f}" }
|
251
287
|
|
252
288
|
if self.config.concurrent_uploads
|
253
|
-
|
289
|
+
jobs = Queue.new
|
290
|
+
local_files_to_upload.each { |f| jobs.push(f) }
|
291
|
+
jobs.close
|
292
|
+
|
293
|
+
num_threads = [self.config.concurrent_uploads_max_threads, local_files_to_upload.length].min
|
254
294
|
# Upload new files
|
255
|
-
|
256
|
-
|
257
|
-
|
295
|
+
workers = Array.new(num_threads) do
|
296
|
+
Thread.new do
|
297
|
+
while f = jobs.pop
|
298
|
+
upload_file(f)
|
299
|
+
end
|
300
|
+
end
|
258
301
|
end
|
259
|
-
|
302
|
+
workers.map(&:join)
|
260
303
|
else
|
261
304
|
# Upload new files
|
262
305
|
local_files_to_upload.each do |f|
|
263
|
-
next unless File.file? "#{path}/#{f}" # Only files.
|
264
306
|
upload_file f
|
265
307
|
end
|
266
308
|
end
|
@@ -271,6 +313,8 @@ module AssetSync
|
|
271
313
|
data = cdn.post_invalidation(self.config.cdn_distribution_id, files_to_invalidate)
|
272
314
|
log "Invalidation id: #{data.body["Id"]}"
|
273
315
|
end
|
316
|
+
|
317
|
+
update_remote_file_list_cache(local_files_to_upload)
|
274
318
|
end
|
275
319
|
|
276
320
|
def sync
|
data/lib/asset_sync/version.rb
CHANGED
@@ -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', 'Google', or '
|
8
|
+
class_option :provider, :type => :string, :default => "AWS", :desc => "Generate with support for 'AWS', 'Rackspace', 'Google', 'AzureRM', or 'Backblaze'"
|
9
9
|
|
10
10
|
def self.source_root
|
11
11
|
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
@@ -27,6 +27,10 @@ module AssetSync
|
|
27
27
|
options[:provider] == 'AzureRM'
|
28
28
|
end
|
29
29
|
|
30
|
+
def backblaze?
|
31
|
+
options[:provider] == 'Backblaze'
|
32
|
+
end
|
33
|
+
|
30
34
|
def aws_access_key_id
|
31
35
|
"<%= ENV['AWS_ACCESS_KEY_ID'] %>"
|
32
36
|
end
|
@@ -35,6 +39,10 @@ module AssetSync
|
|
35
39
|
"<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
|
36
40
|
end
|
37
41
|
|
42
|
+
def aws_session_token
|
43
|
+
"<%= ENV['AWS_SESSION_TOKEN'] %>"
|
44
|
+
end
|
45
|
+
|
38
46
|
def google_storage_access_key_id
|
39
47
|
"<%= ENV['GOOGLE_STORAGE_ACCESS_KEY_ID'] %>"
|
40
48
|
end
|
@@ -59,6 +67,18 @@ module AssetSync
|
|
59
67
|
"<%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>"
|
60
68
|
end
|
61
69
|
|
70
|
+
def b2_key_id
|
71
|
+
"<%= ENV['B2_KEY_ID'] %>"
|
72
|
+
end
|
73
|
+
|
74
|
+
def b2_key_token
|
75
|
+
"<%= ENV['B2_KEY_TOKEN'] %>"
|
76
|
+
end
|
77
|
+
|
78
|
+
def b2_bucket_id
|
79
|
+
"<%= ENV['B2_BUCKET_ID'] %>"
|
80
|
+
end
|
81
|
+
|
62
82
|
def app_name
|
63
83
|
@app_name ||= Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "").downcase
|
64
84
|
end
|
@@ -4,6 +4,7 @@ if defined?(AssetSync)
|
|
4
4
|
config.fog_provider = 'AWS'
|
5
5
|
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
6
6
|
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
7
|
+
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.key?('AWS_SESSION_TOKEN')
|
7
8
|
# To use AWS reduced redundancy storage.
|
8
9
|
# config.aws_reduced_redundancy = true
|
9
10
|
#
|
@@ -34,6 +35,12 @@ if defined?(AssetSync)
|
|
34
35
|
config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME']
|
35
36
|
config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY']
|
36
37
|
|
38
|
+
<%- elsif backblaze? -%>
|
39
|
+
config.fog_provider = 'Backblaze'
|
40
|
+
config.b2_key_id = ENV['B2_KEY_ID']
|
41
|
+
config.b2_key_token = ENV['B2_KEY_TOKEN']
|
42
|
+
config.b2_bucket_id = ENV['B2_BUCKET_ID']
|
43
|
+
|
37
44
|
# config.fog_directory specifies container name of Azure Blob storage
|
38
45
|
<%- end -%>
|
39
46
|
config.fog_directory = ENV['FOG_DIRECTORY']
|
@@ -66,6 +73,9 @@ if defined?(AssetSync)
|
|
66
73
|
# Upload files concurrently
|
67
74
|
# config.concurrent_uploads = false
|
68
75
|
#
|
76
|
+
# Path to cache file to skip scanning remote
|
77
|
+
# config.remote_file_list_cache_file_path = './.asset_sync_remote_file_list_cache.json'
|
78
|
+
#
|
69
79
|
# Fail silently. Useful for environments such as Heroku
|
70
80
|
# config.fail_silently = true
|
71
81
|
#
|
@@ -32,8 +32,13 @@ defaults: &defaults
|
|
32
32
|
fog_provider: 'AzureRM'
|
33
33
|
azure_storage_account_name: "<%= azure_storage_account_name %>"
|
34
34
|
azure_storage_access_key: "<%= azure_storage_access_key %>"
|
35
|
-
|
36
35
|
# fog_directory specifies container name of Azure Blob storage
|
36
|
+
<%- elsif backblaze? -%>
|
37
|
+
fog_provider: Backblaze
|
38
|
+
b2_key_id: "<%= b2_key_id %>"
|
39
|
+
b2_key_token: "<%= b2_key_token %>"
|
40
|
+
b2_bucket_id: "<%= b2_bucket_id %>"
|
41
|
+
# fog_directory specifies container name of Backblaze B2 Bucket
|
37
42
|
<%- end -%>
|
38
43
|
fog_directory: "<%= app_name %>-assets"
|
39
44
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: "Backblaze"
|
3
|
+
b2_key_id: 'xxxx'
|
4
|
+
b2_key_token: 'zzzz'
|
5
|
+
b2_bucket_id: '1234'
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *defaults
|
9
|
+
fog_directory: "rails_app_development"
|
10
|
+
existing_remote_files: keep
|
11
|
+
|
12
|
+
test:
|
13
|
+
<<: *defaults
|
14
|
+
fog_directory: "rails_app_test"
|
15
|
+
existing_remote_files: keep
|
16
|
+
|
17
|
+
production:
|
18
|
+
<<: *defaults
|
19
|
+
fog_directory: "rails_app_production"
|
20
|
+
existing_remote_files: delete
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require "fog/backblaze"
|
3
|
+
|
4
|
+
def bucket(name)
|
5
|
+
options = {
|
6
|
+
:provider => 'Backblaze',
|
7
|
+
:b2_key_id => ENV['B2_KEY_ID'],
|
8
|
+
:b2_key_token => ENV['B2_KEY_TOKEN'],
|
9
|
+
:b2_bucket_id => ENV['B2_BUCKET_ID']
|
10
|
+
}
|
11
|
+
options.merge!({ :environment => ENV['FOG_REGION'] }) if ENV.has_key?('FOG_REGION')
|
12
|
+
|
13
|
+
connection = Fog::Storage.new(options)
|
14
|
+
connection.directories.get(ENV['FOG_DIRECTORY'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(command)
|
18
|
+
app_path = File.expand_path("../../dummy_app", __FILE__)
|
19
|
+
Dir.chdir app_path
|
20
|
+
`#{command}`
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "AssetSync" do
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
@prefix = SecureRandom.hex(6)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:app_js_regex){
|
30
|
+
/#{@prefix}\/application-[a-zA-Z0-9]*.js$/
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:app_js_gz_regex){
|
34
|
+
/#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
|
35
|
+
}
|
36
|
+
|
37
|
+
let(:files){ bucket(@prefix).files }
|
38
|
+
|
39
|
+
|
40
|
+
after(:each) do
|
41
|
+
@directory = bucket(@prefix)
|
42
|
+
@directory.files.each do |f|
|
43
|
+
f.destroy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sync" do
|
48
|
+
execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile"
|
49
|
+
|
50
|
+
files = bucket(@prefix).files
|
51
|
+
|
52
|
+
app_js = files.select{ |f| f.key =~ app_js_regex }.first
|
53
|
+
expect(app_js.content_type).to eq("application/javascript")
|
54
|
+
|
55
|
+
app_js_gz = files.select{ |f| f.key =~ app_js_gz_regex }.first
|
56
|
+
expect(app_js_gz.content_type).to eq("application/javascript")
|
57
|
+
expect(app_js_gz.content_encoding).to eq("gzip")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "sync with enabled=false" do
|
61
|
+
execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile"
|
62
|
+
expect(bucket(@prefix).files.size).to eq(0)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "sync with gzip_compression=true" do
|
66
|
+
execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile"
|
67
|
+
# bucket(@prefix).files.size.should == 3
|
68
|
+
|
69
|
+
app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
|
70
|
+
app_js = files.get( app_js_path.key )
|
71
|
+
expect(app_js.content_type).to eq("application/javascript")
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,150 @@
|
|
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 = 'Backblaze'
|
11
|
+
config.b2_key_id = 'aaaa'
|
12
|
+
config.b2_key_token = 'bbbb'
|
13
|
+
config.b2_bucket_id = '4567'
|
14
|
+
config.fog_directory = 'mybucket'
|
15
|
+
config.existing_remote_files = "keep"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should configure provider as Backblaze" do
|
20
|
+
expect(AssetSync.config.fog_provider).to eq('Backblaze')
|
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 b2_key_id" do
|
28
|
+
expect(AssetSync.config.b2_key_id).to eq("aaaa")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should configure b2_key_token" do
|
32
|
+
expect(AssetSync.config.b2_key_token).to eq("bbbb")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should configure b2_bucket_id" do
|
36
|
+
expect(AssetSync.config.b2_bucket_id).to eq("4567")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should configure fog_directory" do
|
40
|
+
expect(AssetSync.config.fog_directory).to eq("mybucket")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should configure existing_remote_files" do
|
44
|
+
expect(AssetSync.config.existing_remote_files).to eq("keep")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should default gzip_compression to false" do
|
48
|
+
expect(AssetSync.config.gzip_compression).to be_falsey
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should default manifest to false" do
|
52
|
+
expect(AssetSync.config.manifest).to be_falsey
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'from yml' do
|
57
|
+
before(:each) do
|
58
|
+
set_rails_root('backblaze_with_yml')
|
59
|
+
AssetSync.config = AssetSync::Config.new
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should configure b2_key_id" do
|
63
|
+
expect(AssetSync.config.b2_key_id).to eq("xxxx")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should configure b2_key_token" do
|
67
|
+
expect(AssetSync.config.b2_key_token).to eq("zzzz")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should configure b2_bucket_id" do
|
71
|
+
expect(AssetSync.config.b2_bucket_id).to eq("1234")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should configure fog_directory" do
|
75
|
+
expect(AssetSync.config.fog_directory).to eq("rails_app_test")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should configure existing_remote_files" do
|
79
|
+
expect(AssetSync.config.existing_remote_files).to eq("keep")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should default gzip_compression to false" do
|
83
|
+
expect(AssetSync.config.gzip_compression).to be_falsey
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should default manifest to false" do
|
87
|
+
expect(AssetSync.config.manifest).to be_falsey
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'with no configuration' do
|
92
|
+
before(:each) do
|
93
|
+
AssetSync.config = AssetSync::Config.new
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be invalid" do
|
97
|
+
expect{ AssetSync.sync }.to raise_error(::AssetSync::Config::Invalid)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'with fail_silent configuration' do
|
102
|
+
before(:each) do
|
103
|
+
allow(AssetSync).to receive(:stderr).and_return(StringIO.new)
|
104
|
+
AssetSync.config = AssetSync::Config.new
|
105
|
+
AssetSync.configure do |config|
|
106
|
+
config.fail_silently = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not raise an invalid exception" do
|
111
|
+
expect{ AssetSync.sync }.not_to raise_error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'with gzip_compression enabled' do
|
116
|
+
before(:each) do
|
117
|
+
AssetSync.config = AssetSync::Config.new
|
118
|
+
AssetSync.config.gzip_compression = true
|
119
|
+
end
|
120
|
+
|
121
|
+
it "config.gzip? should be true" do
|
122
|
+
expect(AssetSync.config.gzip?).to be_truthy
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'with manifest enabled' do
|
127
|
+
before(:each) do
|
128
|
+
AssetSync.config = AssetSync::Config.new
|
129
|
+
AssetSync.config.manifest = true
|
130
|
+
end
|
131
|
+
|
132
|
+
it "config.manifest should be true" do
|
133
|
+
expect(AssetSync.config.manifest).to be_truthy
|
134
|
+
end
|
135
|
+
|
136
|
+
it "config.manifest_path should default to public/assets.." do
|
137
|
+
expect(AssetSync.config.manifest_path).to match(/public\/assets\/manifest.yml/)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "config.manifest_path should default to public/assets.." do
|
141
|
+
Rails.application.config.assets.manifest = "/var/assets"
|
142
|
+
expect(AssetSync.config.manifest_path).to eq("/var/assets/manifest.yml")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "config.manifest_path should default to public/custom_assets.." do
|
146
|
+
Rails.application.config.assets.prefix = 'custom_assets'
|
147
|
+
expect(AssetSync.config.manifest_path).to match(/public\/custom_assets\/manifest.yml/)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/spec/unit/storage_spec.rb
CHANGED
@@ -70,6 +70,71 @@ describe AssetSync::Storage do
|
|
70
70
|
storage.upload_files
|
71
71
|
end
|
72
72
|
|
73
|
+
it 'should allow custom number of threads' do
|
74
|
+
@config.concurrent_uploads = true
|
75
|
+
@config.concurrent_uploads_max_threads = 2
|
76
|
+
storage = AssetSync::Storage.new(@config)
|
77
|
+
|
78
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
79
|
+
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
80
|
+
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
81
|
+
|
82
|
+
expect(Thread).to receive(:new).exactly(2).times.and_call_original
|
83
|
+
(@local_files - @remote_files + storage.always_upload_files).each do |file|
|
84
|
+
expect(storage).to receive(:upload_file).with(file)
|
85
|
+
end
|
86
|
+
|
87
|
+
storage.upload_files
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should allow remote_file_list_cache_file_path configuration' do
|
91
|
+
file_path = './foo.json'
|
92
|
+
@config.remote_file_list_cache_file_path = file_path
|
93
|
+
storage = AssetSync::Storage.new(@config)
|
94
|
+
|
95
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
96
|
+
File.write(file_path, @remote_files.to_json)
|
97
|
+
expect(storage).not_to receive(:get_remote_files)
|
98
|
+
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
99
|
+
|
100
|
+
(@local_files - @remote_files + storage.always_upload_files).each do |file|
|
101
|
+
expect(storage).to receive(:upload_file).with(file)
|
102
|
+
end
|
103
|
+
|
104
|
+
expect(storage).not_to receive(:warn)
|
105
|
+
storage.upload_files
|
106
|
+
|
107
|
+
# update remote_file_list_cache corretly
|
108
|
+
updated = JSON.parse(File.read(file_path))
|
109
|
+
expect(updated.sort.uniq).to eq (@remote_files + @local_files + storage.always_upload_files).sort.uniq
|
110
|
+
|
111
|
+
File.delete(file_path)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should work with broken cache' do
|
115
|
+
file_path = './foo.json'
|
116
|
+
@config.remote_file_list_cache_file_path = file_path
|
117
|
+
|
118
|
+
storage = AssetSync::Storage.new(@config)
|
119
|
+
|
120
|
+
File.write(file_path, 'some non-json text file content')
|
121
|
+
|
122
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
123
|
+
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
124
|
+
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
125
|
+
|
126
|
+
(@local_files - @remote_files + storage.always_upload_files).each do |file|
|
127
|
+
expect(storage).to receive(:upload_file).with(file)
|
128
|
+
end
|
129
|
+
|
130
|
+
# when broken, warning message should be prompted
|
131
|
+
expect(storage).to receive(:warn)
|
132
|
+
|
133
|
+
storage.upload_files
|
134
|
+
|
135
|
+
File.delete(file_path)
|
136
|
+
end
|
137
|
+
|
73
138
|
it 'should upload updated non-fingerprinted files' do
|
74
139
|
@local_files = [
|
75
140
|
'public/image.png',
|
@@ -371,6 +436,7 @@ describe AssetSync::Storage do
|
|
371
436
|
allow(directory).to receive(:files).and_return([file])
|
372
437
|
allow(file).to receive(:key).and_return('public/image.png')
|
373
438
|
allow(connection).to receive(:directories).and_return(directories)
|
439
|
+
allow(config).to receive(:backblaze?).and_return(false)
|
374
440
|
expect(connection).not_to receive(:delete_multiple_objects)
|
375
441
|
expect(file).to receive(:destroy)
|
376
442
|
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Hamilton
|
8
8
|
- David Rice
|
9
9
|
- Phil McClure
|
10
10
|
- Toby Osbourn
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-
|
14
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog-core
|
@@ -153,6 +153,20 @@ dependencies:
|
|
153
153
|
- - ">="
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
|
+
- !ruby/object:Gem::Dependency
|
157
|
+
name: fog-backblaze
|
158
|
+
requirement: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
type: :development
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
156
170
|
- !ruby/object:Gem::Dependency
|
157
171
|
name: uglifier
|
158
172
|
requirement: !ruby/object:Gem::Requirement
|
@@ -223,15 +237,18 @@ files:
|
|
223
237
|
- spec/dummy_app/app/assets/javascripts/application.js
|
224
238
|
- spec/fixtures/aws_with_yml/config/asset_sync.yml
|
225
239
|
- spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
|
240
|
+
- spec/fixtures/backblaze_with_yml/config/asset_sync.yml
|
226
241
|
- spec/fixtures/google_with_service_account_yml/config/asset_sync.yml
|
227
242
|
- spec/fixtures/google_with_yml/config/asset_sync.yml
|
228
243
|
- spec/fixtures/rackspace_with_yml/config/asset_sync.yml
|
229
244
|
- spec/fixtures/with_invalid_yml/config/asset_sync.yml
|
230
245
|
- spec/integration/aws_integration_spec.rb
|
231
246
|
- spec/integration/azure_rm_integration_spec.rb
|
247
|
+
- spec/integration/backblaze_intergration_spec.rb
|
232
248
|
- spec/spec_helper.rb
|
233
249
|
- spec/unit/asset_sync_spec.rb
|
234
250
|
- spec/unit/azure_rm_spec.rb
|
251
|
+
- spec/unit/backblaze_spec.rb
|
235
252
|
- spec/unit/google_spec.rb
|
236
253
|
- spec/unit/multi_mime_spec.rb
|
237
254
|
- spec/unit/rackspace_spec.rb
|
@@ -241,7 +258,7 @@ homepage: https://github.com/rumblelabs/asset_sync
|
|
241
258
|
licenses:
|
242
259
|
- MIT
|
243
260
|
metadata: {}
|
244
|
-
post_install_message:
|
261
|
+
post_install_message:
|
245
262
|
rdoc_options: []
|
246
263
|
require_paths:
|
247
264
|
- lib
|
@@ -256,8 +273,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
273
|
- !ruby/object:Gem::Version
|
257
274
|
version: '0'
|
258
275
|
requirements: []
|
259
|
-
rubygems_version: 3.
|
260
|
-
signing_key:
|
276
|
+
rubygems_version: 3.2.0
|
277
|
+
signing_key:
|
261
278
|
specification_version: 4
|
262
279
|
summary: Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and
|
263
280
|
Rackspace Cloudfiles
|
@@ -266,15 +283,18 @@ test_files:
|
|
266
283
|
- spec/dummy_app/app/assets/javascripts/application.js
|
267
284
|
- spec/fixtures/aws_with_yml/config/asset_sync.yml
|
268
285
|
- spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
|
286
|
+
- spec/fixtures/backblaze_with_yml/config/asset_sync.yml
|
269
287
|
- spec/fixtures/google_with_service_account_yml/config/asset_sync.yml
|
270
288
|
- spec/fixtures/google_with_yml/config/asset_sync.yml
|
271
289
|
- spec/fixtures/rackspace_with_yml/config/asset_sync.yml
|
272
290
|
- spec/fixtures/with_invalid_yml/config/asset_sync.yml
|
273
291
|
- spec/integration/aws_integration_spec.rb
|
274
292
|
- spec/integration/azure_rm_integration_spec.rb
|
293
|
+
- spec/integration/backblaze_intergration_spec.rb
|
275
294
|
- spec/spec_helper.rb
|
276
295
|
- spec/unit/asset_sync_spec.rb
|
277
296
|
- spec/unit/azure_rm_spec.rb
|
297
|
+
- spec/unit/backblaze_spec.rb
|
278
298
|
- spec/unit/google_spec.rb
|
279
299
|
- spec/unit/multi_mime_spec.rb
|
280
300
|
- spec/unit/rackspace_spec.rb
|