asset_sync 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -3
- data/lib/asset_sync/config.rb +8 -0
- data/lib/asset_sync/storage.rb +29 -7
- data/lib/asset_sync/version.rb +1 -1
- data/lib/generators/asset_sync/templates/asset_sync.rb +2 -0
- data/spec/asset_sync_spec.rb +34 -1
- metadata +11 -11
data/README.md
CHANGED
@@ -87,8 +87,13 @@ The generator will create a Rails initializer at `config/initializers/asset_sync
|
|
87
87
|
config.aws_access_key = ENV['AWS_ACCESS_KEY']
|
88
88
|
config.aws_access_secret = ENV['AWS_ACCESS_SECRET']
|
89
89
|
config.aws_bucket = ENV['AWS_BUCKET']
|
90
|
-
# config.aws_region = 'eu-west-1'
|
91
90
|
config.existing_remote_files = "keep"
|
91
|
+
# Increase upload performance by configuring your region
|
92
|
+
# config.aws_region = "eu-west-1"
|
93
|
+
# Automatically replace files with their equivalent gzip compressed version
|
94
|
+
# config.gzip_compression = true
|
95
|
+
# Use the Rails generated 'manifest.yml' file to produce the list of files to upload instead of searching the assets directory.
|
96
|
+
# config.manifest = true
|
92
97
|
end
|
93
98
|
|
94
99
|
|
@@ -101,6 +106,10 @@ If you used the `--use-yml` flag, the generator will create a YAML file at `conf
|
|
101
106
|
aws_access_secret: "<%= ENV['AWS_ACCESS_SECRET'] %>"
|
102
107
|
# You may need to specify what region your S3 bucket is in
|
103
108
|
# aws_region: "eu-west-1"
|
109
|
+
existing_remote_files: keep
|
110
|
+
# Automatically replace files with their equivalent gzip compressed version
|
111
|
+
# gzip_compression = true
|
112
|
+
|
104
113
|
|
105
114
|
development:
|
106
115
|
<<: *defaults
|
@@ -110,12 +119,16 @@ If you used the `--use-yml` flag, the generator will create a YAML file at `conf
|
|
110
119
|
test:
|
111
120
|
<<: *defaults
|
112
121
|
aws_bucket: "rails-app-test"
|
113
|
-
|
122
|
+
|
123
|
+
staging:
|
124
|
+
<<: *defaults
|
125
|
+
aws_bucket: "rails-app-staging"
|
114
126
|
|
115
127
|
production:
|
116
128
|
<<: *defaults
|
117
129
|
aws_bucket: "rails-app-production"
|
118
|
-
|
130
|
+
# Existing pre-compiled assets on S3 will be deleted
|
131
|
+
# existing_remote_files: delete
|
119
132
|
|
120
133
|
### Environment Variables
|
121
134
|
|
@@ -138,6 +151,7 @@ Or add to a traditional unix system
|
|
138
151
|
* **aws\_region**: the region your S3 bucket is in e.g. *eu-west-1*
|
139
152
|
* **existing\_remote\_files**: what to do with previously precompiled files, options are **keep** or **delete**
|
140
153
|
* **gzip\_compression**: when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version.
|
154
|
+
* **manifest**: when enabled, will use the `manifest.yml` generated by Rails to get the list of local files to upload. **experimental**
|
141
155
|
|
142
156
|
## Automatic gzip compression
|
143
157
|
|
data/lib/asset_sync/config.rb
CHANGED
@@ -10,6 +10,7 @@ module AssetSync
|
|
10
10
|
attr_accessor :aws_region
|
11
11
|
attr_accessor :existing_remote_files
|
12
12
|
attr_accessor :gzip_compression
|
13
|
+
attr_accessor :manifest
|
13
14
|
|
14
15
|
validates :aws_access_key, :presence => true
|
15
16
|
validates :aws_access_secret, :presence => true
|
@@ -21,9 +22,15 @@ module AssetSync
|
|
21
22
|
self.aws_region = nil
|
22
23
|
self.existing_remote_files = 'keep'
|
23
24
|
self.gzip_compression = false
|
25
|
+
self.manifest = false
|
24
26
|
load_yml! if yml_exists?
|
25
27
|
end
|
26
28
|
|
29
|
+
def manifest_path
|
30
|
+
default = File.join(Rails.root, 'public', 'assets', 'manifest.yml')
|
31
|
+
Rails.application.config.assets.manifest || default
|
32
|
+
end
|
33
|
+
|
27
34
|
def gzip?
|
28
35
|
self.gzip_compression
|
29
36
|
end
|
@@ -52,6 +59,7 @@ module AssetSync
|
|
52
59
|
self.aws_region = yml["aws_region"] if yml.has_key?("aws_region")
|
53
60
|
self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files")
|
54
61
|
self.gzip_compression = yml["gzip_compression"] if yml.has_key?("gzip_compression")
|
62
|
+
self.manifest = yml["manifest"] if yml.has_key?("manifest")
|
55
63
|
|
56
64
|
# TODO deprecate old style config settings
|
57
65
|
self.aws_access_key = yml["access_key_id"] if yml.has_key?("access_key_id")
|
data/lib/asset_sync/storage.rb
CHANGED
@@ -14,7 +14,8 @@ module AssetSync
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def bucket
|
17
|
-
|
17
|
+
# fixes: https://github.com/rumblelabs/asset_sync/issues/18
|
18
|
+
@bucket ||= connection.directories.get(self.config.aws_bucket, :prefix => 'assets')
|
18
19
|
end
|
19
20
|
|
20
21
|
def keep_existing_remote_files?
|
@@ -26,12 +27,30 @@ module AssetSync
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def local_files
|
29
|
-
|
30
|
+
@local_files ||= get_local_files
|
30
31
|
end
|
31
32
|
|
33
|
+
def get_local_files
|
34
|
+
if self.config.manifest
|
35
|
+
if File.exists?(self.config.manifest_path)
|
36
|
+
yml = YAML.load(IO.read(self.config.manifest_path))
|
37
|
+
STDERR.puts "Using: Manifest #{self.config.manifest_path}"
|
38
|
+
return yml.values.map { |f| File.join('assets', f) }
|
39
|
+
else
|
40
|
+
STDERR.puts "Warning: manifest.yml not found at #{self.config.manifest_path}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
STDERR.puts "Using: Directory Search of #{path}/assets"
|
44
|
+
Dir["#{path}/assets/**/**"].map { |f| f[path.length+1,f.length-path.length] }
|
45
|
+
end
|
46
|
+
|
32
47
|
def get_remote_files
|
33
48
|
raise BucketNotFound.new("AWS Bucket: #{self.config.aws_bucket} not found.") unless bucket
|
34
|
-
|
49
|
+
# fixes: https://github.com/rumblelabs/asset_sync/issues/16
|
50
|
+
# (work-around for https://github.com/fog/fog/issues/596)
|
51
|
+
files = []
|
52
|
+
bucket.files.each { |f| files << f.key }
|
53
|
+
return files
|
35
54
|
end
|
36
55
|
|
37
56
|
def delete_file(f, remote_files_to_delete)
|
@@ -44,7 +63,8 @@ module AssetSync
|
|
44
63
|
def delete_extra_remote_files
|
45
64
|
STDERR.puts "Fetching files to flag for delete"
|
46
65
|
remote_files = get_remote_files
|
47
|
-
|
66
|
+
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
|
67
|
+
from_remote_files_to_delete = remote_files - local_files
|
48
68
|
|
49
69
|
STDERR.puts "Flagging #{from_remote_files_to_delete.size} file(s) for deletion"
|
50
70
|
# Delete unneeded remote files
|
@@ -99,7 +119,8 @@ module AssetSync
|
|
99
119
|
def upload_files
|
100
120
|
# get a fresh list of remote files
|
101
121
|
remote_files = get_remote_files
|
102
|
-
|
122
|
+
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
|
123
|
+
local_files_to_upload = local_files - remote_files
|
103
124
|
|
104
125
|
# Upload new files
|
105
126
|
local_files_to_upload.each do |f|
|
@@ -109,10 +130,11 @@ module AssetSync
|
|
109
130
|
end
|
110
131
|
|
111
132
|
def sync
|
112
|
-
|
133
|
+
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
|
113
134
|
upload_files
|
135
|
+
delete_extra_remote_files unless keep_existing_remote_files?
|
114
136
|
STDERR.puts "Done."
|
115
137
|
end
|
116
138
|
|
117
139
|
end
|
118
|
-
end
|
140
|
+
end
|
data/lib/asset_sync/version.rb
CHANGED
@@ -7,4 +7,6 @@ AssetSync.configure do |config|
|
|
7
7
|
# config.aws_region = "eu-west-1"
|
8
8
|
# Automatically replace files with their equivalent gzip compressed version
|
9
9
|
# config.gzip_compression = true
|
10
|
+
# Use the Rails generated 'manifest.yml' file to produce the list of files to upload instead of searching the assets directory.
|
11
|
+
# config.manifest = true
|
10
12
|
end
|
data/spec/asset_sync_spec.rb
CHANGED
@@ -43,6 +43,10 @@ describe AssetSync, 'with initializer' do
|
|
43
43
|
AssetSync.config.gzip_compression.should be_false
|
44
44
|
end
|
45
45
|
|
46
|
+
it "should default manifest to false" do
|
47
|
+
AssetSync.config.manifest.should be_false
|
48
|
+
end
|
49
|
+
|
46
50
|
end
|
47
51
|
|
48
52
|
|
@@ -77,6 +81,10 @@ describe AssetSync, 'from yml' do
|
|
77
81
|
AssetSync.config.gzip_compression.should be_false
|
78
82
|
end
|
79
83
|
|
84
|
+
it "should default manifest to false" do
|
85
|
+
AssetSync.config.manifest.should be_false
|
86
|
+
end
|
87
|
+
|
80
88
|
end
|
81
89
|
|
82
90
|
describe AssetSync, 'with no configuration' do
|
@@ -104,4 +112,29 @@ describe AssetSync, 'with gzip_compression enabled' do
|
|
104
112
|
AssetSync.config.gzip?.should be_true
|
105
113
|
end
|
106
114
|
|
107
|
-
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe AssetSync, 'with manifest enabled' do
|
118
|
+
|
119
|
+
before(:all) do
|
120
|
+
Rails.root = 'without_yml'
|
121
|
+
AssetSync.config = AssetSync::Config.new
|
122
|
+
AssetSync.config.manifest = true
|
123
|
+
end
|
124
|
+
|
125
|
+
it "config.manifest should be true" do
|
126
|
+
AssetSync.config.manifest.should be_true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "config.manifest_path should default to public/assets.." do
|
130
|
+
pending
|
131
|
+
AssetSync.config.manifest_path.should =~ "public/assets/manifest.yml"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "config.manifest_path should default to public/assets.." do
|
135
|
+
pending
|
136
|
+
Rails.app.config.assets.manifest = "/var/assets/manifest.yml"
|
137
|
+
AssetSync.config.manifest_path.should == "/var/assets/manifest.yml"
|
138
|
+
end
|
139
|
+
|
140
|
+
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: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-11-05 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fog
|
17
|
-
requirement: &
|
17
|
+
requirement: &70137703451140 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70137703451140
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activemodel
|
28
|
-
requirement: &
|
28
|
+
requirement: &70137703450520 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70137703450520
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70137703449900 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70137703449900
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
|
-
requirement: &
|
50
|
+
requirement: &70137703449240 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70137703449240
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: jeweler
|
61
|
-
requirement: &
|
61
|
+
requirement: &70137703448620 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70137703448620
|
70
70
|
description: After you run assets:precompile your assets will be synchronised with
|
71
71
|
your S3 bucket, deleting unused files and only uploading the files it needs to.
|
72
72
|
email:
|