dockly 2.7.2 → 3.0.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/Gemfile +0 -3
- data/dockly.gemspec +1 -2
- data/lib/dockly.rb +41 -16
- data/lib/dockly/build_cache/base.rb +12 -8
- data/lib/dockly/deb.rb +10 -5
- data/lib/dockly/docker.rb +17 -19
- data/lib/dockly/rake_task.rb +131 -136
- data/lib/dockly/s3_writer.rb +79 -0
- data/lib/dockly/util/git.rb +32 -7
- data/lib/dockly/version.rb +6 -1
- data/spec/dockly/build_cache/base_spec.rb +15 -7
- data/spec/dockly/build_cache/local_spec.rb +1 -1
- data/spec/dockly/deb_spec.rb +13 -9
- data/spec/dockly/docker_spec.rb +5 -3
- data/spec/dockly/history_spec.rb +1 -1
- data/spec/dockly/rpm_spec.rb +13 -9
- data/spec/dockly/s3_writer_spec.rb +139 -0
- data/spec/dockly/util/git_spec.rb +38 -0
- data/spec/spec_helper.rb +0 -4
- metadata +10 -27
- data/lib/dockly/aws.rb +0 -62
- data/lib/dockly/aws/s3_writer.rb +0 -59
- data/spec/dockly/aws/s3_writer_spec.rb +0 -154
- data/spec/dockly/aws_spec.rb +0 -17
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dockly::Util::Git do
|
4
|
+
describe '#repo' do
|
5
|
+
it 'returns the repo for the current directory' do
|
6
|
+
expect(subject.repo.workdir).to eq(File.expand_path('.') + '/')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#sha' do
|
11
|
+
it 'returns a shortened sha for the head object' do
|
12
|
+
expect(subject.sha).to eq(`git rev-parse --short HEAD`[0..6])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#ls_files' do
|
17
|
+
it 'returns an Array of the files for the given OID' do
|
18
|
+
expect(subject.ls_files(subject.sha).map { |hash| hash[:name] }.sort)
|
19
|
+
.to eq(`git ls-files`.split("\n").sort)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#archive' do
|
24
|
+
let(:io) { StringIO.new }
|
25
|
+
let(:prefix) { '/gem/dockly' }
|
26
|
+
let(:reader) { Gem::Package::TarReader.new(io.tap(&:rewind)) }
|
27
|
+
|
28
|
+
it 'archives the current directory into the given IO' do
|
29
|
+
subject.archive(subject.sha, prefix, io)
|
30
|
+
reader.each do |entry|
|
31
|
+
expect(entry.full_name).to start_with(prefix)
|
32
|
+
orig = entry.full_name.gsub(/\A#{prefix}\//, '')
|
33
|
+
expect(File.exist?(orig)).to be_true
|
34
|
+
expect(entry.read).to eq(File.read(orig)) if orig.end_with?('.rb')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,10 +5,6 @@ require 'rspec'
|
|
5
5
|
require 'dockly'
|
6
6
|
require 'pry'
|
7
7
|
|
8
|
-
Fog.mock!
|
9
|
-
|
10
|
-
Dockly::AWS.aws_access_key_id = 'MOCK_KEY'
|
11
|
-
Dockly::AWS.aws_secret_access_key = 'MOCK_SECRET'
|
12
8
|
Dockly::Util::Logger.disable! unless ENV['ENABLE_LOGGER'] == 'true'
|
13
9
|
|
14
10
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clamp
|
@@ -76,13 +76,13 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: aws-sdk
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
85
|
+
version: '2.0'
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
93
|
+
version: '2.0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: foreman
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,22 +123,6 @@ dependencies:
|
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: 1.2.0
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: grit
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ! '>='
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '0'
|
134
|
-
type: :runtime
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
|
-
requirements:
|
139
|
-
- - ! '>='
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '0'
|
142
126
|
- !ruby/object:Gem::Dependency
|
143
127
|
name: rugged
|
144
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,8 +258,6 @@ files:
|
|
274
258
|
- dockly.gemspec
|
275
259
|
- img/dockly.png
|
276
260
|
- lib/dockly.rb
|
277
|
-
- lib/dockly/aws.rb
|
278
|
-
- lib/dockly/aws/s3_writer.rb
|
279
261
|
- lib/dockly/bash_builder.rb
|
280
262
|
- lib/dockly/build_cache.rb
|
281
263
|
- lib/dockly/build_cache/base.rb
|
@@ -289,6 +271,7 @@ files:
|
|
289
271
|
- lib/dockly/history.rb
|
290
272
|
- lib/dockly/rake_task.rb
|
291
273
|
- lib/dockly/rpm.rb
|
274
|
+
- lib/dockly/s3_writer.rb
|
292
275
|
- lib/dockly/tar_diff.rb
|
293
276
|
- lib/dockly/util/git.rb
|
294
277
|
- lib/dockly/util/tar.rb
|
@@ -305,8 +288,6 @@ files:
|
|
305
288
|
- snippets/registry_import.erb
|
306
289
|
- snippets/s3_diff_docker_import.erb
|
307
290
|
- snippets/s3_docker_import.erb
|
308
|
-
- spec/dockly/aws/s3_writer_spec.rb
|
309
|
-
- spec/dockly/aws_spec.rb
|
310
291
|
- spec/dockly/bash_builder_spec.rb
|
311
292
|
- spec/dockly/build_cache/base_spec.rb
|
312
293
|
- spec/dockly/build_cache/docker_spec.rb
|
@@ -318,7 +299,9 @@ files:
|
|
318
299
|
- spec/dockly/foreman_spec.rb
|
319
300
|
- spec/dockly/history_spec.rb
|
320
301
|
- spec/dockly/rpm_spec.rb
|
302
|
+
- spec/dockly/s3_writer_spec.rb
|
321
303
|
- spec/dockly/tar_diff_spec.rb
|
304
|
+
- spec/dockly/util/git_spec.rb
|
322
305
|
- spec/dockly_spec.rb
|
323
306
|
- spec/fixtures/Procfile
|
324
307
|
- spec/fixtures/Rakefile
|
@@ -355,8 +338,6 @@ signing_key:
|
|
355
338
|
specification_version: 3
|
356
339
|
summary: Packaging made easy
|
357
340
|
test_files:
|
358
|
-
- spec/dockly/aws/s3_writer_spec.rb
|
359
|
-
- spec/dockly/aws_spec.rb
|
360
341
|
- spec/dockly/bash_builder_spec.rb
|
361
342
|
- spec/dockly/build_cache/base_spec.rb
|
362
343
|
- spec/dockly/build_cache/docker_spec.rb
|
@@ -368,7 +349,9 @@ test_files:
|
|
368
349
|
- spec/dockly/foreman_spec.rb
|
369
350
|
- spec/dockly/history_spec.rb
|
370
351
|
- spec/dockly/rpm_spec.rb
|
352
|
+
- spec/dockly/s3_writer_spec.rb
|
371
353
|
- spec/dockly/tar_diff_spec.rb
|
354
|
+
- spec/dockly/util/git_spec.rb
|
372
355
|
- spec/dockly_spec.rb
|
373
356
|
- spec/fixtures/Procfile
|
374
357
|
- spec/fixtures/Rakefile
|
data/lib/dockly/aws.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'fog/aws'
|
2
|
-
|
3
|
-
# This module holds the connections for all AWS services used by the gem.
|
4
|
-
module Dockly::AWS
|
5
|
-
extend self
|
6
|
-
|
7
|
-
autoload :S3Writer, 'dockly/aws/s3_writer'
|
8
|
-
|
9
|
-
def service(name, klass)
|
10
|
-
define_method name do
|
11
|
-
if val = instance_variable_get(:"@#{name}")
|
12
|
-
val
|
13
|
-
else
|
14
|
-
instance = klass.new(creds)
|
15
|
-
instance_variable_set(:"@#{name}", instance)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
services << name
|
19
|
-
end
|
20
|
-
|
21
|
-
def services
|
22
|
-
@services ||= []
|
23
|
-
end
|
24
|
-
|
25
|
-
def env_attr(*names)
|
26
|
-
names.each do |name|
|
27
|
-
define_method name do
|
28
|
-
instance_variable_get(:"@#{name}") || ENV[name.to_s.upcase]
|
29
|
-
end
|
30
|
-
|
31
|
-
define_method :"#{name}=" do |val|
|
32
|
-
reset_cache!
|
33
|
-
instance_variable_set(:"@#{name}", val)
|
34
|
-
end
|
35
|
-
|
36
|
-
env_attrs << name
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def env_attrs
|
41
|
-
@env_attrs ||= []
|
42
|
-
end
|
43
|
-
|
44
|
-
def creds
|
45
|
-
attrs = Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
|
46
|
-
if attrs.empty?
|
47
|
-
if ENV['FOG_CREDENTIAL']
|
48
|
-
attrs = {} # let Fog use the env var
|
49
|
-
else
|
50
|
-
attrs = { :use_iam_profile => true }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
attrs
|
54
|
-
end
|
55
|
-
|
56
|
-
def reset_cache!
|
57
|
-
services.each { |service| instance_variable_set(:"@#{service}", nil) }
|
58
|
-
end
|
59
|
-
|
60
|
-
service :s3, Fog::Storage::AWS
|
61
|
-
env_attr :aws_access_key_id, :aws_secret_access_key
|
62
|
-
end
|
data/lib/dockly/aws/s3_writer.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module Dockly
|
2
|
-
module AWS
|
3
|
-
class S3Writer
|
4
|
-
include Dockly::Util::Logger::Mixin
|
5
|
-
|
6
|
-
logger_prefix '[dockly s3writer]'
|
7
|
-
|
8
|
-
attr_accessor :buffer
|
9
|
-
attr_reader :connection, :s3_bucket, :s3_object, :upload_id
|
10
|
-
|
11
|
-
def initialize(connection, s3_bucket, s3_object)
|
12
|
-
@connection = connection
|
13
|
-
@s3_bucket = s3_bucket
|
14
|
-
@s3_object = s3_object
|
15
|
-
@parts = []
|
16
|
-
@closed = false
|
17
|
-
@buffer = ""
|
18
|
-
|
19
|
-
init_upload_res = connection.initiate_multipart_upload(s3_bucket, s3_object)
|
20
|
-
@upload_id = init_upload_res.body['UploadId']
|
21
|
-
end
|
22
|
-
|
23
|
-
def upload_buffer
|
24
|
-
res = connection.upload_part(s3_bucket, s3_object, upload_id, @parts.size + 1, buffer)
|
25
|
-
@parts << res.headers["ETag"]
|
26
|
-
debug "Writing a chunk"
|
27
|
-
@buffer = ""
|
28
|
-
end
|
29
|
-
|
30
|
-
def write(chunk)
|
31
|
-
self.buffer << chunk
|
32
|
-
|
33
|
-
upload_buffer if buffer.bytesize > 5242880
|
34
|
-
|
35
|
-
chunk.length
|
36
|
-
end
|
37
|
-
|
38
|
-
def close
|
39
|
-
return if @closed
|
40
|
-
upload_buffer unless buffer.empty?
|
41
|
-
|
42
|
-
res = connection.complete_multipart_upload(s3_bucket, s3_object, upload_id, @parts)
|
43
|
-
if res.body['Code'] || res.body['Message']
|
44
|
-
raise "Failed to upload to S3: #{res.body['Code']}: #{res.body['Message']}"
|
45
|
-
end
|
46
|
-
@closed = true
|
47
|
-
end
|
48
|
-
|
49
|
-
def abort
|
50
|
-
connection.abort_multipart_upload(s3_bucket, s3_object, upload_id)
|
51
|
-
end
|
52
|
-
|
53
|
-
def abort_unless_closed
|
54
|
-
abort unless @closed
|
55
|
-
@closed = true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dockly::AWS::S3Writer do
|
4
|
-
let(:connection) { double(:connection) }
|
5
|
-
let(:bucket) { 'test_bucket' }
|
6
|
-
let(:object) { 'object_name.tar' }
|
7
|
-
let(:initiate_response) { double(:initiate_response) }
|
8
|
-
let(:upload_id) { 'test_id' }
|
9
|
-
|
10
|
-
subject { described_class.new(connection, bucket, object) }
|
11
|
-
|
12
|
-
before do
|
13
|
-
connection.should_receive(:initiate_multipart_upload) { initiate_response }
|
14
|
-
initiate_response.stub(:body) { { 'UploadId' => upload_id } }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe ".new" do
|
18
|
-
|
19
|
-
it "sets the connection, s3_bucket, s3_object, and upload_id" do
|
20
|
-
expect(subject.connection).to eq(connection)
|
21
|
-
expect(subject.s3_bucket).to eq(bucket)
|
22
|
-
expect(subject.s3_object).to eq(object)
|
23
|
-
expect(subject.upload_id).to eq(upload_id)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#upload_buffer" do
|
28
|
-
let(:message) { "message" }
|
29
|
-
let(:upload_response) { double(:upload_response) }
|
30
|
-
let(:etag) { "test" }
|
31
|
-
|
32
|
-
before do
|
33
|
-
connection.should_receive(:upload_part).with(bucket, object, upload_id, 1, message) do
|
34
|
-
upload_response
|
35
|
-
end
|
36
|
-
upload_response.stub(:headers) { { "ETag" => etag } }
|
37
|
-
subject.instance_variable_set(:"@buffer", message)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "connects to S3" do
|
41
|
-
subject.upload_buffer
|
42
|
-
expect(subject.instance_variable_get(:"@parts")).to include(etag)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#write" do
|
47
|
-
let(:message) { "a" * chunk_length }
|
48
|
-
|
49
|
-
context "with a buffer of less than 5 MB" do
|
50
|
-
let(:chunk_length) { 100 }
|
51
|
-
|
52
|
-
before do
|
53
|
-
subject.should_not_receive(:upload_buffer)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "adds it to the buffer and returns the chunk length" do
|
57
|
-
expect(subject.write(message)).to eq(chunk_length)
|
58
|
-
expect(subject.instance_variable_get(:"@buffer")).to eq(message)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "with a buffer of greater than 5 MB" do
|
63
|
-
let(:chunk_length) { 1 + 5 * 1024 * 1024 }
|
64
|
-
|
65
|
-
before do
|
66
|
-
subject.should_receive(:upload_buffer)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "adds it to the buffer, writes to S3 and returns the chunk length" do
|
70
|
-
expect(subject.write(message)).to eq(chunk_length)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#close" do
|
76
|
-
let(:complete_response) { double(:complete_response) }
|
77
|
-
|
78
|
-
before do
|
79
|
-
connection.should_receive(:complete_multipart_upload).with(bucket, object, upload_id, []) do
|
80
|
-
complete_response
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when it passes" do
|
85
|
-
before do
|
86
|
-
complete_response.stub(:body) { {} }
|
87
|
-
end
|
88
|
-
|
89
|
-
context "when the buffer is not empty" do
|
90
|
-
before do
|
91
|
-
subject.instance_variable_set(:"@buffer", "text")
|
92
|
-
subject.should_receive(:upload_buffer)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "uploads the rest of the buffer and closes the connection" do
|
96
|
-
expect(subject.close).to be_true
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when the buffer is empty" do
|
101
|
-
before do
|
102
|
-
subject.should_not_receive(:upload_buffer)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "closes the connection" do
|
106
|
-
expect(subject.close).to be_true
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "when it fails" do
|
112
|
-
before do
|
113
|
-
complete_response.stub(:body) { { 'Code' => 20, 'Message' => 'Msggg' } }
|
114
|
-
end
|
115
|
-
|
116
|
-
it "raises an error" do
|
117
|
-
expect { subject.close }.to raise_error("Failed to upload to S3: 20: Msggg")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#abort" do
|
123
|
-
before do
|
124
|
-
connection.should_receive(:abort_multipart_upload).with(bucket, object, upload_id)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "aborts the upload" do
|
128
|
-
subject.abort
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe "#abort_unless_closed" do
|
133
|
-
context "when the upload is closed" do
|
134
|
-
before do
|
135
|
-
subject.should_not_receive(:abort)
|
136
|
-
subject.instance_variable_set(:"@closed", true)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "does not abort" do
|
140
|
-
subject.abort_unless_closed
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "when the upload is open" do
|
145
|
-
before do
|
146
|
-
subject.should_receive(:abort)
|
147
|
-
end
|
148
|
-
|
149
|
-
it "aborts the upload" do
|
150
|
-
subject.abort_unless_closed
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
data/spec/dockly/aws_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dockly::AWS do
|
4
|
-
subject { Dockly::AWS }
|
5
|
-
|
6
|
-
describe '#reset_cache!' do
|
7
|
-
before do
|
8
|
-
subject.instance_variable_set(:@s3, double)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'sets @s3 to nil' do
|
12
|
-
expect { subject.reset_cache! }
|
13
|
-
.to change { subject.instance_variable_get(:@s3) }
|
14
|
-
.to(nil)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|