refinerycms-s3assets 0.1.0 → 0.2.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 +27 -5
- data/lib/refinerycms-s3assets/version.rb +1 -1
- data/lib/refinerycms-s3assets.rb +44 -30
- data/lib/tasks/s3assets.rake +14 -3
- data/refinerycms-s3assets.gemspec +4 -4
- metadata +77 -44
data/README.md
CHANGED
|
@@ -7,14 +7,14 @@ This gem adds a rake task to your Refinery CMS project which copies your product
|
|
|
7
7
|
|
|
8
8
|
1. Mac OS X, Linux, or UNIX.
|
|
9
9
|
2. A Heroku account (or S3 credentials).
|
|
10
|
-
3. A Refinery CMS project
|
|
10
|
+
3. A Refinery CMS 2.x project (RefineryCMS 1.x not currently supported)
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
Open up your Gemfile and add at the bottom this line:
|
|
15
15
|
|
|
16
16
|
```ruby
|
|
17
|
-
gem 'refinerycms-s3assets'
|
|
17
|
+
gem 'refinerycms-s3assets', :group => :development
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Now, run:
|
|
@@ -29,6 +29,8 @@ This gem assumes that your production Heroku app is storing assets on Amazon s3
|
|
|
29
29
|
and that your Heroku app has the following three config vars properly defined:
|
|
30
30
|
`S3_BUCKET`, `S3_KEY` and `S3_SECRET` ( see http://devcenter.heroku.com/articles/config-vars for more info).
|
|
31
31
|
|
|
32
|
+
### Copying production data to development
|
|
33
|
+
|
|
32
34
|
Start by copying your production database to your local database:
|
|
33
35
|
|
|
34
36
|
```shell
|
|
@@ -38,20 +40,40 @@ heroku db:pull
|
|
|
38
40
|
To copy all Image and Resource files from S3 you can now run the following:
|
|
39
41
|
|
|
40
42
|
```shell
|
|
41
|
-
bundle exec rake
|
|
43
|
+
bundle exec rake refinery_s3assets:pull
|
|
42
44
|
```
|
|
43
45
|
|
|
46
|
+
### Copying development data to production
|
|
47
|
+
|
|
48
|
+
Start by copying your development database to your production:
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
heroku db:push
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To copy all Image and Resources files from local development to S3 you can run the following:
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
bundle exec rake refinery_s3assets:push
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Alternatative methods of specifying S3 credentials
|
|
61
|
+
|
|
44
62
|
If you do not have a Heroku application but you do know the S3 credentials then you
|
|
45
63
|
can provide these manually as ENV variables:
|
|
46
64
|
|
|
47
65
|
```shell
|
|
48
|
-
S3_KEY=key S3_SECRET=secret S3_BUCKET=bucket bundle exec rake
|
|
66
|
+
S3_KEY=key S3_SECRET=secret S3_BUCKET=bucket bundle exec rake refinery_s3assets:pull
|
|
49
67
|
```
|
|
50
68
|
|
|
69
|
+
## Warning
|
|
70
|
+
|
|
71
|
+
There is currently no prompting if you are overwriting existing files so please be careful.
|
|
72
|
+
|
|
51
73
|
## License
|
|
52
74
|
|
|
53
75
|
Please see MIT-LICENSE for more details.
|
|
54
76
|
|
|
55
77
|
## Copyright
|
|
56
78
|
|
|
57
|
-
Copyright (c)
|
|
79
|
+
Copyright (c) 2012 Rounders Consulting Inc.
|
data/lib/refinerycms-s3assets.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require 'aws
|
|
1
|
+
require 'aws-sdk'
|
|
2
2
|
require 'heroku/command/base'
|
|
3
3
|
require 'progress_bar'
|
|
4
4
|
|
|
@@ -13,50 +13,64 @@ module Refinery
|
|
|
13
13
|
class Util
|
|
14
14
|
|
|
15
15
|
def self.pull
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
verify_s3_configuration
|
|
17
|
+
base_path = "public/system/refinery"
|
|
18
|
+
copy_from_s3_bucket(Image, :image_uid, s3_config[:bucket], File.join(base_path, "images"))
|
|
19
|
+
copy_from_s3_bucket(Resource, :file_uid, s3_config[:bucket], File.join(base_path, "resources"))
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
def self.push
|
|
23
|
+
verify_s3_configuration
|
|
24
|
+
base_path = "public/system/refinery"
|
|
25
|
+
copy_to_s3_bucket(Image, :image_uid, s3_config[:bucket], File.join(base_path, "images"))
|
|
26
|
+
copy_to_s3_bucket(Resource, :file_uid, s3_config[:bucket], File.join(base_path, "resources"))
|
|
27
|
+
end
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
AWS::S3::Base.establish_connection!(:access_key_id => s3_key, :secret_access_key => s3_secret)
|
|
26
|
-
bucket = AWS::S3::Bucket.find(s3_bucket)
|
|
29
|
+
private
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
dest = File.join(output_path,"images",s3_object.key)
|
|
32
|
-
copy_s3_object(s3_object,dest)
|
|
31
|
+
def self.verify_s3_configuration
|
|
32
|
+
{ :key => 'S3_KEY', :secret => 'S3_SECRET', :bucket => 'S3_BUCKET' }.each do |key, val|
|
|
33
|
+
raise(StandardError, "no #{val} config var or environment variable found") if s3_config[key].nil?
|
|
33
34
|
end
|
|
35
|
+
end
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
def self.copy_to_s3_bucket(klass, uid, bucket, source_path)
|
|
38
|
+
puts "Uploading #{klass.count} #{klass.to_s.pluralize} to #{bucket} bucket"
|
|
39
|
+
bar = ProgressBar.new(klass.count, :bar, :counter, :percentage)
|
|
40
|
+
klass.all.each do |object|
|
|
41
|
+
s3_object = s3.buckets[bucket].objects[object.send(uid)]
|
|
42
|
+
path = File.join(source_path, object.send(uid))
|
|
43
|
+
s3_object.write(:file => path, :acl => :public_read)
|
|
44
|
+
bar.increment!
|
|
40
45
|
end
|
|
46
|
+
end
|
|
41
47
|
|
|
48
|
+
def self.copy_from_s3_bucket(klass, uid, bucket, output_path)
|
|
49
|
+
puts "Downloading #{klass.count} #{klass.to_s.pluralize} from #{bucket} bucket"
|
|
50
|
+
bar = ProgressBar.new(klass.count, :bar, :counter, :percentage)
|
|
51
|
+
skipped_files = []
|
|
52
|
+
klass.all.each do |object|
|
|
53
|
+
begin
|
|
54
|
+
s3_object = s3.buckets[bucket].objects[object.send(uid)]
|
|
55
|
+
dest = File.join(output_path, s3_object.key)
|
|
56
|
+
copy_s3_object(s3_object, dest)
|
|
57
|
+
bar.increment!
|
|
58
|
+
rescue AWS::S3::Errors::NoSuchKey
|
|
59
|
+
skipped_files << object.send(uid)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
skipped_files.each {|f| puts "could not find #{f}"}
|
|
42
63
|
end
|
|
43
64
|
|
|
44
65
|
def self.copy_s3_object(s3_object, to)
|
|
45
66
|
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
67
|
open(to, 'wb') do |f|
|
|
53
|
-
s3_object.
|
|
54
|
-
bar.increment! chunk.size
|
|
55
|
-
f.write chunk
|
|
56
|
-
end
|
|
68
|
+
f.write s3_object.read
|
|
57
69
|
end
|
|
70
|
+
end
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
def self.s3
|
|
73
|
+
@s3 ||= AWS::S3.new(:access_key_id => s3_config[:key], :secret_access_key => s3_config[:secret])
|
|
60
74
|
end
|
|
61
75
|
|
|
62
76
|
def self.s3_config
|
data/lib/tasks/s3assets.rake
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
namespace :
|
|
3
|
+
namespace :refinery_s3assets do
|
|
4
4
|
desc "download image and resource assets from s3"
|
|
5
|
-
task :
|
|
5
|
+
task :pull => :environment do
|
|
6
6
|
Refinery::S3assets::Util.pull
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
desc "upload local image and resource assets to s3"
|
|
10
|
+
task :push => :environment do
|
|
11
|
+
Refinery::S3assets::Util.push
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# preserve old tasks
|
|
16
|
+
namespace :refinery do
|
|
17
|
+
task :download_s3_assets => 'refinery_s3assets:pull'
|
|
18
|
+
task :upload_s3_assets => 'refinery_s3assets:push'
|
|
19
|
+
end
|
|
@@ -8,13 +8,13 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["Francois Harbec"]
|
|
10
10
|
s.email = ["fharbec@gmail.com"]
|
|
11
|
-
s.homepage = ""
|
|
11
|
+
s.homepage = "https://github.com/rounders/refinerycms-s3assets"
|
|
12
12
|
s.summary = %q{copies s3 assets from production refinerycms app hosted on Heroku to local}
|
|
13
13
|
s.description = %q{copies s3 assets from production refinerycms app hosted on Heroku to local}
|
|
14
14
|
|
|
15
|
-
s.add_dependency("aws-
|
|
16
|
-
s.add_dependency("heroku", "~> 2.
|
|
17
|
-
s.add_dependency("progress_bar", "~> 0.
|
|
15
|
+
s.add_dependency("aws-sdk", "~> 1.3.7")
|
|
16
|
+
s.add_dependency("heroku", "~> 2.21.2")
|
|
17
|
+
s.add_dependency("progress_bar", "~> 0.4.0")
|
|
18
18
|
|
|
19
19
|
s.rubyforge_project = "refinerycms-s3assets"
|
|
20
20
|
|
metadata
CHANGED
|
@@ -1,57 +1,80 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: refinerycms-s3assets
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 2
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.2.0
|
|
6
11
|
platform: ruby
|
|
7
|
-
authors:
|
|
12
|
+
authors:
|
|
8
13
|
- Francois Harbec
|
|
9
14
|
autorequire:
|
|
10
15
|
bindir: bin
|
|
11
16
|
cert_chain: []
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
date: 2012-03-13 00:00:00 Z
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: aws-sdk
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
17
24
|
none: false
|
|
18
|
-
requirements:
|
|
25
|
+
requirements:
|
|
19
26
|
- - ~>
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
hash: 21
|
|
29
|
+
segments:
|
|
30
|
+
- 1
|
|
31
|
+
- 3
|
|
32
|
+
- 7
|
|
33
|
+
version: 1.3.7
|
|
22
34
|
type: :runtime
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- !ruby/object:Gem::Dependency
|
|
35
|
+
version_requirements: *id001
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
26
37
|
name: heroku
|
|
27
|
-
|
|
38
|
+
prerelease: false
|
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
28
40
|
none: false
|
|
29
|
-
requirements:
|
|
41
|
+
requirements:
|
|
30
42
|
- - ~>
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
hash: 95
|
|
45
|
+
segments:
|
|
46
|
+
- 2
|
|
47
|
+
- 21
|
|
48
|
+
- 2
|
|
49
|
+
version: 2.21.2
|
|
33
50
|
type: :runtime
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- !ruby/object:Gem::Dependency
|
|
51
|
+
version_requirements: *id002
|
|
52
|
+
- !ruby/object:Gem::Dependency
|
|
37
53
|
name: progress_bar
|
|
38
|
-
|
|
54
|
+
prerelease: false
|
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
39
56
|
none: false
|
|
40
|
-
requirements:
|
|
57
|
+
requirements:
|
|
41
58
|
- - ~>
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
hash: 15
|
|
61
|
+
segments:
|
|
62
|
+
- 0
|
|
63
|
+
- 4
|
|
64
|
+
- 0
|
|
65
|
+
version: 0.4.0
|
|
44
66
|
type: :runtime
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
local
|
|
49
|
-
email:
|
|
67
|
+
version_requirements: *id003
|
|
68
|
+
description: copies s3 assets from production refinerycms app hosted on Heroku to local
|
|
69
|
+
email:
|
|
50
70
|
- fharbec@gmail.com
|
|
51
71
|
executables: []
|
|
72
|
+
|
|
52
73
|
extensions: []
|
|
74
|
+
|
|
53
75
|
extra_rdoc_files: []
|
|
54
|
-
|
|
76
|
+
|
|
77
|
+
files:
|
|
55
78
|
- .gitignore
|
|
56
79
|
- Gemfile
|
|
57
80
|
- MIT-LICENSE
|
|
@@ -61,28 +84,38 @@ files:
|
|
|
61
84
|
- lib/refinerycms-s3assets/version.rb
|
|
62
85
|
- lib/tasks/s3assets.rake
|
|
63
86
|
- refinerycms-s3assets.gemspec
|
|
64
|
-
homepage:
|
|
87
|
+
homepage: https://github.com/rounders/refinerycms-s3assets
|
|
65
88
|
licenses: []
|
|
89
|
+
|
|
66
90
|
post_install_message:
|
|
67
91
|
rdoc_options: []
|
|
68
|
-
|
|
92
|
+
|
|
93
|
+
require_paths:
|
|
69
94
|
- lib
|
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
96
|
none: false
|
|
72
|
-
requirements:
|
|
73
|
-
- -
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
|
|
76
|
-
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
hash: 3
|
|
101
|
+
segments:
|
|
102
|
+
- 0
|
|
103
|
+
version: "0"
|
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
105
|
none: false
|
|
78
|
-
requirements:
|
|
79
|
-
- -
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
hash: 3
|
|
110
|
+
segments:
|
|
111
|
+
- 0
|
|
112
|
+
version: "0"
|
|
82
113
|
requirements: []
|
|
114
|
+
|
|
83
115
|
rubyforge_project: refinerycms-s3assets
|
|
84
116
|
rubygems_version: 1.8.15
|
|
85
117
|
signing_key:
|
|
86
118
|
specification_version: 3
|
|
87
119
|
summary: copies s3 assets from production refinerycms app hosted on Heroku to local
|
|
88
120
|
test_files: []
|
|
121
|
+
|