dockistrano 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/lib/dockistrano/cli.rb +12 -7
- data/lib/dockistrano/hipache.rb +3 -3
- data/lib/dockistrano/service.rb +15 -17
- data/lib/dockistrano/version.rb +1 -1
- data/spec/dockistrano/cli_spec.rb +4 -1
- data/spec/dockistrano/service_spec.rb +31 -24
- 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: b35d583a8fab01a67cce0aaa48b6991bf37ade7a
|
4
|
+
data.tar.gz: 2b732ea55ec66f519e2c1e78c111d846849f153f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0be8f640a0a35ab5529ca25b34328fb299a98ad579f4e8510592023c3c8fb6b6d98a3d7d5d30a427040567be62cca1f29ed8e23a35c5503ef884fd4cec5fa9db
|
7
|
+
data.tar.gz: b8125c8ddd5c22d9e5e4922a984fbe5014316216daffb3cffb8e19cb9a75079d822fe5c3037dbd078608b6b0a97bafb38a3a6146d92952fdef4a75de2a013da2
|
data/lib/dockistrano/cli.rb
CHANGED
@@ -17,8 +17,7 @@ module Dockistrano
|
|
17
17
|
desc "setup", "Sets up a host for starting the application"
|
18
18
|
method_option "environment", aliases: "-e", default: ENV["DOCKISTRANO_ENVIRONMENT"], type: :string, desc: "Environment to start the container in"
|
19
19
|
def setup
|
20
|
-
|
21
|
-
say "\tmkdir -p #{current_service.directories_required_on_host.join(" ")}"
|
20
|
+
`mkdir -p #{current_service.directories_required_on_host.join(" ")}`
|
22
21
|
end
|
23
22
|
|
24
23
|
desc "status", "Status of the application"
|
@@ -39,17 +38,23 @@ module Dockistrano
|
|
39
38
|
say ""
|
40
39
|
say "Dependencies", :blue
|
41
40
|
current_service.backing_services.each do |name, service|
|
42
|
-
|
41
|
+
if service.running?
|
42
|
+
say_status "online", "#{service.full_image_name}", :green
|
43
|
+
else
|
44
|
+
say_status "offline", "#{service.full_image_name}", :red
|
45
|
+
end
|
43
46
|
end
|
44
47
|
say ""
|
45
48
|
say "Environment", :blue
|
46
49
|
current_service.environment_variables.each do |key, value|
|
47
50
|
say " #{key}=#{value}"
|
48
51
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
if current_service.backing_services["hipache"] and redis_url = current_service.backing_services["hipache"].ip_address
|
53
|
+
say ""
|
54
|
+
say "Hipache", :blue
|
55
|
+
Hipache.new("redis://#{redis_url}:6379").status.each do |host, ips|
|
56
|
+
say " #{host}: #{ips.join(", ")}"
|
57
|
+
end
|
53
58
|
end
|
54
59
|
say ""
|
55
60
|
end
|
data/lib/dockistrano/hipache.rb
CHANGED
@@ -4,8 +4,8 @@ module Dockistrano
|
|
4
4
|
|
5
5
|
class Hipache
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(hipache_url)
|
8
|
+
@hipache_url = hipache_url
|
9
9
|
end
|
10
10
|
|
11
11
|
def online?
|
@@ -55,7 +55,7 @@ module Dockistrano
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def redis
|
58
|
-
@redis ||= Redis.new(
|
58
|
+
@redis ||= Redis.new(url: @hipache_url)
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
data/lib/dockistrano/service.rb
CHANGED
@@ -37,7 +37,7 @@ module Dockistrano
|
|
37
37
|
def config=(config)
|
38
38
|
@config = config
|
39
39
|
@dependencies = config["dependencies"] || {}
|
40
|
-
@image_name ||= config["image_name"] || Git.repository_name
|
40
|
+
@image_name ||= (config["image_name"] || Git.repository_name).gsub(/\-/, "_").gsub(/\./, "")
|
41
41
|
@tag ||= config["tag"] || Git.branch
|
42
42
|
@registry ||= config["registry"]
|
43
43
|
@host ||= config["host"]
|
@@ -147,13 +147,13 @@ module Dockistrano
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def update_hipache(server_up=true)
|
150
|
-
if !host.nil?
|
151
|
-
hipache = Hipache.new(
|
150
|
+
if !host.nil? and (redis_url = backing_services["hipache"].ip_address)
|
151
|
+
hipache = Hipache.new("redis://#{redis_url}:6379")
|
152
152
|
host.each do |hostname, port|
|
153
153
|
if server_up
|
154
|
-
hipache.register(image_name, hostname,
|
154
|
+
hipache.register(image_name, hostname, ip_address, port)
|
155
155
|
else
|
156
|
-
hipache.unregister(image_name, hostname,
|
156
|
+
hipache.unregister(image_name, hostname, ip_address, port)
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
@@ -260,7 +260,7 @@ module Dockistrano
|
|
260
260
|
end
|
261
261
|
|
262
262
|
# Returns a list of available tags in the registry for the image
|
263
|
-
def
|
263
|
+
def available_tags_in_registry
|
264
264
|
@available_tags ||= begin
|
265
265
|
registry_instance.tags_for_image(image_name)
|
266
266
|
rescue Dockistrano::Registry::RepositoryNotFoundInRegistry
|
@@ -268,6 +268,10 @@ module Dockistrano
|
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
+
def available_tags_local
|
272
|
+
@available_tags_local ||= Docker.tags_for_image("#{registry}/#{image_name}")
|
273
|
+
end
|
274
|
+
|
271
275
|
class NoTagFoundForImage < StandardError
|
272
276
|
end
|
273
277
|
|
@@ -277,28 +281,22 @@ module Dockistrano
|
|
277
281
|
|
278
282
|
begin
|
279
283
|
tag_suggestion = fallback_tags.shift
|
280
|
-
final_tag = tag_suggestion if
|
284
|
+
final_tag = tag_suggestion if available_tags_local.include?(tag_suggestion)
|
281
285
|
end while !final_tag and fallback_tags.any?
|
282
286
|
|
283
287
|
if final_tag
|
284
288
|
final_tag
|
285
289
|
else
|
286
|
-
raise NoTagFoundForImage.new("No tag found for image #{image_name}, wanted tag #{tag}, available tags: #{
|
290
|
+
raise NoTagFoundForImage.new("No tag found for image #{image_name}, wanted tag #{tag}, available tags: #{available_tags_local}")
|
287
291
|
end
|
288
292
|
end
|
289
293
|
|
290
|
-
def
|
291
|
-
container_settings["NetworkSettings"]["
|
294
|
+
def ip_address
|
295
|
+
container_settings["NetworkSettings"]["IPAddress"] if running?
|
292
296
|
end
|
293
297
|
|
294
298
|
def ports
|
295
|
-
(config["ports"] ||
|
296
|
-
if k.to_s.include?(":")
|
297
|
-
"#{k}:#{v}"
|
298
|
-
else
|
299
|
-
"172.17.42.1:#{k}:#{v}"
|
300
|
-
end
|
301
|
-
}
|
299
|
+
(config["ports"] || [])
|
302
300
|
end
|
303
301
|
|
304
302
|
def attach(name=nil)
|
data/lib/dockistrano/version.rb
CHANGED
@@ -5,6 +5,7 @@ describe Dockistrano::Cli do
|
|
5
5
|
let(:service) { double(registry: "registry.provider.tld", image_name: "application", tag: "develop", volumes: [], backing_services: { "postgresql" => backing_service }, environment_variables: {}, newer_version_available?: false, stop: nil) }
|
6
6
|
let(:backing_service) { double(:backing_service, full_image_name: "registry.provider.tld/postgresql:develop", image_name: "postgresql", running?: false, newer_version_available?: false, start: nil, stop: nil) }
|
7
7
|
let(:hipache) { double }
|
8
|
+
let(:hipache_service) { double(running?: true, full_image_name: "hipache") }
|
8
9
|
let(:output) { capture(:stdout) { described_class.start(command) } }
|
9
10
|
|
10
11
|
before do
|
@@ -48,7 +49,9 @@ describe Dockistrano::Cli do
|
|
48
49
|
end
|
49
50
|
|
50
51
|
it "lists the Hipache configuration" do
|
51
|
-
allow(
|
52
|
+
allow(service).to receive(:backing_services).and_return({ "hipache" => hipache_service })
|
53
|
+
allow(hipache_service).to receive(:ip_address).and_return("127.0.0.1")
|
54
|
+
allow(Dockistrano::Hipache).to receive(:new).with("redis://127.0.0.1:6379").and_return(hipache)
|
52
55
|
allow(hipache).to receive(:status).and_return({ "somehostname.dev" => ["127.0.0.1:1000", "23.45.56.75:1234"] })
|
53
56
|
expect(output).to include("somehostname.dev: 127.0.0.1:1000, 23.45.56.75:1234")
|
54
57
|
end
|
@@ -242,21 +242,24 @@ describe Dockistrano::Service do
|
|
242
242
|
|
243
243
|
context "#update_hipache" do
|
244
244
|
let(:hipache) { double }
|
245
|
+
let(:hipache_service) { double }
|
245
246
|
|
246
247
|
before do
|
247
248
|
allow(Dockistrano::Hipache).to receive(:new).and_return(hipache)
|
249
|
+
allow(subject).to receive(:backing_services).and_return({ "hipache" => hipache_service })
|
250
|
+
allow(hipache_service).to receive(:ip_address).and_return("172.168.1.1")
|
248
251
|
end
|
249
252
|
|
250
253
|
it "registers the host in Hipache when the server is up" do
|
251
254
|
allow(subject).to receive(:host).and_return({ "hostname.dev" => "8000" })
|
252
|
-
expect(subject).to receive(:
|
255
|
+
expect(subject).to receive(:ip_address).and_return("33.33.33.33")
|
253
256
|
expect(hipache).to receive(:register).with(subject.image_name, "hostname.dev", "33.33.33.33", "8000")
|
254
257
|
subject.update_hipache(true)
|
255
258
|
end
|
256
259
|
|
257
260
|
it "unregisters the host in Hipache when the server is down" do
|
258
261
|
allow(subject).to receive(:host).and_return({ "hostname.dev" => "8000" })
|
259
|
-
expect(subject).to receive(:
|
262
|
+
expect(subject).to receive(:ip_address).and_return("33.33.33.33")
|
260
263
|
expect(hipache).to receive(:unregister).with(subject.image_name, "hostname.dev", "33.33.33.33", "8000")
|
261
264
|
subject.update_hipache(false)
|
262
265
|
end
|
@@ -431,75 +434,79 @@ describe Dockistrano::Service do
|
|
431
434
|
|
432
435
|
context "#directories_required_on_host"
|
433
436
|
|
434
|
-
context "#
|
437
|
+
context "#available_tags_in_registry" do
|
435
438
|
it "returns a list of available tags for the current service" do
|
436
439
|
expect(subject).to receive(:registry_instance).and_return(registry = double)
|
437
440
|
expect(registry).to receive(:tags_for_image).with(subject.image_name).and_return(["develop", "master"])
|
438
|
-
expect(subject.
|
441
|
+
expect(subject.available_tags_in_registry).to eq(["develop", "master"])
|
439
442
|
end
|
440
443
|
|
441
444
|
it "returns an empty list when the repository is not found in the registry" do
|
442
445
|
expect(subject).to receive(:registry_instance).and_return(registry = double)
|
443
446
|
expect(registry).to receive(:tags_for_image).with(subject.image_name).and_raise(Dockistrano::Registry::RepositoryNotFoundInRegistry)
|
444
|
-
expect(subject.
|
447
|
+
expect(subject.available_tags_in_registry).to eq([])
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
context "#available_tags_local" do
|
452
|
+
it "returns a list of available tags for the current service" do
|
453
|
+
expect(Dockistrano::Docker).to receive(:tags_for_image).with("#{subject.registry}/#{subject.image_name}").and_return(["develop", "master"])
|
454
|
+
expect(subject.available_tags_local).to eq(["develop", "master"])
|
445
455
|
end
|
446
456
|
end
|
447
457
|
|
448
458
|
context "#tag_with_fallback" do
|
449
459
|
it "uses the feature branch when available" do
|
450
460
|
allow(subject).to receive(:tag).and_return("feature_branch")
|
451
|
-
allow(subject).to receive(:
|
461
|
+
allow(subject).to receive(:available_tags_local).and_return(["develop", "master", "feature_branch"])
|
452
462
|
expect(subject.tag_with_fallback).to eq("feature_branch")
|
453
463
|
end
|
454
464
|
|
455
465
|
it "uses the develop branch when available" do
|
456
466
|
allow(subject).to receive(:tag).and_return("feature_branch")
|
457
|
-
allow(subject).to receive(:
|
467
|
+
allow(subject).to receive(:available_tags_local).and_return(["develop", "master", "latest"])
|
458
468
|
expect(subject.tag_with_fallback).to eq("develop")
|
459
469
|
end
|
460
470
|
|
461
471
|
it "uses the master branch when available" do
|
462
472
|
allow(subject).to receive(:tag).and_return("feature_branch")
|
463
|
-
allow(subject).to receive(:
|
473
|
+
allow(subject).to receive(:available_tags_local).and_return(["master", "latest"])
|
464
474
|
expect(subject.tag_with_fallback).to eq("master")
|
465
475
|
end
|
466
476
|
|
467
477
|
it "uses the latest branch when available" do
|
468
478
|
allow(subject).to receive(:tag).and_return("feature_branch")
|
469
|
-
allow(subject).to receive(:
|
479
|
+
allow(subject).to receive(:available_tags_local).and_return(["latest"])
|
470
480
|
expect(subject.tag_with_fallback).to eq("latest")
|
471
481
|
end
|
472
482
|
|
473
483
|
it "raises an error when no tags are found" do
|
474
484
|
allow(subject).to receive(:tag).and_return("feature_branch")
|
475
|
-
allow(subject).to receive(:
|
485
|
+
allow(subject).to receive(:available_tags_local).and_return(["foobar", "test"])
|
476
486
|
expect { subject.tag_with_fallback }.to raise_error(Dockistrano::Service::NoTagFoundForImage)
|
477
487
|
end
|
478
488
|
end
|
479
489
|
|
480
|
-
context "#
|
481
|
-
it "returns the ip address
|
490
|
+
context "#ip_address" do
|
491
|
+
it "returns the ip address of the running container" do
|
482
492
|
allow(subject).to receive(:running?).and_return(true)
|
483
|
-
allow(subject).to receive(:container_settings).and_return({
|
484
|
-
"
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
]
|
490
|
-
}}})
|
491
|
-
expect(subject.ip_address_for_port(3000)).to eq("127.0.0.1")
|
493
|
+
allow(subject).to receive(:container_settings).and_return({
|
494
|
+
"NetworkSettings" => {
|
495
|
+
"IPAddress" => "172.168.1.1"
|
496
|
+
}
|
497
|
+
})
|
498
|
+
expect(subject.ip_address).to eq("172.168.1.1")
|
492
499
|
end
|
493
500
|
end
|
494
501
|
|
495
502
|
context "#ports" do
|
496
503
|
it "returns a string representation of the port mappings" do
|
497
|
-
subject.config = { "ports" =>
|
498
|
-
expect(subject.ports).to eq(["
|
504
|
+
subject.config = { "ports" => [ "1234:5678" ] }
|
505
|
+
expect(subject.ports).to eq(["1234:5678"])
|
499
506
|
end
|
500
507
|
|
501
508
|
it "returns the ip address included in the configuration" do
|
502
|
-
subject.config = { "ports" =>
|
509
|
+
subject.config = { "ports" => [ "33.33.33.10:1234:5678" ] }
|
503
510
|
expect(subject.ports).to eq(["33.33.33.10:1234:5678"])
|
504
511
|
end
|
505
512
|
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.7
|
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-11-
|
11
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|