dockly 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/dockly/docker.rb +22 -3
- data/lib/dockly/version.rb +1 -1
- data/spec/dockly/build_cache/docker_spec.rb +4 -4
- data/spec/dockly/deb_spec.rb +1 -1
- data/spec/dockly/docker_spec.rb +9 -8
- metadata +2 -2
data/README.md
CHANGED
@@ -111,6 +111,9 @@ The `docker` DSL is used to define Docker containers. It has the following attri
|
|
111
111
|
- required: `false` -- only required when `import` is not supplied
|
112
112
|
- description: the location of the base image to start building from
|
113
113
|
- examples: `paintedfox/ruby`, `registry.example.com/my-custom-image`
|
114
|
+
- `build_env`
|
115
|
+
- required: `false`
|
116
|
+
- description: Hash whose values are environment variables and keys are their values. These variables are only used during build commands, exported images will not contain them.
|
114
117
|
- `import`
|
115
118
|
- required: `false` -- only required when `registry_import` is not supplied
|
116
119
|
- description: the location (url or S3 path) of the base image to start building from
|
data/lib/dockly/docker.rb
CHANGED
@@ -28,6 +28,10 @@ class Dockly::Docker
|
|
28
28
|
default_value :s3_bucket, nil
|
29
29
|
default_value :s3_object_prefix, ""
|
30
30
|
|
31
|
+
def build_env(hash = nil)
|
32
|
+
(@build_env ||= {}).tap { |env| env.merge!(hash) if hash.is_a?(Hash) }
|
33
|
+
end
|
34
|
+
|
31
35
|
def generate!
|
32
36
|
image = generate_build
|
33
37
|
export_image(image)
|
@@ -50,9 +54,10 @@ class Dockly::Docker
|
|
50
54
|
info "Successfully pulled #{full_name}"
|
51
55
|
end
|
52
56
|
|
53
|
-
images[:two] =
|
54
|
-
images[:three] =
|
55
|
-
|
57
|
+
images[:two] = add_build_env(images[:one])
|
58
|
+
images[:three] = add_git_archive(images[:two])
|
59
|
+
images[:four] = run_build_caches(images[:three])
|
60
|
+
build_image(images[:four])
|
56
61
|
ensure
|
57
62
|
cleanup(images.values.compact) if cleanup_images
|
58
63
|
end
|
@@ -69,6 +74,8 @@ class Dockly::Docker
|
|
69
74
|
|
70
75
|
def cleanup(images)
|
71
76
|
info 'Cleaning up intermediate images'
|
77
|
+
images ||= []
|
78
|
+
images = images.compact
|
72
79
|
::Docker::Container.all(:all => true).each do |container|
|
73
80
|
image_id = container.json['Image']
|
74
81
|
if images.any? { |image| image.id.start_with?(image_id) || image_id.start_with?(image.id) }
|
@@ -144,6 +151,18 @@ class Dockly::Docker
|
|
144
151
|
image
|
145
152
|
end
|
146
153
|
|
154
|
+
def add_build_env(image)
|
155
|
+
return image if build_env.empty?
|
156
|
+
info "Setting the following environment variables in the docker image: #{build_env.keys}"
|
157
|
+
dockerfile = [
|
158
|
+
"FROM #{image.id}",
|
159
|
+
*build_env.map { |key, val| "ENV #{key.to_s.shellescape}=#{val.to_s.shellescape}" }
|
160
|
+
].join("\n")
|
161
|
+
out_image = ::Docker::Image.build(dockerfile)
|
162
|
+
info "Successfully set the environment variables in the dockerfile"
|
163
|
+
out_image
|
164
|
+
end
|
165
|
+
|
147
166
|
def add_git_archive(image)
|
148
167
|
return image if git_archive.nil?
|
149
168
|
info "adding the git archive"
|
data/lib/dockly/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe Dockly::BuildCache::Docker, :docker do
|
|
7
7
|
git_archive '/app'
|
8
8
|
end
|
9
9
|
end
|
10
|
-
let(:image) { ::Docker::Image.build('from
|
10
|
+
let(:image) { ::Docker::Image.build('from ubuntu:14.04') }
|
11
11
|
|
12
12
|
before do
|
13
13
|
build_cache.s3_bucket 'lol'
|
@@ -100,7 +100,7 @@ describe Dockly::BuildCache::Docker, :docker do
|
|
100
100
|
|
101
101
|
describe '#hash_output' do
|
102
102
|
let(:output) {
|
103
|
-
"
|
103
|
+
"b458e7b28b9bc2d04bd5a3fd0f8d777e /etc/vim/vimrc"
|
104
104
|
}
|
105
105
|
|
106
106
|
context "when hash command returns successfully" do
|
@@ -127,7 +127,7 @@ describe Dockly::BuildCache::Docker, :docker do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
describe '#copy_output_dir' do
|
130
|
-
let(:container) { Docker::Container.create('Image' => '
|
130
|
+
let(:container) { Docker::Container.create('Image' => 'ubuntu:14.04', 'Cmd' => %w[true]) }
|
131
131
|
let(:file) { build_cache.copy_output_dir(container) }
|
132
132
|
let(:hash) { 'this_really_unique_hash' }
|
133
133
|
let(:path) { file.path }
|
@@ -156,7 +156,7 @@ describe Dockly::BuildCache::Docker, :docker do
|
|
156
156
|
context "when parameter command returns successfully" do
|
157
157
|
let(:command) { "uname -r" }
|
158
158
|
it 'returns the output of the parameter_command' do
|
159
|
-
expect(build_cache.parameter_output(command)).to match(/\A3\.\d{2}\.\d-\d-
|
159
|
+
expect(build_cache.parameter_output(command)).to match(/\A3\.\d{2}\.\d-\d{2}-generic\Z/)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
data/spec/dockly/deb_spec.rb
CHANGED
data/spec/dockly/docker_spec.rb
CHANGED
@@ -148,7 +148,7 @@ describe Dockly::Docker do
|
|
148
148
|
end
|
149
149
|
|
150
150
|
describe "#export_image", :docker do
|
151
|
-
let(:image) { Docker::Image.create('fromImage' => '
|
151
|
+
let(:image) { Docker::Image.create('fromImage' => 'ubuntu:14.04') }
|
152
152
|
|
153
153
|
context "with a registry export" do
|
154
154
|
let(:registry) { double(:registry) }
|
@@ -250,7 +250,7 @@ describe Dockly::Docker do
|
|
250
250
|
let(:docker_file) { 'build/docker/dockly_test-image.tgz' }
|
251
251
|
before { FileUtils.rm_rf(docker_file) }
|
252
252
|
|
253
|
-
context '
|
253
|
+
context 'with cleaning up' do
|
254
254
|
before do
|
255
255
|
subject.instance_eval do
|
256
256
|
import 'https://s3.amazonaws.com/swipely-pub/docker-export-ubuntu-latest.tgz'
|
@@ -258,7 +258,7 @@ describe Dockly::Docker do
|
|
258
258
|
build "run touch /it_worked"
|
259
259
|
repository 'dockly_test'
|
260
260
|
build_dir 'build/docker'
|
261
|
-
cleanup_images
|
261
|
+
cleanup_images true
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
@@ -276,19 +276,20 @@ describe Dockly::Docker do
|
|
276
276
|
paths.should include('sbin/init')
|
277
277
|
paths.should include('lib/dockly.rb')
|
278
278
|
paths.should include('it_worked')
|
279
|
-
}.
|
279
|
+
}.to_not change { ::Docker::Image.all(:all => true).length }
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
|
-
context '
|
283
|
+
context 'without cleaning up' do
|
284
284
|
before do
|
285
285
|
subject.instance_eval do
|
286
286
|
import 'https://s3.amazonaws.com/swipely-pub/docker-export-ubuntu-latest.tgz'
|
287
287
|
git_archive '.'
|
288
|
-
|
288
|
+
build_env 'TEST_FILE' => 'it_worked'
|
289
|
+
build "run touch $TEST_FILE"
|
289
290
|
repository 'dockly_test'
|
290
291
|
build_dir 'build/docker'
|
291
|
-
cleanup_images
|
292
|
+
cleanup_images false
|
292
293
|
end
|
293
294
|
end
|
294
295
|
|
@@ -306,7 +307,7 @@ describe Dockly::Docker do
|
|
306
307
|
paths.should include('sbin/init')
|
307
308
|
paths.should include('lib/dockly.rb')
|
308
309
|
paths.should include('it_worked')
|
309
|
-
}.
|
310
|
+
}.to change { ::Docker::Image.all(:all => true).length }.by(4)
|
310
311
|
end
|
311
312
|
end
|
312
313
|
|
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: 2.
|
4
|
+
version: 2.2.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-
|
12
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clamp
|