localist-asset_sync 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/README.md +179 -0
- data/Rakefile +1 -0
- data/asset_sync.gemspec +30 -0
- data/lib/asset_sync.rb +6 -0
- data/lib/asset_sync/asset_sync.rb +30 -0
- data/lib/asset_sync/config.rb +71 -0
- data/lib/asset_sync/storage.rb +85 -0
- data/lib/asset_sync/version.rb +3 -0
- data/lib/generators/asset_sync/install_generator.rb +49 -0
- data/lib/generators/asset_sync/templates/asset_sync.rake +3 -0
- data/lib/generators/asset_sync/templates/asset_sync.rb +10 -0
- data/lib/generators/asset_sync/templates/asset_sync.yml +23 -0
- data/spec/asset_sync_spec.rb +104 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/with_rackspace_yml/config/asset_sync.yml +19 -0
- data/spec/with_yml/config/asset_sync.yml +20 -0
- metadata +128 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
# Asset Sync
|
2
|
+
|
3
|
+
Synchronises Assets between Rails and S3.
|
4
|
+
|
5
|
+
Asset Sync is built to run with the new Rails Asset Pipeline feature of Rails 3.1. After you run __bundle exec rake assets:precompile__ your assets will be synchronised to your S3
|
6
|
+
bucket, optionally deleting unused files and only uploading the files it needs to.
|
7
|
+
|
8
|
+
This was initially built and is intended to work on [Heroku](http://heroku.com)
|
9
|
+
|
10
|
+
## KNOWN ISSUES (IMPORTANT)
|
11
|
+
|
12
|
+
We are currently trying to talk with Heroku to iron these out.
|
13
|
+
|
14
|
+
1. Will not work on heroku on an application with a *RAILS_ENV* configured as anything other than production
|
15
|
+
2. Will not work on heroku using ENV variables with the configuration as described below, you must hardcode all variables
|
16
|
+
|
17
|
+
### 1. RAILS_ENV
|
18
|
+
|
19
|
+
When you see `rake assets:precompile` during deployment. Herok is actually running something like
|
20
|
+
|
21
|
+
env RAILS_ENV=production DATABASE_URL=scheme://user:pass@127.0.0.1/dbname bundle exec rake assets:precompile 2>&1
|
22
|
+
|
23
|
+
This means the *RAILS_ENV* you have set via *heroku:config* is not used.
|
24
|
+
|
25
|
+
**Workaround:** you could have just one S3 bucket dedicated to assets and ensure to set keep the existing remote files
|
26
|
+
|
27
|
+
AssetSync.configure do |config|
|
28
|
+
...
|
29
|
+
config.fog_directory = 'app-assets'
|
30
|
+
config.existing_remote_files = "keep"
|
31
|
+
end
|
32
|
+
|
33
|
+
### 2. ENV varables not available
|
34
|
+
|
35
|
+
Currently when heroku runs `rake assets:precompile` during deployment. It does not load your Rails application's environment config. This means using any **ENV** variables you could normally depend on are not available.
|
36
|
+
|
37
|
+
**Workaround:** you could just hardcode your AWS credentials in the initializer or yml
|
38
|
+
|
39
|
+
AssetSync.configure do |config|
|
40
|
+
config.aws_access_key_id = 'xxx'
|
41
|
+
config.aws_secret_access_key = 'xxx'
|
42
|
+
config.fog_directory = 'mybucket'
|
43
|
+
end
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
Add the gem to your Gemfile
|
48
|
+
|
49
|
+
gem "asset_sync"
|
50
|
+
|
51
|
+
Generate the rake task and config files
|
52
|
+
|
53
|
+
rails g asset_sync:install
|
54
|
+
|
55
|
+
If you would like to use a YAML file for configuration instead of the default (Rails Initializer) then
|
56
|
+
|
57
|
+
rails g asset_sync:install --use-yml
|
58
|
+
|
59
|
+
## Configuration
|
60
|
+
|
61
|
+
Configure __config/environments/production.rb__ to use Amazon
|
62
|
+
S3 as the asset host and ensure precompiling is enabled.
|
63
|
+
|
64
|
+
# config/environments/production.rb
|
65
|
+
config.action_controller.asset_host = Proc.new do |source, request|
|
66
|
+
request.ssl? ? "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com" : "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
|
67
|
+
end
|
68
|
+
|
69
|
+
We support two methods of configuration.
|
70
|
+
|
71
|
+
* Rails Initializer
|
72
|
+
* A YAML config file
|
73
|
+
|
74
|
+
Using an **Initializer** is the default method and is best used with **environment** variables. It's the recommended approach for deployments on Heroku.
|
75
|
+
|
76
|
+
Using a **YAML** config file is a traditional strategy for Capistrano deployments. If you are using [Moonshine](https://github.com/railsmachine/moonshine) (which we would recommend) then it is best used with [shared configuration files](https://github.com/railsmachine/moonshine/wiki/Shared-Configuration-Files).
|
77
|
+
|
78
|
+
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.
|
79
|
+
|
80
|
+
### Initializer (config/initializers/asset_sync.rb)
|
81
|
+
|
82
|
+
The generator will create a Rails initializer at `config/initializers/asset_sync.rb`.
|
83
|
+
|
84
|
+
AssetSync.configure do |config|
|
85
|
+
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
86
|
+
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
87
|
+
config.fog_directory = ENV['FOG_DIRECTORY']
|
88
|
+
# config.fog_region = 'eu-west-1'
|
89
|
+
config.existing_remote_files = "keep"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
### YAML (config/asset_sync.yml)
|
94
|
+
|
95
|
+
If you used the `--use-yml` flag, the generator will create a YAML file at `config/initializers/asset_sync.rb`.
|
96
|
+
|
97
|
+
defaults: &defaults
|
98
|
+
aws_access_key_id: "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
|
99
|
+
aws_secret_access_key: "<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
|
100
|
+
# You may need to specify what region your S3 bucket is in
|
101
|
+
# fog_region: "eu-west-1"
|
102
|
+
|
103
|
+
development:
|
104
|
+
<<: *defaults
|
105
|
+
fog_directory: "rails-app-development"
|
106
|
+
existing_remote_files: keep # Existing pre-compiled assets on S3 will be kept
|
107
|
+
|
108
|
+
test:
|
109
|
+
<<: *defaults
|
110
|
+
fog_directory: "rails-app-test"
|
111
|
+
existing_remote_files: keep
|
112
|
+
|
113
|
+
production:
|
114
|
+
<<: *defaults
|
115
|
+
fog_directory: "rails-app-production"
|
116
|
+
existing_remote_files: delete # Existing pre-compiled assets on S3 will be deleted
|
117
|
+
|
118
|
+
### Environment Variables
|
119
|
+
|
120
|
+
Add your Amazon S3 configuration details to **heroku**
|
121
|
+
|
122
|
+
heroku config:add AWS_ACCESS_KEY_ID=xxxx
|
123
|
+
heroku config:add AWS_SECRET_ACCESS_KEY=xxxx
|
124
|
+
heroku config:add FOG_DIRECTORY=xxxx
|
125
|
+
|
126
|
+
Or add to a traditional unix system
|
127
|
+
|
128
|
+
export AWS_ACCESS_KEY_ID=xxxx
|
129
|
+
export AWS_SECRET_ACCESS_KEY=xxxx
|
130
|
+
export FOG_DIRECTORY=xxxx
|
131
|
+
|
132
|
+
### Available Configuration Options
|
133
|
+
|
134
|
+
* **aws\_access\_key\_id**: your Amazon S3 access key
|
135
|
+
* **aws\_secret\_access\_key**: your Amazon S3 access secret
|
136
|
+
* **aws\_region**: the region your S3 bucket is in e.g. *eu-west-1*
|
137
|
+
* **existing_remote_files**: what to do with previously precompiled files, options are **keep** or **delete**
|
138
|
+
|
139
|
+
## Amazon S3 Multiple Region Support
|
140
|
+
|
141
|
+
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 with YAML.
|
142
|
+
|
143
|
+
production:
|
144
|
+
# ...
|
145
|
+
aws\_region: 'eu-west-1'
|
146
|
+
|
147
|
+
Or via the initializer
|
148
|
+
|
149
|
+
AssetSync.configure do |config|
|
150
|
+
# ...
|
151
|
+
config.fog_region = 'eu-west-1'
|
152
|
+
end
|
153
|
+
|
154
|
+
## Rake Task
|
155
|
+
|
156
|
+
A rake task is installed with the generator to enhance the rails
|
157
|
+
precompile task by automatically running after it:
|
158
|
+
|
159
|
+
# lib/tasks/asset_sync.rake
|
160
|
+
Rake::Task["assets:precompile"].enhance do
|
161
|
+
AssetSync.sync
|
162
|
+
end
|
163
|
+
|
164
|
+
## Todo
|
165
|
+
|
166
|
+
1. Add some before and after filters for deleting and uploading
|
167
|
+
2. Support more cloud storage fog_providers
|
168
|
+
3. Better test coverage
|
169
|
+
|
170
|
+
## Credits
|
171
|
+
|
172
|
+
Have borrowed ideas from:
|
173
|
+
|
174
|
+
- [https://github.com/moocode/asset_id](https://github.com/moocode/asset_id)
|
175
|
+
- [https://gist.github.com/1053855](https://gist.github.com/1053855)
|
176
|
+
|
177
|
+
## License
|
178
|
+
|
179
|
+
MIT License. Copyright 2011 Rumble Labs Ltd. [rumblelabs.com](http://rumblelabs.com)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/asset_sync.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require "asset_sync/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "localist-asset_sync"
|
8
|
+
s.version = AssetSync::VERSION
|
9
|
+
s.date = "2011-10-04"
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ["Simon Hamilton", "David Rice", "Steve Hoeksema"]
|
12
|
+
s.email = ["shamilton@rumblelabs.com", "me@davidjrice.co.uk", "steve@seven.net.nz"]
|
13
|
+
s.homepage = "https://github.com/localist/asset_sync"
|
14
|
+
s.summary = %q{Synchronises Assets between Rails and S3 or Rackspace}
|
15
|
+
s.description = %q{After you run assets:precompile your assets will be synchronised with your S3 bucket or Rackspace Cloud Files container, deleting unused files and only uploading the files it needs to.}
|
16
|
+
|
17
|
+
s.rubyforge_project = "asset_sync"
|
18
|
+
|
19
|
+
s.add_dependency('fog')
|
20
|
+
s.add_dependency('activemodel')
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "bundler"
|
24
|
+
s.add_development_dependency "jeweler"
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
end
|
data/lib/asset_sync.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module AssetSync
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def config=(data)
|
6
|
+
@config = data
|
7
|
+
end
|
8
|
+
|
9
|
+
def config
|
10
|
+
@config ||= Config.new
|
11
|
+
raise Config::Invalid.new(@config.errors.full_messages.join(', ')) unless @config && @config.valid?
|
12
|
+
@config
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(&proc)
|
16
|
+
@config ||= Config.new
|
17
|
+
yield @config
|
18
|
+
end
|
19
|
+
|
20
|
+
def storage
|
21
|
+
@storage ||= Storage.new(self.config)
|
22
|
+
end
|
23
|
+
|
24
|
+
def sync
|
25
|
+
self.storage.sync
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module AssetSync
|
2
|
+
class Config
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
class Invalid < StandardError; end
|
6
|
+
|
7
|
+
attr_accessor :fog_provider, :fog_directory, :fog_region
|
8
|
+
attr_accessor :aws_access_key_id, :aws_secret_access_key
|
9
|
+
attr_accessor :rackspace_username, :rackspace_api_key
|
10
|
+
attr_accessor :existing_remote_files
|
11
|
+
|
12
|
+
validates :fog_provider, :presence => true
|
13
|
+
validates :fog_directory, :presence => true
|
14
|
+
validates :existing_remote_files, :inclusion => { :in => %w(keep delete) }
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
self.fog_provider = "AWS"
|
18
|
+
self.existing_remote_files = "keep"
|
19
|
+
load_yml! if yml_exists?
|
20
|
+
end
|
21
|
+
|
22
|
+
def existing_remote_files?
|
23
|
+
(self.existing_remote_files == "keep")
|
24
|
+
end
|
25
|
+
|
26
|
+
def yml_exists?
|
27
|
+
File.exists?(self.yml_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def yml
|
31
|
+
y ||= YAML.load(ERB.new(IO.read(yml_path)).result)[Rails.env] rescue nil || {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def yml_path
|
35
|
+
File.join(Rails.root, "config/asset_sync.yml")
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_yml!
|
39
|
+
self.fog_provider = yml["fog_provider"]
|
40
|
+
self.fog_directory = yml["fog_directory"]
|
41
|
+
self.fog_region = yml["fog_region"]
|
42
|
+
self.aws_access_key_id = yml["aws_access_key_id"]
|
43
|
+
self.aws_secret_access_key = yml["aws_secret_access_key"]
|
44
|
+
self.rackspace_username = yml["rackspace_username"]
|
45
|
+
self.rackspace_api_key = yml["rackspace_api_key"]
|
46
|
+
self.existing_remote_files = yml["existing_remote_files"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def fog_options
|
50
|
+
if fog_provider == "AWS"
|
51
|
+
options = {
|
52
|
+
:provider => fog_provider,
|
53
|
+
:aws_access_key_id => aws_access_key_id,
|
54
|
+
:aws_secret_access_key => aws_secret_access_key,
|
55
|
+
}
|
56
|
+
elsif fog_provider == "Rackspace"
|
57
|
+
options = {
|
58
|
+
:provider => fog_provider,
|
59
|
+
:rackspace_username => rackspace_username,
|
60
|
+
:rackspace_api_key => rackspace_api_key
|
61
|
+
}
|
62
|
+
else
|
63
|
+
raise ArgumentError, "Unknown provider: #{fog_provider}"
|
64
|
+
end
|
65
|
+
|
66
|
+
options.merge!({:region => fog_region}) if fog_region
|
67
|
+
return options
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module AssetSync
|
2
|
+
class Storage
|
3
|
+
|
4
|
+
class BucketNotFound < StandardError; end
|
5
|
+
|
6
|
+
attr_accessor :config
|
7
|
+
|
8
|
+
def initialize(cfg)
|
9
|
+
@config = cfg
|
10
|
+
end
|
11
|
+
|
12
|
+
def connection
|
13
|
+
@connection ||= Fog::Storage.new(self.config.fog_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def bucket
|
17
|
+
@bucket ||= connection.directories.get(self.config.fog_directory)
|
18
|
+
end
|
19
|
+
|
20
|
+
def keep_existing_remote_files?
|
21
|
+
self.config.existing_remote_files?
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
"#{Rails.root.to_s}/public"
|
26
|
+
end
|
27
|
+
|
28
|
+
def local_files
|
29
|
+
Dir["#{path}/assets/**/**"].map { |f| f[path.length+1,f.length-path.length] }
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_remote_files
|
33
|
+
raise BucketNotFound.new("Fog directory: #{self.config.fog_directory} not found.") unless bucket
|
34
|
+
return bucket.files.map { |f| f.key }
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete_file(f, remote_files_to_delete)
|
38
|
+
if remote_files_to_delete.include?(f.key)
|
39
|
+
STDERR.puts "Deleting: #{f.key}"
|
40
|
+
f.destroy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_extra_remote_files
|
45
|
+
STDERR.puts "Fetching files to flag for delete"
|
46
|
+
remote_files = get_remote_files
|
47
|
+
from_remote_files_to_delete = (local_files | remote_files) - (local_files & remote_files)
|
48
|
+
|
49
|
+
STDERR.puts "Flagging #{from_remote_files_to_delete.size} file(s) for deletion"
|
50
|
+
# Delete unneeded remote files
|
51
|
+
bucket.files.each do |f|
|
52
|
+
delete_file(f, from_remote_files_to_delete)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def upload_file(f)
|
57
|
+
STDERR.puts "Uploading: #{f}"
|
58
|
+
file = bucket.files.create(
|
59
|
+
:key => "#{f}",
|
60
|
+
:body => File.open("#{path}/#{f}"),
|
61
|
+
:public => true,
|
62
|
+
:cache_control => "max-age=31557600"
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def upload_files
|
67
|
+
# get a fresh list of remote files
|
68
|
+
remote_files = get_remote_files
|
69
|
+
local_files_to_upload = (remote_files | local_files) - (remote_files & local_files)
|
70
|
+
|
71
|
+
# Upload new files
|
72
|
+
local_files_to_upload.each do |f|
|
73
|
+
next unless File.file? "#{path}/#{f}" # Only files.
|
74
|
+
upload_file f
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def sync
|
79
|
+
delete_extra_remote_files unless keep_existing_remote_files?
|
80
|
+
upload_files
|
81
|
+
STDERR.puts "Done."
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module AssetSync
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "Install a config/asset_sync.yml and the asset:precompile rake task enhancer"
|
5
|
+
|
6
|
+
# Commandline options can be defined here using Thor-like options:
|
7
|
+
class_option :use_yml, :type => :boolean, :default => false, :desc => "Use YML file instead of Rails Initializer"
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
11
|
+
end
|
12
|
+
|
13
|
+
def aws_access_key_id
|
14
|
+
"<%= ENV['AWS_ACCESS_KEY_ID'] %>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def aws_secret_access_key
|
18
|
+
"<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def rackspace_username
|
22
|
+
"<%= ENV['RACKSPACE_USERNAME'] %>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def rackspace_api_key
|
26
|
+
"<%= ENV['RACKSPACE_API_KEY'] %>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def app_name
|
30
|
+
@app_name ||= Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "").downcase
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_config
|
34
|
+
if options[:use_yml]
|
35
|
+
template "asset_sync.yml", "config/asset_sync.yml"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_initializer
|
40
|
+
unless options[:use_yml]
|
41
|
+
template "asset_sync.rb", "config/initializers/asset_sync.rb"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_rake_task
|
46
|
+
template "asset_sync.rake", "lib/tasks/asset_sync.rake"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
AssetSync.configure do |config|
|
2
|
+
config.fog_provider = ENV['FOG_PROVIDER']
|
3
|
+
config.fog_directory = ENV['FOG_DIRECTORY']
|
4
|
+
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
5
|
+
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
6
|
+
config.rackspace_username = ENV['RACKSPACE_USERNAME']
|
7
|
+
config.rackspace_api_key = ENV['RACKSPACE_API_KEY']
|
8
|
+
# config.fog_region = "eu-west-1"
|
9
|
+
config.existing_remote_files = "keep"
|
10
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: AWS
|
3
|
+
aws_access_key_id: "<%= aws_access_key_id %>"
|
4
|
+
aws_secret_access_key: "<%= aws_secret_access_key %>"
|
5
|
+
rackspace_username: "<%= rackspace_username %>"
|
6
|
+
rackspace_api_key: "<%= rackspace_api_key %>"
|
7
|
+
# You may need to specify what region your S3 bucket is in
|
8
|
+
# region: "eu-west-1"
|
9
|
+
|
10
|
+
development:
|
11
|
+
<<: *defaults
|
12
|
+
fog_directory: "<%= app_name %>_development"
|
13
|
+
existing_remote_files: keep # Existing pre-compiled assets on S3 will be kept
|
14
|
+
|
15
|
+
test:
|
16
|
+
<<: *defaults
|
17
|
+
fog_directory: "<%= app_name %>_test"
|
18
|
+
existing_remote_files: keep
|
19
|
+
|
20
|
+
production:
|
21
|
+
<<: *defaults
|
22
|
+
fog_directory: "<%= app_name %>_production"
|
23
|
+
existing_remote_files: delete # Existing pre-compiled assets on S3 will be deleted
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetSync, 'with initializer' do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Rails.root = 'without_yml'
|
7
|
+
AssetSync.config = AssetSync::Config.new
|
8
|
+
AssetSync.configure do |config|
|
9
|
+
config.aws_access_key_id = 'aaaa'
|
10
|
+
config.aws_secret_access_key = 'bbbb'
|
11
|
+
config.fog_directory = 'mybucket'
|
12
|
+
config.fog_region = 'eu-west-1'
|
13
|
+
config.existing_remote_files = "keep"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should should keep existing remote files" do
|
18
|
+
AssetSync.config.existing_remote_files?.should == true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should configure aws_access_key_id" do
|
22
|
+
AssetSync.config.aws_access_key_id.should == "aaaa"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should configure aws_secret_access_key" do
|
26
|
+
AssetSync.config.aws_secret_access_key.should == "bbbb"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should configure fog_directory" do
|
30
|
+
AssetSync.config.fog_directory.should == "mybucket"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should configure fog_region" do
|
34
|
+
AssetSync.config.fog_region.should == "eu-west-1"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should configure existing_remote_files" do
|
38
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe AssetSync, 'from yml' do
|
44
|
+
|
45
|
+
before(:all) do
|
46
|
+
Rails.root = 'with_yml'
|
47
|
+
AssetSync.config = AssetSync::Config.new
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should configure aws_access_key_id" do
|
51
|
+
AssetSync.config.aws_access_key_id.should == "xxxx"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should configure aws_secret_access_key" do
|
55
|
+
AssetSync.config.aws_secret_access_key.should == "zzzz"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should configure fog_directory" do
|
59
|
+
AssetSync.config.fog_directory.should == "rails_app_test"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should configure fog_region" do
|
63
|
+
AssetSync.config.fog_region.should == "eu-west-1"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should configure existing_remote_files" do
|
67
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe AssetSync, 'from rackspace yml' do
|
73
|
+
|
74
|
+
before(:all) do
|
75
|
+
Rails.root = 'with_rackspace_yml'
|
76
|
+
AssetSync.config = AssetSync::Config.new
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should configure fog_provider" do
|
80
|
+
AssetSync.config.fog_provider.should == "Rackspace"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should configure rackspace_username" do
|
84
|
+
AssetSync.config.rackspace_username.should == "vvvv"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should configure rackspace_api_key" do
|
88
|
+
AssetSync.config.rackspace_api_key.should == "wwww"
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe AssetSync, 'with no configuration' do
|
94
|
+
|
95
|
+
before(:all) do
|
96
|
+
Rails.root = 'without_yml'
|
97
|
+
AssetSync.config = AssetSync::Config.new
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should be invalid" do
|
101
|
+
lambda{ AssetSync.config.valid?.should == false }.should raise_error(AssetSync::Config::Invalid)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
require 'asset_sync'
|
14
|
+
|
15
|
+
class Rails
|
16
|
+
|
17
|
+
@@path = 'without_yml'
|
18
|
+
|
19
|
+
def self.env
|
20
|
+
"test"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.root=(path)
|
24
|
+
@@path = path
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.root
|
28
|
+
File.expand_path(File.join('spec', @@path))
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: Rackspace
|
3
|
+
rackspace_username: vvvv
|
4
|
+
rackspace_api_key: wwww
|
5
|
+
|
6
|
+
development:
|
7
|
+
<<: *defaults
|
8
|
+
fog_directory: rails_app_development
|
9
|
+
existing_remote_files: keep
|
10
|
+
|
11
|
+
test:
|
12
|
+
<<: *defaults
|
13
|
+
fog_directory: rails_app_test
|
14
|
+
existing_remote_files: keep
|
15
|
+
|
16
|
+
production:
|
17
|
+
<<: *defaults
|
18
|
+
fog_directory: rails_app_production
|
19
|
+
existing_remote_files: delete
|
@@ -0,0 +1,20 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
fog_provider: AWS
|
3
|
+
fog_region: eu-west-1
|
4
|
+
aws_access_key_id: xxxx
|
5
|
+
aws_secret_access_key: zzzz
|
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
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: localist-asset_sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon Hamilton
|
9
|
+
- David Rice
|
10
|
+
- Steve Hoeksema
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-10-04 00:00:00.000000000Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: fog
|
18
|
+
requirement: &70100529221200 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *70100529221200
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: &70100529220780 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *70100529220780
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
requirement: &70100529220360 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *70100529220360
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bundler
|
51
|
+
requirement: &70100529250900 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *70100529250900
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: jeweler
|
62
|
+
requirement: &70100529250480 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *70100529250480
|
71
|
+
description: After you run assets:precompile your assets will be synchronised with
|
72
|
+
your S3 bucket or Rackspace Cloud Files container, deleting unused files and only
|
73
|
+
uploading the files it needs to.
|
74
|
+
email:
|
75
|
+
- shamilton@rumblelabs.com
|
76
|
+
- me@davidjrice.co.uk
|
77
|
+
- steve@seven.net.nz
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- .gitignore
|
83
|
+
- Gemfile
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- asset_sync.gemspec
|
87
|
+
- lib/asset_sync.rb
|
88
|
+
- lib/asset_sync/asset_sync.rb
|
89
|
+
- lib/asset_sync/config.rb
|
90
|
+
- lib/asset_sync/storage.rb
|
91
|
+
- lib/asset_sync/version.rb
|
92
|
+
- lib/generators/asset_sync/install_generator.rb
|
93
|
+
- lib/generators/asset_sync/templates/asset_sync.rake
|
94
|
+
- lib/generators/asset_sync/templates/asset_sync.rb
|
95
|
+
- lib/generators/asset_sync/templates/asset_sync.yml
|
96
|
+
- spec/asset_sync_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/with_rackspace_yml/config/asset_sync.yml
|
99
|
+
- spec/with_yml/config/asset_sync.yml
|
100
|
+
homepage: https://github.com/localist/asset_sync
|
101
|
+
licenses: []
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project: asset_sync
|
120
|
+
rubygems_version: 1.8.6
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Synchronises Assets between Rails and S3 or Rackspace
|
124
|
+
test_files:
|
125
|
+
- spec/asset_sync_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/with_rackspace_yml/config/asset_sync.yml
|
128
|
+
- spec/with_yml/config/asset_sync.yml
|