asset_sync 0.2.12 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +135 -55
- data/asset_sync.gemspec +1 -1
- data/lib/asset_sync/engine.rb +3 -1
- data/lib/asset_sync/version.rb +1 -1
- metadata +12 -12
data/README.md
CHANGED
@@ -30,45 +30,107 @@ Add the gem to your Gemfile
|
|
30
30
|
gem "asset_sync"
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
If you want, you can put it within your **:assets** group in your Gemfile.
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
``` ruby
|
36
|
+
group :assets do
|
37
|
+
gem 'sass-rails', '~> 3.2.3'
|
38
|
+
gem 'coffee-rails', '~> 3.2.1'
|
39
|
+
gem 'uglifier', '>= 1.0.3'
|
40
|
+
gem "asset_sync"
|
41
|
+
end
|
42
|
+
```
|
42
43
|
|
43
|
-
|
44
|
+
This is good practice when pre-compiling your assets as it will reduce load time and server memory in production. The only caveat being, you may not be able to use a custom initializer, without perhaps wrapping it with.
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
``` ruby
|
47
|
+
defined?(AssetSync) do
|
48
|
+
...
|
49
|
+
end
|
50
|
+
```
|
47
51
|
|
48
52
|
## Configuration
|
49
53
|
|
54
|
+
### Rails
|
55
|
+
|
50
56
|
Configure __config/environments/production.rb__ to use Amazon
|
51
57
|
S3 as the asset host and ensure precompiling is enabled.
|
52
58
|
|
59
|
+
|
53
60
|
``` ruby
|
54
|
-
#
|
55
|
-
config.action_controller.asset_host = Proc.new do |source, request|
|
56
|
-
|
61
|
+
#config/environments/production.rb
|
62
|
+
config.action_controller.asset_host = Proc.new do |source, request|
|
63
|
+
request.ssl? ? "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com" : "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
|
57
64
|
end
|
58
65
|
```
|
59
66
|
|
60
|
-
|
67
|
+
Also, ensure the following are defined (in production.rb or application.rb)
|
68
|
+
|
69
|
+
* **config.assets.digest** is set to **true**.
|
70
|
+
* **config.assets.enabled** is set to **true**.
|
61
71
|
|
72
|
+
### AssetSync
|
73
|
+
|
74
|
+
**AssetSync** supports the following methods of configuration.
|
75
|
+
|
76
|
+
* [Built-in Initializer](/rumblelabs/asset_sync/blob/master/lib/asset_sync/engine.rb) (configured through environment variables)
|
62
77
|
* Rails Initializer
|
63
78
|
* A YAML config file
|
64
79
|
|
65
|
-
Using an **Initializer** is the default method and is best used with **environment** variables. It's the recommended approach for deployments on Heroku.
|
66
80
|
|
67
|
-
Using
|
81
|
+
Using the **Built-in Initializer** is the default method and is supposed to be used with **environment** variables. It's the recommended approach for deployments on Heroku.
|
82
|
+
|
83
|
+
If you need more control over configuration you will want to use a **custom rails initializer**.
|
84
|
+
|
85
|
+
Configuration using a **YAML** file (a common strategy for Capistrano deployments) is also suppored.
|
86
|
+
|
87
|
+
The recommend way to configure **asset_sync** is by using **environment variables** however it's up to you, it will work fine if you hard code them too. The main reason is that then your access keys are not checked into version control.
|
88
|
+
|
89
|
+
### Built-in Initializer (Environment Variables)
|
90
|
+
|
91
|
+
The Built-in Initializer will configure **AssetSync** based on the contents of your environment variables.
|
92
|
+
|
93
|
+
Add your configuration details to **heroku**
|
94
|
+
|
95
|
+
``` bash
|
96
|
+
heroku config:add AWS_ACCESS_KEY_ID=xxxx
|
97
|
+
heroku config:add AWS_SECRET_ACCESS_KEY=xxxx
|
98
|
+
heroku config:add FOG_DIRECTORY=xxxx
|
99
|
+
heroku config:add FOG_PROVIDER=AWS
|
100
|
+
# and optionally:
|
101
|
+
heroku config:add FOG_REGION=eu-west-1
|
102
|
+
heroku config:add ASSET_SYNC_GZIP_COMPRESSION=true
|
103
|
+
heroku config:add ASSET_SYNC_MANIFEST=true
|
104
|
+
heroku config:add ASSET_SYNC_EXISTING_REMOTE_FILES=keep
|
105
|
+
```
|
106
|
+
|
107
|
+
Or add to a traditional unix system
|
108
|
+
|
109
|
+
``` bash
|
110
|
+
export AWS_ACCESS_KEY_ID=xxxx
|
111
|
+
export AWS_SECRET_ACCESS_KEY=xxxx
|
112
|
+
export FOG_DIRECTORY=xxxx
|
113
|
+
```
|
114
|
+
|
115
|
+
Rackspace configuration is also supported
|
116
|
+
|
117
|
+
``` bash
|
118
|
+
heroku config:add RACKSPACE_USERNAME=xxxx
|
119
|
+
heroku config:add RACKSPACE_API_KEY=xxxx
|
120
|
+
heroku config:add FOG_DIRECTORY=xxxx
|
121
|
+
heroku config:add FOG_PROVIDER=Rackspace
|
122
|
+
```
|
123
|
+
|
124
|
+
The Built-in Initializer also sets the AssetSync default for **existing_remote_files** to **keep**.
|
68
125
|
|
69
|
-
|
126
|
+
### Custom Rails Initializer (config/initializers/asset_sync.rb)
|
70
127
|
|
71
|
-
|
128
|
+
If you want to enable some of the advanced configuration options you will want to create your own initializer.
|
129
|
+
|
130
|
+
Run the included Rake task to generate a starting point.
|
131
|
+
|
132
|
+
rails g asset_sync:install --provider=Rackspace
|
133
|
+
rails g asset_sync:install --provider=AWS
|
72
134
|
|
73
135
|
The generator will create a Rails initializer at `config/initializers/asset_sync.rb`.
|
74
136
|
|
@@ -97,10 +159,14 @@ AssetSync.configure do |config|
|
|
97
159
|
end
|
98
160
|
```
|
99
161
|
|
100
|
-
|
101
162
|
### YAML (config/asset_sync.yml)
|
102
163
|
|
103
|
-
|
164
|
+
Run the included Rake task to generate a starting point.
|
165
|
+
|
166
|
+
rails g asset_sync:install --use-yml --provider=Rackspace
|
167
|
+
rails g asset_sync:install --use-yml --provider=AWS
|
168
|
+
|
169
|
+
The generator will create a YAML file at `config/asset_sync.yml`.
|
104
170
|
|
105
171
|
``` yaml
|
106
172
|
defaults: &defaults
|
@@ -128,35 +194,31 @@ production:
|
|
128
194
|
<<: *defaults
|
129
195
|
```
|
130
196
|
|
131
|
-
###
|
197
|
+
### Available Configuration Options
|
132
198
|
|
133
|
-
|
199
|
+
All AssetSync configuration can be modified directly using environment variables with the **Built-in initializer**. e.g.
|
134
200
|
|
135
|
-
|
136
|
-
|
137
|
-
|
201
|
+
```ruby
|
202
|
+
AssetSync.config.fog_provider == ENV['FOG_PROVIDER']
|
203
|
+
```
|
138
204
|
|
139
|
-
|
205
|
+
Simply **upcase** the ruby attribute names to get the equivalent environment variable to set. The only exception to that rule are the internal **AssetSync** config variables, they must be prepended with `ASSET_SYNC_*` e.g.
|
140
206
|
|
141
|
-
```
|
142
|
-
|
143
|
-
export AWS_SECRET_ACCESS_KEY=xxxx
|
144
|
-
export FOG_DIRECTORY=xxxx
|
207
|
+
```ruby
|
208
|
+
AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
|
145
209
|
```
|
146
210
|
|
147
|
-
|
211
|
+
#### AssetSync (optional)
|
148
212
|
|
149
|
-
|
213
|
+
* **existing_remote_files**: (`'keep', 'delete'`) what to do with previously precompiled files. **default:** `'keep'`
|
214
|
+
* **gzip\_compression**: (`true, false`) when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. **default:** `'false'`
|
215
|
+
* **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'`
|
150
216
|
|
151
|
-
|
152
|
-
* **gzip\_compression**: when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version.
|
153
|
-
* **manifest**: when enabled, will use the `manifest.yml` generated by Rails to get the list of local files to upload. **experimental**
|
154
|
-
|
155
|
-
#### Required (Fog)
|
217
|
+
#### Fog (Required)
|
156
218
|
* **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files)
|
157
219
|
* **fog\_directory**: your bucket name
|
158
220
|
|
159
|
-
#### Optional
|
221
|
+
#### Fog (Optional)
|
160
222
|
|
161
223
|
* **fog\_region**: the region your storage bucket is in e.g. *eu-west-1*
|
162
224
|
|
@@ -170,21 +232,19 @@ export FOG_DIRECTORY=xxxx
|
|
170
232
|
* **rackspace\_username**: your Rackspace username
|
171
233
|
* **rackspace\_api\_key**: your Rackspace API Key.
|
172
234
|
|
173
|
-
#### Rackspace Optional
|
235
|
+
#### Rackspace (Optional)
|
174
236
|
|
175
237
|
* **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: lon.auth.api.rackspacecloud.com
|
176
238
|
|
177
239
|
## Amazon S3 Multiple Region Support
|
178
240
|
|
179
|
-
If you are using anything other than the US buckets with S3 then you'll want to set the **region**. For example with an EU bucket you could set the following
|
241
|
+
If you are using anything other than the US buckets with S3 then you'll want to set the **region**. For example with an EU bucket you could set the following environment variable.
|
180
242
|
|
181
|
-
```
|
182
|
-
|
183
|
-
# ...
|
184
|
-
aws_region: 'eu-west-1'
|
243
|
+
``` bash
|
244
|
+
heroku config:add FOG_REGION=eu-west-1
|
185
245
|
```
|
186
246
|
|
187
|
-
Or via
|
247
|
+
Or via a custom initializer
|
188
248
|
|
189
249
|
``` ruby
|
190
250
|
AssetSync.configure do |config|
|
@@ -193,27 +253,46 @@ AssetSync.configure do |config|
|
|
193
253
|
end
|
194
254
|
```
|
195
255
|
|
256
|
+
Or via YAML
|
257
|
+
|
258
|
+
``` yaml
|
259
|
+
production:
|
260
|
+
# ...
|
261
|
+
aws_region: 'eu-west-1'
|
262
|
+
```
|
263
|
+
|
264
|
+
|
196
265
|
## Automatic gzip compression
|
197
266
|
|
198
267
|
With the `gzip_compression` option enabled, when uploading your assets. If a file has a gzip compressed equivalent we will replace that asset with the compressed version and sets the correct headers for S3 to serve it. For example, if you have a file **master.css** and it was compressed to **master.css.gz** we will upload the **.gz** file to S3 in place of the uncompressed file.
|
199
268
|
|
200
269
|
If the compressed file is actually larger than the uncompressed file we will ignore this rule and upload the standard uncompressed version.
|
201
270
|
|
202
|
-
##
|
271
|
+
## Fail Silently
|
272
|
+
|
273
|
+
With the `fail_silently` option enabled, when running `rake assets:precompile` AssetSync will never throw an error due to missing configuration variables.
|
203
274
|
|
204
|
-
With
|
275
|
+
With the new **user_env_compile** feature of Heroku (see above), this is no longer required or recommended. Yet was added for the following reasons:
|
205
276
|
|
206
|
-
|
277
|
+
> With Rails 3.1 on the Heroku cedar stack, the deployment process automatically runs `rake assets:precompile`. If you are using **ENV** variable style configuration. Due to the methods with which Heroku compile slugs, there will be an error raised by asset\_sync as the environment is not available. This causes heroku to install the `rails31_enable_runtime_asset_compilation` plugin which is not necessary when using **asset_sync** and also massively slows down the first incoming requests to your app.
|
278
|
+
|
279
|
+
> To prevent this part of the deploy from failing (asset_sync raising a config error), but carry on as normal set `fail_silently` to true in your configuration and ensure to run `heroku run rake assets:precompile` after deploy.
|
207
280
|
|
208
281
|
## Rake Task
|
209
282
|
|
210
|
-
A rake task is included
|
283
|
+
A rake task is included within the **asset_sync** gem to enhance the rails precompile task by automatically running after it.
|
211
284
|
|
212
285
|
``` ruby
|
213
|
-
# asset_sync/lib/tasks/asset_sync.rake
|
214
|
-
Rake::Task
|
215
|
-
|
216
|
-
|
286
|
+
# asset_sync/lib/tasks/asset_sync.rake
|
287
|
+
if Rake::Task.task_defined?("assets:precompile:nondigest")
|
288
|
+
Rake::Task["assets:precompile:nondigest"].enhance do
|
289
|
+
AssetSync.sync
|
290
|
+
end
|
291
|
+
else
|
292
|
+
Rake::Task["assets:precompile"].enhance do
|
293
|
+
AssetSync.sync
|
294
|
+
end
|
295
|
+
end
|
217
296
|
```
|
218
297
|
|
219
298
|
## Todo
|
@@ -221,10 +300,11 @@ end
|
|
221
300
|
1. Add some before and after filters for deleting and uploading
|
222
301
|
2. Support more cloud storage providers
|
223
302
|
3. Better test coverage
|
303
|
+
4. Add rake tasks to clean old assets from a bucket
|
224
304
|
|
225
305
|
## Credits
|
226
306
|
|
227
|
-
|
307
|
+
Inspired by:
|
228
308
|
|
229
309
|
- [https://github.com/moocode/asset_id](https://github.com/moocode/asset_id)
|
230
310
|
- [https://gist.github.com/1053855](https://gist.github.com/1053855)
|
data/asset_sync.gemspec
CHANGED
@@ -6,7 +6,7 @@ require "asset_sync/version"
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "asset_sync"
|
8
8
|
s.version = AssetSync::VERSION
|
9
|
-
s.date = "2012-03-
|
9
|
+
s.date = "2012-03-07"
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.authors = ["Simon Hamilton", "David Rice", "Phil McClure"]
|
12
12
|
s.email = ["shamilton@rumblelabs.com", "me@davidjrice.co.uk", "pmcclure@rumblelabs.com"]
|
data/lib/asset_sync/engine.rb
CHANGED
@@ -21,7 +21,9 @@ class Engine < Rails::Engine
|
|
21
21
|
|
22
22
|
config.rackspace_username = ENV['RACKSPACE_USERNAME']
|
23
23
|
config.rackspace_api_key = ENV['RACKSPACE_API_KEY']
|
24
|
-
config.existing_remote_files = "keep"
|
24
|
+
config.existing_remote_files = ENV['ASSET_SYNC_EXISTING_REMOTE_FILES'] || "keep"
|
25
|
+
config.gzip_compression = ENV['ASSET_SYNC_GZIP_COMPRESSION'] == 'true'
|
26
|
+
config.manifest = ENV['ASSET_SYNC_MANIFEST'] == 'true'
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
data/lib/asset_sync/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-03-
|
14
|
+
date: 2012-03-07 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog
|
18
|
-
requirement: &
|
18
|
+
requirement: &70330270051360 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70330270051360
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
|
-
requirement: &
|
29
|
+
requirement: &70330270050940 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70330270050940
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &70330270050520 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70330270050520
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: bundler
|
51
|
-
requirement: &
|
51
|
+
requirement: &70330270050100 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '0'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70330270050100
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: jeweler
|
62
|
-
requirement: &
|
62
|
+
requirement: &70330270049680 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ! '>='
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70330270049680
|
71
71
|
description: After you run assets:precompile your compiled assets will be synchronised
|
72
72
|
with your S3 bucket.
|
73
73
|
email:
|