refinerycms-s3assets 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +41 -0
- data/Rakefile +2 -0
- data/lib/refinerycms-s3assets/version.rb +5 -0
- data/lib/refinerycms-s3assets.rb +86 -0
- data/lib/tasks/s3assets.rake +8 -0
- data/refinerycms-s3assets.gemspec +25 -0
- metadata +124 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
refinerycms-s3assets (0.0.1)
|
5
|
+
aws-s3 (~> 0.6.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
aws-s3 (0.6.2)
|
11
|
+
builder
|
12
|
+
mime-types
|
13
|
+
xml-simple
|
14
|
+
builder (3.0.0)
|
15
|
+
mime-types (1.16)
|
16
|
+
xml-simple (1.0.15)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
refinerycms-s3assets!
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011, Rounders Consulting Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= refinerycms-s3assets
|
2
|
+
|
3
|
+
A common development scenario, when using a Heroku-hosted RefineryCMS app, is to copy production data to development via the use of heroku db:pull. This gem adds a rake task to your RefineryCMS project which copies your production assets stored on s3 onto the local filesystem.
|
4
|
+
|
5
|
+
= Requirements
|
6
|
+
|
7
|
+
1. Mac OS X, Linux, or UNIX.
|
8
|
+
2. A Heroku account.
|
9
|
+
3. A Refinery CMS project
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
Open up your Gemfile and add at the bottom this line:
|
14
|
+
|
15
|
+
gem 'refinerycms-s3assets'
|
16
|
+
|
17
|
+
Now, run:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
== Usage
|
22
|
+
|
23
|
+
This gem assumes that your production Heroku app is storing assets on Amazon s3 and that your Heroku app has the following three config vars properly defined: S3_BUCKET, S3_KEY and S3_SECRET ( see http://devcenter.heroku.com/articles/config-vars for more info).
|
24
|
+
|
25
|
+
Start by copying your production database to your local database:
|
26
|
+
|
27
|
+
$ heroku db:pull
|
28
|
+
|
29
|
+
To copy all Image and Resource files from S3 you can now run the following:
|
30
|
+
|
31
|
+
$ rake refinery:download_s3_assets
|
32
|
+
|
33
|
+
== License
|
34
|
+
|
35
|
+
Please see MIT-LICENSE for more details.
|
36
|
+
|
37
|
+
== Copyright
|
38
|
+
|
39
|
+
Copyright (c) 2011 Rounders Consulting Inc.
|
40
|
+
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'aws/s3'
|
2
|
+
require 'heroku/command'
|
3
|
+
require 'progress_bar'
|
4
|
+
|
5
|
+
module Refinery
|
6
|
+
module S3assets
|
7
|
+
class MyRailtie < Rails::Railtie
|
8
|
+
rake_tasks do
|
9
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Util
|
14
|
+
|
15
|
+
def self.pull
|
16
|
+
raise(StandardError, "no S3_KEY config var or environment variable found") if s3_config[:s3_key].nil?
|
17
|
+
raise(StandardError, "no S3_SECRET config var or environment variable found") if s3_config[:s3_secret].nil?
|
18
|
+
raise(StandardError, "no S3_BUCKET config var or environment variable found") if s3_config[:s3_bucket].nil?
|
19
|
+
copy_s3_bucket(s3_config[:s3_key], s3_config[:s3_secret], s3_config[:s3_bucket], 'public/system')
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.copy_s3_bucket(s3_key, s3_secret, s3_bucket, output_path)
|
25
|
+
AWS::S3::Base.establish_connection!(:access_key_id => s3_key, :secret_access_key => s3_secret)
|
26
|
+
bucket = AWS::S3::Bucket.find(s3_bucket)
|
27
|
+
|
28
|
+
puts "There are #{Image.count} images in the #{s3_bucket} bucket"
|
29
|
+
Image.all.each do |image|
|
30
|
+
object = AWS::S3::S3Object.find image.image_uid,s3_bucket
|
31
|
+
dest = File.join(output_path,"images",object.key)
|
32
|
+
copy_s3_object(object,dest)
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "\n\nThere are #{Resource.count} resources in the #{s3_bucket} bucket"
|
36
|
+
Resource.all.each do |resource|
|
37
|
+
object = AWS::S3::S3Object.find resource.file_uid,s3_bucket
|
38
|
+
dest = File.join(output_path,"resources",object.key)
|
39
|
+
copy_s3_object(object,dest)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.copy_s3_object(s3_object, to)
|
45
|
+
FileUtils::mkdir_p File.dirname(to), :verbose => false
|
46
|
+
|
47
|
+
filesize = s3_object.about['content-length'].to_f
|
48
|
+
puts "Saving #{s3_object.key} (#{filesize} bytes):"
|
49
|
+
|
50
|
+
bar = ProgressBar.new(filesize, :percentage, :counter)
|
51
|
+
|
52
|
+
open(to, 'w') do |f|
|
53
|
+
s3_object.value do |chunk|
|
54
|
+
bar.increment! chunk.size
|
55
|
+
f.puts chunk
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
puts "\n=======================================\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.s3_config
|
63
|
+
return @s3_config unless @s3_config.nil?
|
64
|
+
|
65
|
+
heroku_command = Heroku::Command::Base.new({})
|
66
|
+
|
67
|
+
begin
|
68
|
+
app = heroku_command.extract_app
|
69
|
+
rescue
|
70
|
+
puts "This does not look like a Heroku app!"
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
|
74
|
+
config_vars = heroku_command.heroku.config_vars(app)
|
75
|
+
|
76
|
+
@s3_config = {
|
77
|
+
:s3_key => ENV['S3_KEY'] || config_vars['S3_KEY'],
|
78
|
+
:s3_secret => ENV['S3_SECRET'] || config_vars['S3_SECRET'],
|
79
|
+
:s3_bucket => ENV['S3_BUCKET'] || config_vars['S3_BUCKET']
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "refinerycms-s3assets/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "refinerycms-s3assets"
|
7
|
+
s.version = Refinery::S3assets::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Francois Harbec"]
|
10
|
+
s.email = ["fharbec@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{copies s3 assets from production refinerycms app hosted on Heroku to local}
|
13
|
+
s.description = %q{copies s3 assets from production refinerycms app hosted on Heroku to local}
|
14
|
+
|
15
|
+
s.add_dependency("aws-s3", "~> 0.6.2")
|
16
|
+
s.add_dependency("heroku", "~> 1.20.1")
|
17
|
+
s.add_dependency("progress_bar", "~> 0.3.4")
|
18
|
+
|
19
|
+
s.rubyforge_project = "refinerycms-s3assets"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refinerycms-s3assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Francois Harbec
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-03 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: aws-s3
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
- 2
|
34
|
+
version: 0.6.2
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: heroku
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 69
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 20
|
49
|
+
- 1
|
50
|
+
version: 1.20.1
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: progress_bar
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 27
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 3
|
65
|
+
- 4
|
66
|
+
version: 0.3.4
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
description: copies s3 assets from production refinerycms app hosted on Heroku to local
|
70
|
+
email:
|
71
|
+
- fharbec@gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files: []
|
77
|
+
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- MIT-LICENSE
|
83
|
+
- README.rdoc
|
84
|
+
- Rakefile
|
85
|
+
- lib/refinerycms-s3assets.rb
|
86
|
+
- lib/refinerycms-s3assets/version.rb
|
87
|
+
- lib/tasks/s3assets.rake
|
88
|
+
- refinerycms-s3assets.gemspec
|
89
|
+
has_rdoc: true
|
90
|
+
homepage: ""
|
91
|
+
licenses: []
|
92
|
+
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project: refinerycms-s3assets
|
119
|
+
rubygems_version: 1.3.7
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: copies s3 assets from production refinerycms app hosted on Heroku to local
|
123
|
+
test_files: []
|
124
|
+
|