asset_sync 2.10.0 → 2.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yaml +64 -0
- data/.travis.yml +4 -9
- data/Appraisals +4 -8
- data/CHANGELOG.md +46 -1
- data/README.md +32 -6
- data/asset_sync.gemspec +1 -0
- data/gemfiles/{rails_5_0.gemfile → rails_6_1.gemfile} +1 -1
- data/lib/asset_sync/config.rb +26 -1
- data/lib/asset_sync/engine.rb +6 -0
- data/lib/asset_sync/storage.rb +40 -4
- 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 +61 -6
- metadata +28 -8
- data/gemfiles/rails_5_1.gemfile +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c593c361046c4faf574342749aced526c101c823c60b7ab8be5e39c7d029efe7
|
4
|
+
data.tar.gz: 63d1361cfa79cfea245eb5cc63bf889cefa239fdf7ba863164414d48e861d444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be760845b518f72bdad531311817b2d449bcaaada2b3ea3feb316af17e6c77fe29c1d7c2b72a46c866ba3b3d94fe0c751fa6a8206936c6d19e935bb0cae93a3
|
7
|
+
data.tar.gz: 1a3bb12b3db320cd566d130eb0abce3a4209c7466324c12dc963822bb0edefb9f04926ece5379a6c74b392cfccc751a5097400ccf922f0ec2dcb9e1b620d43d8
|
@@ -0,0 +1,64 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
paths-ignore:
|
8
|
+
- 'README.md'
|
9
|
+
push:
|
10
|
+
branches:
|
11
|
+
- master
|
12
|
+
paths-ignore:
|
13
|
+
- 'README.md'
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
unit_tests:
|
17
|
+
name: Unit Tests
|
18
|
+
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
|
19
|
+
strategy:
|
20
|
+
fail-fast: false
|
21
|
+
matrix:
|
22
|
+
os:
|
23
|
+
- ubuntu
|
24
|
+
ruby:
|
25
|
+
- 2.5
|
26
|
+
- 2.6
|
27
|
+
- 2.7
|
28
|
+
- 3.0
|
29
|
+
- jruby
|
30
|
+
gemfile:
|
31
|
+
- gemfiles/rails_5_2.gemfile
|
32
|
+
- gemfiles/rails_6_0.gemfile
|
33
|
+
- gemfiles/rails_6_1.gemfile
|
34
|
+
allow_failures:
|
35
|
+
- false
|
36
|
+
include:
|
37
|
+
- os: ubuntu
|
38
|
+
ruby: ruby-head
|
39
|
+
gemfile: gemfiles/rails_6_1.gemfile
|
40
|
+
allow_failures: true
|
41
|
+
- os: ubuntu
|
42
|
+
ruby: jruby-head
|
43
|
+
gemfile: gemfiles/rails_6_1.gemfile
|
44
|
+
allow_failures: true
|
45
|
+
exclude:
|
46
|
+
- os: ubuntu
|
47
|
+
ruby: 3.0
|
48
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
49
|
+
allow_failures: false
|
50
|
+
env:
|
51
|
+
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
52
|
+
ALLOW_FAILURES: "${{ matrix.allow_failures }}"
|
53
|
+
runs-on: ${{ matrix.os }}-latest
|
54
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
55
|
+
steps:
|
56
|
+
- name: Checkout
|
57
|
+
uses: actions/checkout@v2
|
58
|
+
- name: Setup Ruby
|
59
|
+
uses: ruby/setup-ruby@v1
|
60
|
+
with:
|
61
|
+
ruby-version: ${{ matrix.ruby }}
|
62
|
+
bundler-cache: true
|
63
|
+
- name: Test
|
64
|
+
run: bundle exec rake spec:unit || $ALLOW_FAILURES
|
data/.travis.yml
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
3
3
|
sudo: false
|
4
4
|
language: ruby
|
5
|
+
arch:
|
6
|
+
- amd64
|
7
|
+
- ppc64le
|
5
8
|
cache:
|
6
9
|
bundler: true
|
7
10
|
rvm:
|
8
|
-
- 2.3
|
9
|
-
- 2.4
|
10
11
|
- 2.5
|
11
12
|
- 2.6
|
12
13
|
- 2.7
|
@@ -14,10 +15,9 @@ rvm:
|
|
14
15
|
- jruby
|
15
16
|
- jruby-head
|
16
17
|
gemfile:
|
17
|
-
- gemfiles/rails_5_0.gemfile
|
18
|
-
- gemfiles/rails_5_1.gemfile
|
19
18
|
- gemfiles/rails_5_2.gemfile
|
20
19
|
- gemfiles/rails_6_0.gemfile
|
20
|
+
- gemfiles/rails_6_1.gemfile
|
21
21
|
before_install:
|
22
22
|
# Cannot use bundler 2.x due to dependency (mainly rails 4.2)
|
23
23
|
# Solution from https://github.com/rails/rails/blob/4-2-stable/.travis.yml
|
@@ -34,11 +34,6 @@ matrix:
|
|
34
34
|
allow_failures:
|
35
35
|
- rvm: ruby-head
|
36
36
|
- rvm: jruby-head
|
37
|
-
exclude:
|
38
|
-
- rvm: 2.3
|
39
|
-
gemfile: gemfiles/rails_6_0.gemfile
|
40
|
-
- rvm: 2.4
|
41
|
-
gemfile: gemfiles/rails_6_0.gemfile
|
42
37
|
notifications:
|
43
38
|
webhooks:
|
44
39
|
urls:
|
data/Appraisals
CHANGED
@@ -1,12 +1,4 @@
|
|
1
1
|
|
2
|
-
appraise "rails_5_0" do
|
3
|
-
gem "rails", "~> 5.0.0"
|
4
|
-
end
|
5
|
-
|
6
|
-
appraise "rails_5_1" do
|
7
|
-
gem "rails", "~> 5.1.0"
|
8
|
-
end
|
9
|
-
|
10
2
|
appraise "rails_5_2" do
|
11
3
|
gem "rails", "~> 5.2.0"
|
12
4
|
end
|
@@ -14,3 +6,7 @@ end
|
|
14
6
|
appraise "rails_6_0" do
|
15
7
|
gem "rails", "~> 6.0.0"
|
16
8
|
end
|
9
|
+
|
10
|
+
appraise "rails_6_1" do
|
11
|
+
gem "rails", "~> 6.1.0"
|
12
|
+
end
|
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.1] - 2021-03-01
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
|
25
|
+
- Fix "files to be uploaded list" generation for file names with dashes
|
26
|
+
(https://github.com/AssetSync/asset_sync/pull/414)
|
27
|
+
|
28
|
+
|
29
|
+
## [2.13.0] - 2020-12-14
|
30
|
+
|
31
|
+
### Added
|
32
|
+
|
33
|
+
- Add Backblaze B2 Cloud Storage support
|
34
|
+
(https://github.com/AssetSync/asset_sync/pull/410)
|
35
|
+
|
36
|
+
|
37
|
+
## [2.12.1] - 2020-06-17
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
|
41
|
+
- Fix initializer template in generator
|
42
|
+
(https://github.com/AssetSync/asset_sync/pull/404)
|
43
|
+
|
44
|
+
|
45
|
+
## [2.12.0] - 2020-06-11
|
46
|
+
|
47
|
+
### Added
|
48
|
+
|
49
|
+
- Add option `aws_session_token` to support AWS Temporary Security Credentials
|
50
|
+
(https://github.com/AssetSync/asset_sync/pull/403)
|
51
|
+
|
52
|
+
|
53
|
+
## [2.11.0] - 2020-03-13
|
54
|
+
|
55
|
+
### Added
|
56
|
+
|
57
|
+
- Add option `remote_file_list_cache_file_path` to skip scanning remote
|
58
|
+
(https://github.com/AssetSync/asset_sync/pull/400)
|
59
|
+
|
60
|
+
|
21
61
|
## [2.10.0] - 2020-02-26
|
22
62
|
|
23
63
|
### Added
|
@@ -954,7 +994,12 @@ Changes:
|
|
954
994
|
* Merge branch 'sinatra'
|
955
995
|
|
956
996
|
|
957
|
-
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.
|
997
|
+
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.13.1...HEAD
|
998
|
+
[2.13.1]: https://github.com/AssetSync/asset_sync/compare/v2.13.0...v2.13.1
|
999
|
+
[2.13.0]: https://github.com/AssetSync/asset_sync/compare/v2.12.1...v2.13.0
|
1000
|
+
[2.12.1]: https://github.com/AssetSync/asset_sync/compare/v2.12.0...v2.12.1
|
1001
|
+
[2.12.0]: https://github.com/AssetSync/asset_sync/compare/v2.11.0...v2.12.0
|
1002
|
+
[2.11.0]: https://github.com/AssetSync/asset_sync/compare/v2.10.0...v2.11.0
|
958
1003
|
[2.10.0]: https://github.com/AssetSync/asset_sync/compare/v2.9.1...v2.10.0
|
959
1004
|
[2.9.1]: https://github.com/AssetSync/asset_sync/compare/v2.9.0...v2.9.1
|
960
1005
|
[2.9.0]: https://github.com/AssetSync/asset_sync/compare/v2.8.2...v2.9.0
|
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'
|
@@ -244,10 +260,13 @@ AssetSync.configure do |config|
|
|
244
260
|
#
|
245
261
|
# Upload files concurrently
|
246
262
|
# config.concurrent_uploads = false
|
247
|
-
#
|
263
|
+
#
|
248
264
|
# Number of threads when concurrent_uploads is enabled
|
249
265
|
# config.concurrent_uploads_max_threads = 10
|
250
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
|
+
#
|
251
270
|
# Fail silently. Useful for environments such as Heroku
|
252
271
|
# config.fail_silently = true
|
253
272
|
#
|
@@ -270,6 +289,7 @@ Run the included Rake task to generate a starting point.
|
|
270
289
|
rails g asset_sync:install --use-yml --provider=Rackspace
|
271
290
|
rails g asset_sync:install --use-yml --provider=AWS
|
272
291
|
rails g asset_sync:install --use-yml --provider=AzureRM
|
292
|
+
rails g asset_sync:install --use-yml --provider=Backblaze
|
273
293
|
|
274
294
|
The generator will create a YAML file at `config/asset_sync.yml`.
|
275
295
|
|
@@ -346,6 +366,7 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
|
|
346
366
|
* **include_manifest**: (`true, false`) when enabled, will upload the `manifest.yml` generated by Rails. **default:** `'false'`
|
347
367
|
* **concurrent_uploads**: (`true, false`) when enabled, will upload the files in different Threads, this greatly improves the upload speed. **default:** `'false'`
|
348
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`
|
349
370
|
* **enabled**: (`true, false`) when false, will disable asset sync. **default:** `'true'` (enabled)
|
350
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**: `[]`
|
351
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**: `[]`
|
@@ -378,7 +399,7 @@ To customize the overrides:
|
|
378
399
|
AssetSync.configure do |config|
|
379
400
|
# Clear the default overrides
|
380
401
|
config.file_ext_to_mime_type_overrides.clear
|
381
|
-
|
402
|
+
|
382
403
|
# Add/Edit overrides
|
383
404
|
# Will call `#to_s` for inputs
|
384
405
|
config.file_ext_to_mime_type_overrides.add(:js, :"application/x-javascript")
|
@@ -387,7 +408,7 @@ end
|
|
387
408
|
The blocks are run when local files are being scanned and uploaded
|
388
409
|
|
389
410
|
#### Fog (Required)
|
390
|
-
* **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)
|
391
412
|
* **fog\_directory**: your bucket name
|
392
413
|
|
393
414
|
#### Fog (Optional)
|
@@ -421,6 +442,11 @@ When using the S3 API
|
|
421
442
|
* **azure\_storage\_account\_name**: your Azure Blob access key
|
422
443
|
* **azure\_storage\_access\_key**: your Azure Blob access secret
|
423
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
|
+
|
424
450
|
#### Rackspace (Optional)
|
425
451
|
|
426
452
|
* **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: `https://lon.identity.api.rackspacecloud.com/v2.0`
|
@@ -546,7 +572,7 @@ AssetSync.configure do |config|
|
|
546
572
|
config.prefix = 'assets'
|
547
573
|
# Can be a `Pathname` or `String`
|
548
574
|
# Will be converted into an `Pathname`
|
549
|
-
# If relative, will be converted into an absolute path
|
575
|
+
# If relative, will be converted into an absolute path
|
550
576
|
# via `::Rails.root` or `::Dir.pwd`
|
551
577
|
config.public_path = Pathname('./public')
|
552
578
|
end
|
@@ -617,7 +643,7 @@ Make sure you have a .env file with these details:-
|
|
617
643
|
AWS_SECRET_ACCESS_KEY=<yoursecretkey>
|
618
644
|
FOG_DIRECTORY=<yourbucket>
|
619
645
|
FOG_REGION=<youbucketregion>
|
620
|
-
|
646
|
+
|
621
647
|
# for AzureRM provider
|
622
648
|
AZURE_STORAGE_ACCOUNT_NAME=<youraccountname>
|
623
649
|
AZURE_STORAGE_ACCESS_KEY=<youraccesskey>
|
data/asset_sync.gemspec
CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "rcov", platforms: :mri_18, group: [:development, :test]
|
6
6
|
gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
|
7
7
|
gem "jruby-openssl", platform: :jruby
|
8
|
-
gem "rails", "~>
|
8
|
+
gem "rails", "~> 6.1.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
data/lib/asset_sync/config.rb
CHANGED
@@ -28,6 +28,7 @@ module AssetSync
|
|
28
28
|
attr_accessor :include_manifest
|
29
29
|
attr_accessor :concurrent_uploads
|
30
30
|
attr_accessor :concurrent_uploads_max_threads
|
31
|
+
attr_accessor :remote_file_list_cache_file_path
|
31
32
|
|
32
33
|
# FOG configuration
|
33
34
|
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
|
@@ -36,7 +37,7 @@ module AssetSync
|
|
36
37
|
attr_reader :fog_public # e.g. true, false, "default"
|
37
38
|
|
38
39
|
# Amazon AWS
|
39
|
-
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
|
40
41
|
attr_accessor :fog_host # e.g. 's3.amazonaws.com'
|
41
42
|
attr_accessor :fog_port # e.g. '9000'
|
42
43
|
attr_accessor :fog_path_style # e.g. true
|
@@ -54,6 +55,11 @@ module AssetSync
|
|
54
55
|
attr_accessor :azure_storage_account_name
|
55
56
|
attr_accessor :azure_storage_access_key
|
56
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
|
+
|
57
63
|
validates :existing_remote_files, :inclusion => { :in => %w(keep delete ignore) }
|
58
64
|
|
59
65
|
validates :fog_provider, :presence => true
|
@@ -88,6 +94,7 @@ module AssetSync
|
|
88
94
|
self.include_manifest = false
|
89
95
|
self.concurrent_uploads = false
|
90
96
|
self.concurrent_uploads_max_threads = 10
|
97
|
+
self.remote_file_list_cache_file_path = nil
|
91
98
|
@additional_local_file_paths_procs = []
|
92
99
|
|
93
100
|
load_yml! if defined?(::Rails) && yml_exists?
|
@@ -151,6 +158,10 @@ module AssetSync
|
|
151
158
|
fog_provider =~ /azurerm/i
|
152
159
|
end
|
153
160
|
|
161
|
+
def backblaze?
|
162
|
+
fog_provider =~ /backblaze/i
|
163
|
+
end
|
164
|
+
|
154
165
|
def cache_asset_regexp=(cache_asset_regexp)
|
155
166
|
self.cache_asset_regexps = [cache_asset_regexp]
|
156
167
|
end
|
@@ -201,6 +212,7 @@ module AssetSync
|
|
201
212
|
self.fog_scheme = yml["fog_scheme"]
|
202
213
|
self.aws_access_key_id = yml["aws_access_key_id"]
|
203
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")
|
204
216
|
self.aws_reduced_redundancy = yml["aws_reduced_redundancy"]
|
205
217
|
self.aws_iam_roles = yml["aws_iam_roles"]
|
206
218
|
self.aws_signature_version = yml["aws_signature_version"]
|
@@ -225,10 +237,15 @@ module AssetSync
|
|
225
237
|
self.include_manifest = yml['include_manifest'] if yml.has_key?("include_manifest")
|
226
238
|
self.concurrent_uploads = yml['concurrent_uploads'] if yml.has_key?('concurrent_uploads')
|
227
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')
|
228
241
|
|
229
242
|
self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
|
230
243
|
self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")
|
231
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
|
+
|
232
249
|
# TODO deprecate the other old style config settings. FML.
|
233
250
|
self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
|
234
251
|
self.aws_secret_access_key = yml["aws_access_secret"] if yml.has_key?("aws_access_secret")
|
@@ -257,6 +274,7 @@ module AssetSync
|
|
257
274
|
:aws_access_key_id => aws_access_key_id,
|
258
275
|
:aws_secret_access_key => aws_secret_access_key
|
259
276
|
})
|
277
|
+
options.merge!({:aws_session_token => aws_session_token}) if aws_session_token
|
260
278
|
end
|
261
279
|
options.merge!({:host => fog_host}) if fog_host
|
262
280
|
options.merge!({:port => fog_port}) if fog_port
|
@@ -288,6 +306,13 @@ module AssetSync
|
|
288
306
|
:azure_storage_access_key => azure_storage_access_key,
|
289
307
|
})
|
290
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
|
+
})
|
291
316
|
else
|
292
317
|
raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
|
293
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
@@ -4,7 +4,7 @@ require "asset_sync/multi_mime"
|
|
4
4
|
|
5
5
|
module AssetSync
|
6
6
|
class Storage
|
7
|
-
REGEXP_FINGERPRINTED_FILES =
|
7
|
+
REGEXP_FINGERPRINTED_FILES = /\A(.*)\/(.+)-[^\.]+\.([^\.]+)\z/m
|
8
8
|
REGEXP_ASSETS_TO_CACHE_CONTROL = /-[0-9a-fA-F]{32,}$/
|
9
9
|
|
10
10
|
class BucketNotFound < StandardError;
|
@@ -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,8 +279,6 @@ 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
|
@@ -279,6 +313,8 @@ module AssetSync
|
|
279
313
|
data = cdn.post_invalidation(self.config.cdn_distribution_id, files_to_invalidate)
|
280
314
|
log "Invalidation id: #{data.body["Id"]}"
|
281
315
|
end
|
316
|
+
|
317
|
+
update_remote_file_list_cache(local_files_to_upload)
|
282
318
|
end
|
283
319
|
|
284
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
@@ -87,19 +87,72 @@ describe AssetSync::Storage do
|
|
87
87
|
storage.upload_files
|
88
88
|
end
|
89
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
|
+
|
90
138
|
it 'should upload updated non-fingerprinted files' do
|
91
139
|
@local_files = [
|
92
|
-
'public/image.png',
|
93
|
-
'public/image-82389298328.png',
|
94
|
-
'public/image-a8389f9h324.png',
|
140
|
+
'public/great-image.png',
|
141
|
+
'public/great-image-82389298328.png',
|
142
|
+
'public/great-image-a8389f9h324.png',
|
143
|
+
"public/new\nline.js",
|
144
|
+
"public/new\nline-aaaaaaaaaaa.js",
|
145
|
+
"public/new\nline-bbbbbbbbbbb.js",
|
95
146
|
'public/application.js',
|
96
147
|
'public/application-b3389d983k1.js',
|
97
148
|
'public/application-ac387d53f31.js',
|
98
149
|
'public',
|
99
150
|
]
|
100
151
|
@remote_files = [
|
101
|
-
'public/image.png',
|
102
|
-
'public/image-a8389f9h324.png',
|
152
|
+
'public/great-image.png',
|
153
|
+
'public/great-image-a8389f9h324.png',
|
154
|
+
"public/new\nline.js",
|
155
|
+
"public/new\nline-aaaaaaaaaaa.js",
|
103
156
|
'public/application.js',
|
104
157
|
'public/application-b3389d983k1.js',
|
105
158
|
]
|
@@ -110,7 +163,8 @@ describe AssetSync::Storage do
|
|
110
163
|
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
111
164
|
|
112
165
|
updated_nonfingerprinted_files = [
|
113
|
-
'public/image.png',
|
166
|
+
'public/great-image.png',
|
167
|
+
"public/new\nline.js",
|
114
168
|
'public/application.js',
|
115
169
|
]
|
116
170
|
(@local_files - @remote_files + updated_nonfingerprinted_files).each do |file|
|
@@ -388,6 +442,7 @@ describe AssetSync::Storage do
|
|
388
442
|
allow(directory).to receive(:files).and_return([file])
|
389
443
|
allow(file).to receive(:key).and_return('public/image.png')
|
390
444
|
allow(connection).to receive(:directories).and_return(directories)
|
445
|
+
allow(config).to receive(:backblaze?).and_return(false)
|
391
446
|
expect(connection).not_to receive(:delete_multiple_objects)
|
392
447
|
expect(file).to receive(:destroy)
|
393
448
|
|
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.1
|
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:
|
14
|
+
date: 2021-03-01 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
|
@@ -193,6 +207,7 @@ extensions: []
|
|
193
207
|
extra_rdoc_files: []
|
194
208
|
files:
|
195
209
|
- ".editorconfig"
|
210
|
+
- ".github/workflows/tests.yaml"
|
196
211
|
- ".gitignore"
|
197
212
|
- ".travis.yml"
|
198
213
|
- Appraisals
|
@@ -203,10 +218,9 @@ files:
|
|
203
218
|
- UPGRADING.md
|
204
219
|
- asset_sync.gemspec
|
205
220
|
- docs/heroku.md
|
206
|
-
- gemfiles/rails_5_0.gemfile
|
207
|
-
- gemfiles/rails_5_1.gemfile
|
208
221
|
- gemfiles/rails_5_2.gemfile
|
209
222
|
- gemfiles/rails_6_0.gemfile
|
223
|
+
- gemfiles/rails_6_1.gemfile
|
210
224
|
- lib/asset_sync.rb
|
211
225
|
- lib/asset_sync/asset_sync.rb
|
212
226
|
- lib/asset_sync/config.rb
|
@@ -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.11
|
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
|
data/gemfiles/rails_5_1.gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rcov", platforms: :mri_18, group: [:development, :test]
|
6
|
-
gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
|
7
|
-
gem "jruby-openssl", platform: :jruby
|
8
|
-
gem "rails", "~> 5.1.0"
|
9
|
-
|
10
|
-
gemspec path: "../"
|