dockistrano 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ac28b523edaa71eb85020de59988f816994362d
4
- data.tar.gz: e7caed84b3299f8824b2771cb521e20a3ab6770c
3
+ metadata.gz: 4869a713668f9a34a7ff283320a89025f37be8fc
4
+ data.tar.gz: 6cd46f26c5b421a8a1244ff07bc8ee13fc5c9d25
5
5
  SHA512:
6
- metadata.gz: a641af2fa6076e1c3e5c72c69abd54e2b43c85d8addb2c5e0e430cda3744954107ac4d495354d7e42cc72b6c765ffbd966ce0f0d0fb9f18319fe3105c0e6d6cf
7
- data.tar.gz: 8ec45003411aa01abfeb7ecf4bb5a93b3841f100362f18925c5aea5c623dc09896ef77f2eb7b82dfbbdf227378e1bec4f2a42f4b413a39175a93a3a3cfe60dd6
6
+ metadata.gz: e3d575c20065873bdd259cce1b1d16c76885c2c3843c7ab8bac87f84fdc901d0b9953abfbf4eff4b73fe6003d66b729aea61b588a19f15ad8397d619e4bfd04f
7
+ data.tar.gz: c67764b501790eb79ebf7a7a0f8e21feedef23bf9394b7b7e775c5c8a8430311ff243df252343ddbb5f8086f5780f71e20558dc25e1e4a0b9763b55f540f5f07
@@ -6,7 +6,7 @@ module Dockistrano
6
6
  # configuration is not local, the configuration is fetched from Github and
7
7
  # processed.
8
8
  def self.factory(service, name, config)
9
- ServiceDependency.new(service, name, config).backing_service
9
+ ServiceDependency.new(service, name, config).initialized_backing_service
10
10
  end
11
11
 
12
12
  class DefaultEnvironmentMissingInConfiguration < StandardError
@@ -21,32 +21,32 @@ module Dockistrano
21
21
  end
22
22
 
23
23
  def backing_service
24
- @backing_service ||= begin
25
- backing_service = Service.new("default" => {
26
- "registry" => service.registry,
27
- "image_name" => name,
28
- "tag" => service.tag,
29
- "backing_service_env" => config
30
- })
31
-
32
- backing_service.tag = tag_with_fallback(service.registry, name, service.tag)
33
-
34
- begin
35
- loaded_config = load_config
36
- if loaded_config and loaded_config["default"]
37
- backing_service.config = loaded_config["default"]
38
- else
39
- raise DefaultEnvironmentMissingInConfiguration.new("No 'default' configuration found in /dockistrano.yml file in #{name} container.")
40
- end
41
- rescue ContainerConfigurationMissing
42
- puts "Warning: no configuration file found for service #{name}."
43
- rescue HostDirectoriesMissing
44
- puts "Error: missing host directory configuration for #{name}. Please execute `doc setup`"
45
- exit 1
46
- end
24
+ @backing_service ||= Service.new("default" => {
25
+ "registry" => service.registry,
26
+ "image_name" => name,
27
+ "tag" => service.tag,
28
+ "backing_service_env" => config
29
+ })
30
+ end
47
31
 
48
- backing_service
32
+ def initialized_backing_service
33
+ backing_service.tag = tag_with_fallback(service.tag)
34
+
35
+ begin
36
+ loaded_config = load_config
37
+ if loaded_config and loaded_config["default"]
38
+ backing_service.config = loaded_config["default"]
39
+ else
40
+ raise DefaultEnvironmentMissingInConfiguration.new("No 'default' configuration found in /dockistrano.yml file in #{name} container.")
41
+ end
42
+ rescue ContainerConfigurationMissing
43
+ puts "Warning: no configuration file found for service #{name}."
44
+ rescue HostDirectoriesMissing
45
+ puts "Error: missing host directory configuration for #{name}. Please execute `doc setup`"
46
+ exit 1
49
47
  end
48
+
49
+ backing_service
50
50
  end
51
51
 
52
52
  def load_config
@@ -89,10 +89,10 @@ module Dockistrano
89
89
  class NoTagFoundForImage < StandardError
90
90
  end
91
91
 
92
- def tag_with_fallback(registry, image_name, tag)
92
+ def tag_with_fallback(tag)
93
93
  fallback_tags = [tag, "develop", "master", "latest"]
94
94
 
95
- available_tags = Docker.tags_for_image("#{registry}/#{image_name}")
95
+ available_tags = Docker.tags_for_image("#{backing_service.registry}/#{backing_service.image_name}")
96
96
 
97
97
  begin
98
98
  tag_suggestion = fallback_tags.shift
@@ -102,7 +102,7 @@ module Dockistrano
102
102
  if final_tag
103
103
  final_tag
104
104
  else
105
- raise NoTagFoundForImage.new("No tag found for image #{image_name}, locally available tags: #{available_tags} `doc pull` for more tags from repository.")
105
+ raise NoTagFoundForImage.new("No tag found for image #{backing_service.image_name}, locally available tags: #{available_tags} `doc pull` for more tags from repository.")
106
106
  end
107
107
  end
108
108
 
@@ -1,3 +1,3 @@
1
1
  module Dockistrano
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -9,17 +9,12 @@ describe Dockistrano::ServiceDependency do
9
9
  context ".factory" do
10
10
  it "creates a new service based on the name" do
11
11
  expect(described_class).to receive(:new).and_return(service_dependency)
12
- expect(service_dependency).to receive(:backing_service).and_return(service)
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
15
  end
16
16
 
17
- context "#initialize" do
18
- before do
19
- allow(subject).to receive(:load_config).and_return({ "default" => {} })
20
- allow(subject).to receive(:tag_with_fallback).and_return("develop")
21
- end
22
-
17
+ context "#backing_service" do
23
18
  it "backing service has registry of the service" do
24
19
  expect(subject.backing_service.registry).to eq("my.registry.net")
25
20
  end
@@ -31,19 +26,26 @@ describe Dockistrano::ServiceDependency do
31
26
  it "backing service has the tag of the service" do
32
27
  expect(subject.backing_service.tag).to eq("develop")
33
28
  end
29
+ end
30
+
31
+ context "#initialized_backing_service" do
32
+ before do
33
+ allow(subject).to receive(:load_config).and_return({ "default" => {} })
34
+ allow(subject).to receive(:tag_with_fallback).and_return("develop")
35
+ end
34
36
 
35
37
  it "backing service has backing service environment variables from configuration" do
36
- expect(subject.backing_service.backing_service_env).to eq({ database: "application_development" })
38
+ expect(subject.initialized_backing_service.backing_service_env).to eq({ database: "application_development" })
37
39
  end
38
40
 
39
41
  it "sets the tag with a fallback" do
40
- expect(subject).to receive(:tag_with_fallback).with("my.registry.net", "postgresql", "develop").and_return("latest")
41
- expect(subject.backing_service.tag).to eq("latest")
42
+ expect(subject).to receive(:tag_with_fallback).with("develop").and_return("latest")
43
+ expect(subject.initialized_backing_service.tag).to eq("latest")
42
44
  end
43
45
 
44
46
  it "loads the configuration" do
45
47
  expect(subject).to receive(:load_config).and_return({ "default" => { "test_command" => "foobar" }})
46
- expect(subject.backing_service.test_command).to eq("foobar")
48
+ expect(subject.initialized_backing_service.test_command).to eq("foobar")
47
49
  end
48
50
  end
49
51
 
@@ -119,29 +121,35 @@ describe Dockistrano::ServiceDependency do
119
121
  end
120
122
 
121
123
  context "#tag_with_fallback" do
124
+ let(:backing_service) { double(registry: "registry", image_name: "postgresql") }
125
+
126
+ before do
127
+ allow(subject).to receive(:backing_service).and_return(backing_service)
128
+ end
129
+
122
130
  it "returns the given tag when the tag is available" do
123
131
  expect(Dockistrano::Docker).to receive(:tags_for_image).and_return(["feature-branch", "develop", "master", "latest"])
124
- expect(subject.tag_with_fallback("registry", "postgresql", "feature-branch")).to eq("feature-branch")
132
+ expect(subject.tag_with_fallback("feature-branch")).to eq("feature-branch")
125
133
  end
126
134
 
127
135
  it "returns develop when the specific tag is not available" do
128
136
  expect(Dockistrano::Docker).to receive(:tags_for_image).and_return(["develop", "master", "latest"])
129
- expect(subject.tag_with_fallback("registry", "postgresql", "feature-branch")).to eq("develop")
137
+ expect(subject.tag_with_fallback("feature-branch")).to eq("develop")
130
138
  end
131
139
 
132
140
  it "returns master when develop is not available" do
133
141
  expect(Dockistrano::Docker).to receive(:tags_for_image).and_return(["master", "latest"])
134
- expect(subject.tag_with_fallback("registry", "postgresql", "feature-branch")).to eq("master")
142
+ expect(subject.tag_with_fallback("feature-branch")).to eq("master")
135
143
  end
136
144
 
137
145
  it "returns latest when master is not available" do
138
146
  expect(Dockistrano::Docker).to receive(:tags_for_image).and_return(["latest"])
139
- expect(subject.tag_with_fallback("registry", "postgresql", "feature-branch")).to eq("latest")
147
+ expect(subject.tag_with_fallback("feature-branch")).to eq("latest")
140
148
  end
141
149
 
142
150
  it "raises an error when not appropriate tag is found" do
143
151
  expect(Dockistrano::Docker).to receive(:tags_for_image).and_return(["another-feature-branch"])
144
- expect { subject.tag_with_fallback("registry", "postgresql", "feature-branch") }.to raise_error(Dockistrano::ServiceDependency::NoTagFoundForImage)
152
+ expect { subject.tag_with_fallback("feature-branch") }.to raise_error(Dockistrano::ServiceDependency::NoTagFoundForImage)
145
153
  end
146
154
  end
147
155
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Vlieg