dockistrano 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dockistrano/cli.rb +1 -1
- data/lib/dockistrano/service.rb +21 -12
- data/lib/dockistrano/service_dependency.rb +9 -2
- data/lib/dockistrano/version.rb +1 -1
- data/spec/dockistrano/cli_spec.rb +4 -0
- data/spec/dockistrano/service_dependency_spec.rb +6 -0
- data/spec/dockistrano/service_spec.rb +31 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 158d3061ea38673eaf98d564749fc35d959d304b
|
4
|
+
data.tar.gz: 6c106bbf2921d25169e3c1b0c2ed8e783755fdbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d77e9bfa8f228b922b55d0e874cbd13fecd18a6a9c8ca7c80f25653981615984cd0d3c212afa4fe0ddb93b0181ecba6b2314986103dc990f23186957dbb8063
|
7
|
+
data.tar.gz: 6664a8a469961282bcccf1dacf140cc7e68de7b699011e324cad4d89e1fc2d825c0319ee81f66dace7f1bc1783f915c9a7f918f631006e9a28e16b51c859bcae
|
data/lib/dockistrano/cli.rb
CHANGED
@@ -81,7 +81,7 @@ module Dockistrano
|
|
81
81
|
|
82
82
|
desc "pull", "Pull new versions of dependencies"
|
83
83
|
def pull
|
84
|
-
current_service.backing_services.each do |name, service|
|
84
|
+
current_service.backing_services(initialize: false).each do |name, service|
|
85
85
|
if service.newer_version_available?
|
86
86
|
service.pull
|
87
87
|
say_status "Pulled", name
|
data/lib/dockistrano/service.rb
CHANGED
@@ -77,6 +77,10 @@ module Dockistrano
|
|
77
77
|
"#{registry}/#{image_name}:#{tag}"
|
78
78
|
end
|
79
79
|
|
80
|
+
def full_image_name_with_fallback
|
81
|
+
"#{registry}/#{image_name}:#{tag_with_fallback}"
|
82
|
+
end
|
83
|
+
|
80
84
|
# Builds a new image for this service
|
81
85
|
def build
|
82
86
|
previous_image_id = image_id
|
@@ -175,26 +179,28 @@ module Dockistrano
|
|
175
179
|
|
176
180
|
# Runs a command in this container
|
177
181
|
def run(command, options={})
|
178
|
-
Docker.run(
|
182
|
+
Docker.run(full_image_name_with_fallback, command: command, e: environment_variables, v: volumes, p: ports)
|
179
183
|
end
|
180
184
|
|
181
185
|
# Executes a command in this container
|
182
186
|
def exec(command, options={})
|
183
187
|
create_data_directories
|
184
|
-
Docker.exec(
|
188
|
+
Docker.exec(full_image_name_with_fallback, command: command, e: environment_variables, v: volumes, p: ports)
|
185
189
|
end
|
186
190
|
|
187
191
|
# Starts a console in the docker container
|
188
192
|
def console(command, options={})
|
189
193
|
create_data_directories
|
190
|
-
Docker.console(
|
194
|
+
Docker.console(full_image_name_with_fallback, command: command, e: environment_variables, v: volumes, p: ports)
|
191
195
|
end
|
192
196
|
|
193
197
|
# Lists all backing services for this service
|
194
|
-
def backing_services
|
198
|
+
def backing_services(options={})
|
199
|
+
initialize = options.delete(:initialize)
|
200
|
+
initialize = true if initialize.nil?
|
195
201
|
@backing_services ||= {}.tap do |hash|
|
196
202
|
dependencies.collect do |name, config|
|
197
|
-
hash[name] = ServiceDependency.factory(self, name, config)
|
203
|
+
hash[name] = ServiceDependency.factory(self, name, config, initialize)
|
198
204
|
end
|
199
205
|
end
|
200
206
|
end
|
@@ -215,10 +221,9 @@ module Dockistrano
|
|
215
221
|
vars["#{name.upcase}_#{k.upcase}"] = v
|
216
222
|
end
|
217
223
|
|
218
|
-
vars.merge!(backing_service.
|
224
|
+
vars.merge!(backing_service.provided_environment_variables)
|
219
225
|
end
|
220
226
|
|
221
|
-
vars.merge!(provides_env)
|
222
227
|
vars.each do |key, value|
|
223
228
|
vars.each do |replacement_key, replacement_value|
|
224
229
|
unless vars[key].nil? or replacement_value.nil?
|
@@ -230,6 +235,10 @@ module Dockistrano
|
|
230
235
|
vars
|
231
236
|
end
|
232
237
|
|
238
|
+
def provided_environment_variables
|
239
|
+
provides_env
|
240
|
+
end
|
241
|
+
|
233
242
|
# Returns the mounted volumes for this service
|
234
243
|
def volumes
|
235
244
|
[].tap do |volumes|
|
@@ -247,7 +256,7 @@ module Dockistrano
|
|
247
256
|
# Returns a list of available tags in the registry for the image
|
248
257
|
def available_tags
|
249
258
|
@available_tags ||= begin
|
250
|
-
registry_instance.tags_for_image(
|
259
|
+
registry_instance.tags_for_image(image_name)
|
251
260
|
rescue Dockistrano::Registry::RepositoryNotFoundInRegistry
|
252
261
|
[]
|
253
262
|
end
|
@@ -268,7 +277,7 @@ module Dockistrano
|
|
268
277
|
if final_tag
|
269
278
|
final_tag
|
270
279
|
else
|
271
|
-
raise NoTagFoundForImage.new("No tag found for image #{image_name}, available tags: #{available_tags}")
|
280
|
+
raise NoTagFoundForImage.new("No tag found for image #{image_name}, wanted tag #{tag}, available tags: #{available_tags}")
|
272
281
|
end
|
273
282
|
end
|
274
283
|
|
@@ -294,18 +303,18 @@ module Dockistrano
|
|
294
303
|
|
295
304
|
def create_data_directories
|
296
305
|
if data_directories.any?
|
297
|
-
image_config = Docker.inspect_image(
|
306
|
+
image_config = Docker.inspect_image(full_image_name_with_fallback)
|
298
307
|
image_user = image_config["container_config"]["User"]
|
299
308
|
|
300
309
|
command = "mkdir -p #{data_directories.collect { |dir| "/dockistrano/data/#{dir}"}.join(" ") }; "
|
301
310
|
command += "chown #{image_user}:#{image_user} #{data_directories.collect { |dir| "/dockistrano/data/#{dir}"}.join(" ") }"
|
302
311
|
bash_command = "/bin/bash -c '#{command}'"
|
303
|
-
Docker.run(
|
312
|
+
Docker.run(full_image_name_with_fallback, command: bash_command, v: volumes, e: environment_variables, u: "root")
|
304
313
|
end
|
305
314
|
end
|
306
315
|
|
307
316
|
def newer_version_available?
|
308
|
-
registry_image_id = registry_instance.latest_id_for_image(image_name,
|
317
|
+
registry_image_id = registry_instance.latest_id_for_image(image_name, tag_with_fallback)
|
309
318
|
registry_image_id and image_id != registry_image_id
|
310
319
|
end
|
311
320
|
|
@@ -5,8 +5,15 @@ module Dockistrano
|
|
5
5
|
# Creates a new service instance based on the name and configuration. When
|
6
6
|
# configuration is not local, the configuration is fetched from Github and
|
7
7
|
# processed.
|
8
|
-
|
9
|
-
|
8
|
+
# In some cases, you only need an uninitialized version of a dependency, for
|
9
|
+
# example when pulling new versions of images. Provide initialize=false to
|
10
|
+
# skip tag detection and configuration loading from the image.
|
11
|
+
def self.factory(service, name, config, initialize=true)
|
12
|
+
if initialize
|
13
|
+
ServiceDependency.new(service, name, config).initialized_backing_service
|
14
|
+
else
|
15
|
+
ServiceDependency.new(service, name, config).backing_service
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
class DefaultEnvironmentMissingInConfiguration < StandardError
|
data/lib/dockistrano/version.rb
CHANGED
@@ -85,24 +85,28 @@ describe Dockistrano::Cli do
|
|
85
85
|
let(:command) { ["pull"] }
|
86
86
|
|
87
87
|
it "pulls a backing service when newer versions are available" do
|
88
|
+
expect(service).to receive(:backing_services).with(initialize: false).and_return({ "postgresql" => backing_service })
|
88
89
|
expect(backing_service).to receive(:newer_version_available?).and_return(true)
|
89
90
|
expect(backing_service).to receive(:pull)
|
90
91
|
expect(output).to include("Pulled")
|
91
92
|
end
|
92
93
|
|
93
94
|
it "doesn't pull a service when no new versions are available" do
|
95
|
+
expect(service).to receive(:backing_services).with(initialize: false).and_return({ "postgresql" => backing_service })
|
94
96
|
expect(backing_service).to receive(:newer_version_available?).and_return(false)
|
95
97
|
expect(backing_service).to_not receive(:pull)
|
96
98
|
expect(output).to include("Uptodate")
|
97
99
|
end
|
98
100
|
|
99
101
|
it "pulls the application container when newer versions are available" do
|
102
|
+
expect(service).to receive(:backing_services).with(initialize: false).and_return({ "postgresql" => backing_service })
|
100
103
|
expect(service).to receive(:newer_version_available?).and_return(true)
|
101
104
|
expect(service).to receive(:pull)
|
102
105
|
expect(output).to include("Pulled")
|
103
106
|
end
|
104
107
|
|
105
108
|
it "doesn't pull the application container when no newer versions are available" do
|
109
|
+
expect(service).to receive(:backing_services).with(initialize: false).and_return({ "postgresql" => backing_service })
|
106
110
|
expect(service).to receive(:newer_version_available?).and_return(false)
|
107
111
|
expect(service).to_not receive(:pull)
|
108
112
|
expect(output).to include("Uptodate")
|
@@ -12,6 +12,12 @@ describe Dockistrano::ServiceDependency do
|
|
12
12
|
expect(service_dependency).to receive(:initialized_backing_service).and_return(service)
|
13
13
|
expect(described_class.factory(service, "redis", { foo: "bar" })).to eq(service)
|
14
14
|
end
|
15
|
+
|
16
|
+
it "creates a new service based on the name" do
|
17
|
+
expect(described_class).to receive(:new).and_return(service_dependency)
|
18
|
+
expect(service_dependency).to receive(:backing_service).and_return(service)
|
19
|
+
expect(described_class.factory(service, "redis", { foo: "bar" }, false)).to eq(service)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
context "#backing_service" do
|
@@ -294,32 +294,35 @@ describe Dockistrano::Service do
|
|
294
294
|
|
295
295
|
context "#run" do
|
296
296
|
it "runs the command inside the container" do
|
297
|
+
allow(subject).to receive(:full_image_name_with_fallback).and_return("image:develop")
|
297
298
|
allow(subject).to receive(:environment_variables).and_return(environment = double)
|
298
299
|
allow(subject).to receive(:volumes).and_return(volumes = double)
|
299
300
|
allow(subject).to receive(:ports).and_return(ports = double)
|
300
|
-
expect(Dockistrano::Docker).to receive(:run).with(subject.
|
301
|
+
expect(Dockistrano::Docker).to receive(:run).with(subject.full_image_name_with_fallback, e: environment, v: volumes, p: ports, command: "foobar")
|
301
302
|
subject.run("foobar")
|
302
303
|
end
|
303
304
|
end
|
304
305
|
|
305
306
|
context "#exec" do
|
306
307
|
it "executes the command inside the container" do
|
308
|
+
allow(subject).to receive(:full_image_name_with_fallback).and_return("image:develop")
|
307
309
|
allow(subject).to receive(:environment_variables).and_return(environment = double)
|
308
310
|
allow(subject).to receive(:volumes).and_return(volumes = double)
|
309
311
|
allow(subject).to receive(:ports).and_return(ports = double)
|
310
312
|
expect(subject).to receive(:create_data_directories)
|
311
|
-
expect(Dockistrano::Docker).to receive(:exec).with(subject.
|
313
|
+
expect(Dockistrano::Docker).to receive(:exec).with(subject.full_image_name_with_fallback, e: environment, v: volumes, p: ports, command: "foobar")
|
312
314
|
subject.exec("foobar")
|
313
315
|
end
|
314
316
|
end
|
315
317
|
|
316
318
|
context "#console" do
|
317
319
|
it "runs the command inside the container" do
|
320
|
+
allow(subject).to receive(:full_image_name_with_fallback).and_return("image:develop")
|
318
321
|
allow(subject).to receive(:environment_variables).and_return(environment = double)
|
319
322
|
allow(subject).to receive(:volumes).and_return(volumes = double)
|
320
323
|
allow(subject).to receive(:ports).and_return(ports = double)
|
321
324
|
expect(subject).to receive(:create_data_directories)
|
322
|
-
expect(Dockistrano::Docker).to receive(:console).with(subject.
|
325
|
+
expect(Dockistrano::Docker).to receive(:console).with(subject.full_image_name_with_fallback, e: environment, v: volumes, p: ports, command: "foobar")
|
323
326
|
subject.console("foobar")
|
324
327
|
end
|
325
328
|
end
|
@@ -332,9 +335,14 @@ describe Dockistrano::Service do
|
|
332
335
|
end
|
333
336
|
|
334
337
|
it "returns a hash with backing services" do
|
335
|
-
expect(Dockistrano::ServiceDependency).to receive(:factory).with(subject, "postgresql", {}).and_return(service)
|
338
|
+
expect(Dockistrano::ServiceDependency).to receive(:factory).with(subject, "postgresql", {}, true).and_return(service)
|
336
339
|
expect(subject.backing_services).to eq({ "postgresql" => service })
|
337
340
|
end
|
341
|
+
|
342
|
+
it "returns a hash with uninitialized backing services" do
|
343
|
+
expect(Dockistrano::ServiceDependency).to receive(:factory).with(subject, "postgresql", {}, false).and_return(service)
|
344
|
+
expect(subject.backing_services(initialize: false)).to eq({ "postgresql" => service })
|
345
|
+
end
|
338
346
|
end
|
339
347
|
|
340
348
|
context "#environment_variables" do
|
@@ -343,7 +351,7 @@ describe Dockistrano::Service do
|
|
343
351
|
ip_address: "172.0.0.1",
|
344
352
|
port: "1245",
|
345
353
|
backing_service_env: { database: "dockistrano_development" },
|
346
|
-
|
354
|
+
provided_environment_variables: { "DATABASE_URL" => "postgres://postgres@$POSTGRESQL_IP/$POSTGRESQL_DATABASE"}
|
347
355
|
)
|
348
356
|
}
|
349
357
|
|
@@ -368,18 +376,22 @@ describe Dockistrano::Service do
|
|
368
376
|
end
|
369
377
|
|
370
378
|
it "includes environment variables from each backing service" do
|
371
|
-
expect(backing_service).to receive(:
|
379
|
+
expect(backing_service).to receive(:provided_environment_variables).and_return({ "SUB_ENV" => "some_value" })
|
372
380
|
expect(subject.environment_variables["SUB_ENV"]).to eq("some_value")
|
373
381
|
end
|
374
382
|
|
383
|
+
it "interpolates environment variables with present values" do
|
384
|
+
expect(subject.environment_variables["DATABASE_URL"]).to eq("postgres://postgres@172.0.0.1/dockistrano_development")
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
context "#provided_environment_variables" do
|
389
|
+
|
375
390
|
it "includes environment variables that are provided by the service" do
|
376
391
|
expect(subject).to receive(:provides_env).and_return({ "BUNDLE_PATH" => "/bundle" })
|
377
|
-
expect(subject.
|
392
|
+
expect(subject.provided_environment_variables["BUNDLE_PATH"]).to eq("/bundle")
|
378
393
|
end
|
379
394
|
|
380
|
-
it "interpolates environment variables with present values" do
|
381
|
-
expect(subject.environment_variables["DATABASE_URL"]).to eq("postgres://postgres@172.0.0.1/dockistrano_development")
|
382
|
-
end
|
383
395
|
end
|
384
396
|
|
385
397
|
context "#volumes" do
|
@@ -398,13 +410,13 @@ describe Dockistrano::Service do
|
|
398
410
|
context "#available_tags" do
|
399
411
|
it "returns a list of available tags for the current service" do
|
400
412
|
expect(subject).to receive(:registry_instance).and_return(registry = double)
|
401
|
-
expect(registry).to receive(:tags_for_image).with(subject.
|
413
|
+
expect(registry).to receive(:tags_for_image).with(subject.image_name).and_return(["develop", "master"])
|
402
414
|
expect(subject.available_tags).to eq(["develop", "master"])
|
403
415
|
end
|
404
416
|
|
405
417
|
it "returns an empty list when the repository is not found in the registry" do
|
406
418
|
expect(subject).to receive(:registry_instance).and_return(registry = double)
|
407
|
-
expect(registry).to receive(:tags_for_image).with(subject.
|
419
|
+
expect(registry).to receive(:tags_for_image).with(subject.image_name).and_raise(Dockistrano::Registry::RepositoryNotFoundInRegistry)
|
408
420
|
expect(subject.available_tags).to eq([])
|
409
421
|
end
|
410
422
|
end
|
@@ -492,12 +504,13 @@ describe Dockistrano::Service do
|
|
492
504
|
|
493
505
|
context "#create_data_directories" do
|
494
506
|
it "creates directories in the mounted data folder" do
|
507
|
+
allow(subject).to receive(:full_image_name_with_fallback).and_return("image:develop")
|
495
508
|
allow(subject).to receive(:data_directories).and_return(["logs"])
|
496
509
|
allow(subject).to receive(:volumes).and_return(volumes = double)
|
497
510
|
allow(subject).to receive(:environment_variables).and_return(environment_variables = double)
|
498
|
-
allow(Dockistrano::Docker).to receive(:inspect_image).with(subject.
|
511
|
+
allow(Dockistrano::Docker).to receive(:inspect_image).with(subject.full_image_name_with_fallback).and_return({ "container_config" => { "User" => "app" }})
|
499
512
|
|
500
|
-
expect(Dockistrano::Docker).to receive(:run).with(subject.
|
513
|
+
expect(Dockistrano::Docker).to receive(:run).with(subject.full_image_name_with_fallback,
|
501
514
|
v: volumes,
|
502
515
|
e: environment_variables,
|
503
516
|
u: "root",
|
@@ -513,22 +526,23 @@ describe Dockistrano::Service do
|
|
513
526
|
|
514
527
|
before do
|
515
528
|
allow(subject).to receive(:registry_instance).and_return(registry_instance)
|
529
|
+
allow(subject).to receive(:tag_with_fallback).and_return("develop")
|
516
530
|
end
|
517
531
|
|
518
532
|
it "returns true when a newer version of the image is available" do
|
519
533
|
expect(subject).to receive(:image_id).and_return("1")
|
520
|
-
expect(registry_instance).to receive(:latest_id_for_image).with(subject.image_name, subject.
|
534
|
+
expect(registry_instance).to receive(:latest_id_for_image).with(subject.image_name, subject.tag_with_fallback).and_return("2")
|
521
535
|
expect(subject.newer_version_available?).to be_true
|
522
536
|
end
|
523
537
|
|
524
538
|
it "returns false when no registry image id is found" do
|
525
|
-
expect(registry_instance).to receive(:latest_id_for_image).with(subject.image_name, subject.
|
539
|
+
expect(registry_instance).to receive(:latest_id_for_image).with(subject.image_name, subject.tag_with_fallback).and_return(nil)
|
526
540
|
expect(subject.newer_version_available?).to be_false
|
527
541
|
end
|
528
542
|
|
529
543
|
it "returns false when the registry image id is equal to the local id" do
|
530
544
|
expect(subject).to receive(:image_id).and_return("1")
|
531
|
-
expect(registry_instance).to receive(:latest_id_for_image).with(subject.image_name, subject.
|
545
|
+
expect(registry_instance).to receive(:latest_id_for_image).with(subject.image_name, subject.tag_with_fallback).and_return("1")
|
532
546
|
expect(subject.newer_version_available?).to be_false
|
533
547
|
end
|
534
548
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockistrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Vlieg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|