syncassets_r2 0.3.1 → 0.4.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.rdoc +1 -1
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/syncassets_r2.rb +6 -0
- data/lib/tasks/syncassets_r2.rake +37 -16
- data/syncassets_r2.gemspec +5 -6
- metadata +19 -19
data/README.rdoc
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
This rake task will update (delete and copy) all the files under
|
|
1
|
+
This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.
|
|
2
2
|
|
|
3
3
|
The rake task will verify if the local file exist on s3 and
|
|
4
4
|
if the local file have been modified since the upload to s3.
|
data/Rakefile
CHANGED
|
@@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem|
|
|
|
15
15
|
gem.name = "syncassets_r2"
|
|
16
16
|
gem.homepage = "http://github.com/uokesita/syncassets_r2"
|
|
17
17
|
gem.license = "MIT"
|
|
18
|
-
gem.summary = %
|
|
19
|
-
gem.description = %
|
|
18
|
+
gem.summary = %q{This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.}
|
|
19
|
+
gem.description = %q{This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.}
|
|
20
20
|
gem.email = "osledybazo@gmail.com"
|
|
21
21
|
gem.authors = ["Osledy Bazo"]
|
|
22
22
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.4.0
|
data/lib/syncassets_r2.rb
CHANGED
|
@@ -27,6 +27,12 @@ class Credentials
|
|
|
27
27
|
def self.bucket
|
|
28
28
|
Auth.root[Auth.env]['bucket']
|
|
29
29
|
end
|
|
30
|
+
def self.distribution_ids
|
|
31
|
+
unless Auth.root[Auth.env]['distribution_ids'].nil?
|
|
32
|
+
return Auth.root[Auth.env]['distribution_ids'].gsub(' ','').split(',')
|
|
33
|
+
end
|
|
34
|
+
[]
|
|
35
|
+
end
|
|
30
36
|
rescue
|
|
31
37
|
puts"syncassets_r3 : AWS Access Key Id needs a subscription for the service."
|
|
32
38
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require 'fog'
|
|
2
2
|
require 'syncassets_r2'
|
|
3
|
+
|
|
3
4
|
namespace :syncassets do
|
|
4
5
|
|
|
5
6
|
desc "Synchronize public folder with s3"
|
|
6
|
-
task :sync_s3_public_assets do
|
|
7
|
+
task :sync_s3_public_assets, :directory do |t, args|
|
|
7
8
|
puts "#########################################################"
|
|
8
|
-
puts "##
|
|
9
|
-
puts "## all the files under /public on s3, be patient "
|
|
9
|
+
puts "## Syncing folders and files with S3 ##"
|
|
10
10
|
puts "#########################################################"
|
|
11
11
|
|
|
12
12
|
@fog = Fog::Storage.new( :provider => 'AWS',
|
|
@@ -18,6 +18,7 @@ namespace :syncassets do
|
|
|
18
18
|
|
|
19
19
|
@files_for_invalidation = []
|
|
20
20
|
@distribution_ids = []
|
|
21
|
+
@root_directory = "#{args[:directory]}"
|
|
21
22
|
|
|
22
23
|
get_distribution_ids
|
|
23
24
|
upload_directory
|
|
@@ -32,14 +33,19 @@ namespace :syncassets do
|
|
|
32
33
|
|
|
33
34
|
def get_distribution_ids
|
|
34
35
|
get_cdn_connection
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
|
|
37
|
+
if Credentials.distribution_ids.empty?
|
|
38
|
+
distributions = @cdn.get_distribution_list()
|
|
39
|
+
distributions.body["DistributionSummary"].each do |distribution|
|
|
40
|
+
@distribution_ids << distribution["Id"]
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
@distribution_ids = Credentials.distribution_ids
|
|
39
44
|
end
|
|
40
45
|
end
|
|
41
46
|
|
|
42
|
-
def upload_directory(asset='/')
|
|
47
|
+
def upload_directory(asset = @root_directory || '/')
|
|
48
|
+
|
|
43
49
|
Dir.entries(File.join(Rails.root, 'public', asset)).each do |file|
|
|
44
50
|
next if file =~ /\A\./
|
|
45
51
|
|
|
@@ -52,7 +58,13 @@ namespace :syncassets do
|
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
def upload_file asset, file
|
|
55
|
-
|
|
61
|
+
|
|
62
|
+
if @root_directory.blank?
|
|
63
|
+
file_name = asset == "/" ? file : "#{asset}/#{file}".sub('/','')
|
|
64
|
+
else
|
|
65
|
+
file_name = asset == "/" ? file : "#{asset}/#{file}"
|
|
66
|
+
end
|
|
67
|
+
|
|
56
68
|
remote_file = get_remote_file(file_name)
|
|
57
69
|
|
|
58
70
|
if check_timestamps(file_name, remote_file)
|
|
@@ -84,18 +96,27 @@ namespace :syncassets do
|
|
|
84
96
|
end
|
|
85
97
|
|
|
86
98
|
def queue_file_for_invalidation asset, file
|
|
87
|
-
|
|
99
|
+
if @root_directory.blank?
|
|
100
|
+
path_to_file = asset == "/" ? "#{asset}#{file}" : "#{asset}/#{file}"
|
|
101
|
+
else
|
|
102
|
+
path_to_file = asset == "/" ? "/#{asset}#{file}" : "/#{asset}/#{file}"
|
|
103
|
+
end
|
|
88
104
|
@files_for_invalidation << path_to_file
|
|
89
105
|
puts "Queued for invalidation: #{path_to_file}"
|
|
106
|
+
if @files_for_invalidation.size == 200
|
|
107
|
+
invalidate_files
|
|
108
|
+
end
|
|
90
109
|
end
|
|
91
110
|
|
|
92
111
|
def invalidate_files
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
unless @files_for_invalidation.size < 1
|
|
113
|
+
get_cdn_connection
|
|
114
|
+
@distribution_ids.each do |id|
|
|
115
|
+
puts "Invalidating files of distribution #{id}"
|
|
116
|
+
@cdn.post_invalidation(id, @files_for_invalidation, caller_reference = Time.now.to_i.to_s)
|
|
117
|
+
puts "Invalidation list queued"
|
|
118
|
+
end
|
|
119
|
+
@files_for_invalidation.clear
|
|
99
120
|
end
|
|
100
121
|
end
|
|
101
122
|
|
data/syncassets_r2.gemspec
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{syncassets_r2}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.4.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Osledy Bazo"]
|
|
12
|
-
s.date = %q{2011-
|
|
13
|
-
s.description = %q{This rake task will update (delete and copy) all the files under
|
|
12
|
+
s.date = %q{2011-09-15}
|
|
13
|
+
s.description = %q{This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.}
|
|
14
14
|
s.email = %q{osledybazo@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
16
16
|
"LICENSE.txt",
|
|
@@ -34,15 +34,14 @@ Gem::Specification.new do |s|
|
|
|
34
34
|
s.homepage = %q{http://github.com/uokesita/syncassets_r2}
|
|
35
35
|
s.licenses = ["MIT"]
|
|
36
36
|
s.require_paths = ["lib"]
|
|
37
|
-
s.rubygems_version = %q{1.
|
|
38
|
-
s.summary = %q{This rake task will update (delete and copy) all the files under
|
|
37
|
+
s.rubygems_version = %q{1.4.2}
|
|
38
|
+
s.summary = %q{This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.}
|
|
39
39
|
s.test_files = [
|
|
40
40
|
"test/helper.rb",
|
|
41
41
|
"test/test_syncassets_r2.rb"
|
|
42
42
|
]
|
|
43
43
|
|
|
44
44
|
if s.respond_to? :specification_version then
|
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
46
45
|
s.specification_version = 3
|
|
47
46
|
|
|
48
47
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: syncassets_r2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
5
|
-
prerelease:
|
|
4
|
+
hash: 15
|
|
5
|
+
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 0.
|
|
8
|
+
- 4
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.4.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Osledy Bazo
|
|
@@ -15,13 +15,11 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-
|
|
18
|
+
date: 2011-09-15 00:00:00 -04:30
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
22
|
-
prerelease: false
|
|
23
22
|
type: :runtime
|
|
24
|
-
name: fog
|
|
25
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
|
26
24
|
none: false
|
|
27
25
|
requirements:
|
|
@@ -34,10 +32,10 @@ dependencies:
|
|
|
34
32
|
- 2
|
|
35
33
|
version: 0.7.2
|
|
36
34
|
requirement: *id001
|
|
37
|
-
- !ruby/object:Gem::Dependency
|
|
38
35
|
prerelease: false
|
|
36
|
+
name: fog
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
39
38
|
type: :development
|
|
40
|
-
name: shoulda
|
|
41
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
|
42
40
|
none: false
|
|
43
41
|
requirements:
|
|
@@ -48,10 +46,10 @@ dependencies:
|
|
|
48
46
|
- 0
|
|
49
47
|
version: "0"
|
|
50
48
|
requirement: *id002
|
|
51
|
-
- !ruby/object:Gem::Dependency
|
|
52
49
|
prerelease: false
|
|
50
|
+
name: shoulda
|
|
51
|
+
- !ruby/object:Gem::Dependency
|
|
53
52
|
type: :development
|
|
54
|
-
name: bundler
|
|
55
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
|
56
54
|
none: false
|
|
57
55
|
requirements:
|
|
@@ -64,10 +62,10 @@ dependencies:
|
|
|
64
62
|
- 0
|
|
65
63
|
version: 1.0.0
|
|
66
64
|
requirement: *id003
|
|
67
|
-
- !ruby/object:Gem::Dependency
|
|
68
65
|
prerelease: false
|
|
66
|
+
name: bundler
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
69
68
|
type: :development
|
|
70
|
-
name: jeweler
|
|
71
69
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
|
72
70
|
none: false
|
|
73
71
|
requirements:
|
|
@@ -80,10 +78,10 @@ dependencies:
|
|
|
80
78
|
- 2
|
|
81
79
|
version: 1.5.2
|
|
82
80
|
requirement: *id004
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
81
|
prerelease: false
|
|
82
|
+
name: jeweler
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
85
84
|
type: :development
|
|
86
|
-
name: rcov
|
|
87
85
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
|
88
86
|
none: false
|
|
89
87
|
requirements:
|
|
@@ -94,7 +92,9 @@ dependencies:
|
|
|
94
92
|
- 0
|
|
95
93
|
version: "0"
|
|
96
94
|
requirement: *id005
|
|
97
|
-
|
|
95
|
+
prerelease: false
|
|
96
|
+
name: rcov
|
|
97
|
+
description: This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.
|
|
98
98
|
email: osledybazo@gmail.com
|
|
99
99
|
executables: []
|
|
100
100
|
|
|
@@ -147,10 +147,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
147
|
requirements: []
|
|
148
148
|
|
|
149
149
|
rubyforge_project:
|
|
150
|
-
rubygems_version: 1.
|
|
150
|
+
rubygems_version: 1.4.2
|
|
151
151
|
signing_key:
|
|
152
152
|
specification_version: 3
|
|
153
|
-
summary: This rake task will update (delete and copy) all the files under
|
|
153
|
+
summary: This rake task will update (delete and copy) all the files under a directory to S3, by default is the public directory but you can pass as argument the path to the folder.
|
|
154
154
|
test_files:
|
|
155
155
|
- test/helper.rb
|
|
156
156
|
- test/test_syncassets_r2.rb
|