dpl-s3 1.9.2.travis.2737.5 → 1.9.2.travis.2748.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dpl/provider/s3.rb +37 -16
- data/spec/provider/s3_spec.rb +14 -17
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f853bd59ec5a942fe9b384d44d7a2d6003c889cd29c9e715566b4489fbd5f258
|
4
|
+
data.tar.gz: c8566920273400763dc38e11eb1cb7d057f989af54f8449a9a411b9a829a07a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5be8bae73fe0751548ea06f3f4c81a30230a8b996e22bc8c6a17748f1946e92d6dff11d5aa908c89cf13efcd2c8ceac52cb786cb53a36c4cc6fae15550b8cb5
|
7
|
+
data.tar.gz: 691b680708dd4cab9cc0ad2c070442746b220c9dd8861558f2569c061c6439a8deecfd2e0ee03edf45b749127b584d24a8aa120b1be30bbf645f5cf5d6cf58bd
|
data/lib/dpl/provider/s3.rb
CHANGED
@@ -41,23 +41,11 @@ module DPL
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def push_app
|
44
|
-
|
44
|
+
cwd = options.fetch(:local_dir, Dir.pwd)
|
45
|
+
glob_args = [cwd + "/**/*"]
|
45
46
|
glob_args << File::FNM_DOTMATCH if options[:dot_match]
|
46
|
-
Dir.
|
47
|
-
|
48
|
-
opts = content_data_for(filename)
|
49
|
-
opts[:cache_control] = get_option_value_by_filename(options[:cache_control], filename) if options[:cache_control]
|
50
|
-
opts[:acl] = options[:acl].gsub(/_/, '-') if options[:acl]
|
51
|
-
opts[:expires] = get_option_value_by_filename(options[:expires], filename) if options[:expires]
|
52
|
-
opts[:storage_class] = options[:storage_class] if options[:storage_class]
|
53
|
-
opts[:server_side_encryption] = "AES256" if options[:server_side_encryption]
|
54
|
-
unless File.directory?(filename)
|
55
|
-
log "uploading #{filename.inspect} with #{opts.inspect}"
|
56
|
-
result = api.bucket(option(:bucket)).object(upload_path(filename)).upload_file(filename, opts)
|
57
|
-
warn "error while uploading #{filename.inspect}" unless result
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
47
|
+
files = Dir.glob(*glob_args)
|
48
|
+
upload_multithreaded(files.reject {|f| File.directory?(f)})
|
61
49
|
|
62
50
|
if suffix = options[:index_document_suffix]
|
63
51
|
api.bucket(option(:bucket)).website.put(
|
@@ -70,6 +58,39 @@ module DPL
|
|
70
58
|
end
|
71
59
|
end
|
72
60
|
|
61
|
+
def upload_multithreaded(files, thread_count = 5)
|
62
|
+
file_number = 0
|
63
|
+
mutex = Mutex.new
|
64
|
+
threads = []
|
65
|
+
log "Beginning upload of #{files.length} files with #{thread_count} threads."
|
66
|
+
|
67
|
+
thread_count.times do |i|
|
68
|
+
threads[i] = Thread.new {
|
69
|
+
until files.empty?
|
70
|
+
mutex.synchronize do
|
71
|
+
file_number += 1
|
72
|
+
Thread.current["file_number"] = file_number
|
73
|
+
end
|
74
|
+
filename = files.pop rescue nil
|
75
|
+
next unless filename
|
76
|
+
|
77
|
+
opts = content_data_for(filename)
|
78
|
+
opts[:cache_control] = get_option_value_by_filename(options[:cache_control], filename) if options[:cache_control]
|
79
|
+
opts[:acl] = options[:acl].gsub(/_/, '-') if options[:acl]
|
80
|
+
opts[:expires] = get_option_value_by_filename(options[:expires], filename) if options[:expires]
|
81
|
+
opts[:storage_class] = options[:storage_class] if options[:storage_class]
|
82
|
+
opts[:server_side_encryption] = "AES256" if options[:server_side_encryption]
|
83
|
+
unless File.directory?(filename)
|
84
|
+
log "uploading #{filename.inspect} with #{opts.inspect}"
|
85
|
+
result = api.bucket(option(:bucket)).object(upload_path(filename)).upload_file(filename, opts)
|
86
|
+
warn "error while uploading #{filename.inspect}" unless result
|
87
|
+
end
|
88
|
+
end
|
89
|
+
}
|
90
|
+
end
|
91
|
+
threads.each { |t| t.join }
|
92
|
+
end
|
93
|
+
|
73
94
|
def deploy
|
74
95
|
super
|
75
96
|
rescue ::Aws::S3::Errors::InvalidAccessKeyId
|
data/spec/provider/s3_spec.rb
CHANGED
@@ -49,6 +49,8 @@ describe DPL::Provider::S3 do
|
|
49
49
|
|
50
50
|
before :each do
|
51
51
|
provider.stub(:s3_options).and_return(client_options)
|
52
|
+
allow_any_instance_of(::Aws::S3::Object).to receive(:upload_file).and_return(true)
|
53
|
+
allow(provider).to receive(:log).with(anything).and_return(true)
|
52
54
|
end
|
53
55
|
|
54
56
|
describe "#check_auth" do
|
@@ -80,27 +82,22 @@ describe DPL::Provider::S3 do
|
|
80
82
|
end
|
81
83
|
|
82
84
|
describe "#push_app" do
|
83
|
-
example "Without local_dir" do
|
84
|
-
expect(Dir).to receive(:chdir).with(Dir.pwd)
|
85
|
-
provider.push_app
|
86
|
-
end
|
87
|
-
|
88
85
|
example "With local_dir" do
|
89
|
-
|
90
|
-
|
91
|
-
expect(Dir).to receive(:
|
86
|
+
someDir = "/some/dir/"
|
87
|
+
provider.options.update(:local_dir => someDir)
|
88
|
+
expect(Dir).to receive(:glob).with(someDir + "/**/*").and_return([__FILE__])
|
92
89
|
provider.push_app
|
93
90
|
end
|
94
91
|
|
95
92
|
example "Sends MIME type" do
|
96
|
-
expect(Dir).to receive(:glob).
|
93
|
+
expect(Dir).to receive(:glob).and_return([__FILE__])
|
97
94
|
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:content_type => 'application/x-ruby'))
|
98
95
|
provider.push_app
|
99
96
|
end
|
100
97
|
|
101
98
|
example "Sets Cache and Expiration" do
|
102
99
|
provider.options.update(:cache_control => "max-age=99999999", :expires => "2012-12-21 00:00:00 -0000")
|
103
|
-
expect(Dir).to receive(:glob).
|
100
|
+
expect(Dir).to receive(:glob).and_return([__FILE__])
|
104
101
|
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:cache_control => 'max-age=99999999', :expires => '2012-12-21 00:00:00 -0000'))
|
105
102
|
provider.push_app
|
106
103
|
end
|
@@ -108,7 +105,7 @@ describe DPL::Provider::S3 do
|
|
108
105
|
example "Sets different Cache and Expiration" do
|
109
106
|
option_list = []
|
110
107
|
provider.options.update(:cache_control => ["max-age=99999999", "no-cache" => ["foo.html", "bar.txt"], "max-age=9999" => "*.txt"], :expires => ["2012-12-21 00:00:00 -0000", "1970-01-01 00:00:00 -0000" => "*.html"])
|
111
|
-
expect(Dir).to receive(:glob).
|
108
|
+
expect(Dir).to receive(:glob).and_return(%w(foo.html bar.txt baz.js))
|
112
109
|
allow_any_instance_of(Aws::S3::Object).to receive(:upload_file) do |obj, _data, options|
|
113
110
|
option_list << { key: obj.key, options: options }
|
114
111
|
end
|
@@ -122,28 +119,28 @@ describe DPL::Provider::S3 do
|
|
122
119
|
|
123
120
|
example "Sets ACL" do
|
124
121
|
provider.options.update(:acl => "public_read")
|
125
|
-
expect(Dir).to receive(:glob).
|
122
|
+
expect(Dir).to receive(:glob).and_return([__FILE__])
|
126
123
|
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:acl => "public-read"))
|
127
124
|
provider.push_app
|
128
125
|
end
|
129
126
|
|
130
127
|
example "Sets Storage Class" do
|
131
128
|
provider.options.update(:storage_class => "STANDARD_AI")
|
132
|
-
expect(Dir).to receive(:glob).
|
129
|
+
expect(Dir).to receive(:glob).and_return([__FILE__])
|
133
130
|
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:storage_class => "STANDARD_AI"))
|
134
131
|
provider.push_app
|
135
132
|
end
|
136
133
|
|
137
134
|
example "Sets SSE" do
|
138
135
|
provider.options.update(:server_side_encryption => true)
|
139
|
-
expect(Dir).to receive(:glob).
|
136
|
+
expect(Dir).to receive(:glob).and_return([__FILE__])
|
140
137
|
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:server_side_encryption => "AES256"))
|
141
138
|
provider.push_app
|
142
139
|
end
|
143
140
|
|
144
141
|
example "Sets Website Index Document" do
|
145
142
|
provider.options.update(:index_document_suffix => "test/index.html")
|
146
|
-
expect(Dir).to receive(:glob).
|
143
|
+
expect(Dir).to receive(:glob).and_return([__FILE__])
|
147
144
|
expect_any_instance_of(Aws::S3::BucketWebsite).to receive(:put).with(:website_configuration => { :index_document => { :suffix => "test/index.html" } })
|
148
145
|
provider.push_app
|
149
146
|
end
|
@@ -151,7 +148,7 @@ describe DPL::Provider::S3 do
|
|
151
148
|
example "when detect_encoding is set" do
|
152
149
|
path = 'foo.js'
|
153
150
|
provider.options.update(:detect_encoding => true)
|
154
|
-
expect(Dir).to receive(:glob).
|
151
|
+
expect(Dir).to receive(:glob).and_return([path])
|
155
152
|
expect(provider).to receive(:`).at_least(1).times.with("file '#{path}'").and_return('gzip compressed')
|
156
153
|
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:content_encoding => 'gzip'))
|
157
154
|
provider.push_app
|
@@ -159,7 +156,7 @@ describe DPL::Provider::S3 do
|
|
159
156
|
|
160
157
|
example "when dot_match is set" do
|
161
158
|
provider.options.update(:dot_match => true)
|
162
|
-
expect(Dir).to receive(:glob).with("
|
159
|
+
expect(Dir).to receive(:glob).with(Dir.pwd + "/**/*", File::FNM_DOTMATCH).and_return([__FILE__])
|
163
160
|
provider.push_app
|
164
161
|
end
|
165
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dpl-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.2.travis.
|
4
|
+
version: 1.9.2.travis.2748.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dpl
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.9.2.travis.
|
19
|
+
version: 1.9.2.travis.2748.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.9.2.travis.
|
26
|
+
version: 1.9.2.travis.2748.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: aws-sdk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|